From 0764d2ce9231fe422fdca7ca018b0c8870df6dc5 Mon Sep 17 00:00:00 2001 From: Thomas Allmer Date: Fri, 11 Nov 2022 13:01:19 +0100 Subject: [PATCH] chore(rocket-preset-extend-lion-docs): make it work on windows --- .../src/getPublicApiOfPkg.js | 14 +++++++++----- .../test-node/generateExtendDocsConfig.test.js | 2 +- .../test-node/getPublicApiOfPkg.test.js | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages-node/rocket-preset-extend-lion-docs/src/getPublicApiOfPkg.js b/packages-node/rocket-preset-extend-lion-docs/src/getPublicApiOfPkg.js index b9ce1f602..a07228df6 100644 --- a/packages-node/rocket-preset-extend-lion-docs/src/getPublicApiOfPkg.js +++ b/packages-node/rocket-preset-extend-lion-docs/src/getPublicApiOfPkg.js @@ -28,12 +28,16 @@ export async function getPublicApiOfPkg(pkgJsonPath) { pkgExports[pkgExportDefinition].default || pkgExports[pkgExportDefinition].module || pkgExports[pkgExportDefinition]; - const entryPointFilePath = path.join(pkgPath, pkgExportPath); + const entryPointFilePath = path.join(pkgPath, pkgExportPath.split('/').join(path.sep)); - if (glob.hasMagic(entryPointFilePath)) { - const globifiedEntryPointFilePath = entryPointFilePath.replace(/\*/, '**'); + const globifiedEntryPointFilePath = entryPointFilePath + .split(path.sep) + .join('/') + .replace(/\*/, '**'); + + if (glob.hasMagic(globifiedEntryPointFilePath)) { for (const entryPointFile of glob.sync(globifiedEntryPointFilePath, { nodir: true })) { - const fullPkgExportPath = path.join(pkgPath, pkgExportPath); + const fullPkgExportPath = path.join(pkgPath, pkgExportPath).split(path.sep).join('/'); const reg = new RegExp(`^${fullPkgExportPath.replace('*', '(.*)')}$`); const match = reg.exec(entryPointFile); if (match) { @@ -48,7 +52,7 @@ export async function getPublicApiOfPkg(pkgJsonPath) { name: pkgEntryPoint, namePath: pkgEntryPointPath, exports, - path: entryPointFile, + path: entryPointFile.split('/').join(path.sep), }); } } diff --git a/packages-node/rocket-preset-extend-lion-docs/test-node/generateExtendDocsConfig.test.js b/packages-node/rocket-preset-extend-lion-docs/test-node/generateExtendDocsConfig.test.js index 46cf8485f..9a4aa2497 100644 --- a/packages-node/rocket-preset-extend-lion-docs/test-node/generateExtendDocsConfig.test.js +++ b/packages-node/rocket-preset-extend-lion-docs/test-node/generateExtendDocsConfig.test.js @@ -21,7 +21,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); * @returns */ async function execute(input, options = {}) { - const nodeModulesDir = path.join(__dirname, input); + const nodeModulesDir = path.join(__dirname, input.split('/').join(path.sep)); const result = await generateExtendDocsConfig({ // used tsc version does not recognize optional jsdoc params diff --git a/packages-node/rocket-preset-extend-lion-docs/test-node/getPublicApiOfPkg.test.js b/packages-node/rocket-preset-extend-lion-docs/test-node/getPublicApiOfPkg.test.js index 80f0cd6a5..f8fa8b155 100644 --- a/packages-node/rocket-preset-extend-lion-docs/test-node/getPublicApiOfPkg.test.js +++ b/packages-node/rocket-preset-extend-lion-docs/test-node/getPublicApiOfPkg.test.js @@ -13,13 +13,13 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); * @returns */ async function execute(input) { - const pkgJsonPath = path.join(__dirname, input); + const pkgJsonPath = path.join(__dirname, input.split('/').join(path.sep)); const result = await getPublicApiOfPkg(pkgJsonPath); return { ...result, entryPoints: result.entryPoints.map(ep => ({ ...ep, - path: ep.path.replace(__dirname, 'abs::'), + path: ep.path.replace(__dirname, 'abs::').replace(/\\/g, '/'), })), }; }