From e6909dc0523a30b4ce5d686e10fae1f4b611d895 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 9 Dec 2024 20:08:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(cli):=20=E7=BB=84=E4=BB=B6=E5=BA=93?= =?UTF-8?q?=E6=9C=AAnpm=E5=8C=85=E6=97=B6=E5=85=B6=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/utils/resolveAppPackages.ts | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/utils/resolveAppPackages.ts b/packages/cli/src/utils/resolveAppPackages.ts index 003e5e0f..90a8727a 100644 --- a/packages/cli/src/utils/resolveAppPackages.ts +++ b/packages/cli/src/utils/resolveAppPackages.ts @@ -1,6 +1,6 @@ -import { execSync } from 'child_process'; -import path from 'path'; -import { exit } from 'process'; +import { execSync } from 'node:child_process'; +import path from 'node:path'; +import { exit } from 'node:process'; import fs, { existsSync } from 'fs-extra'; import * as recast from 'recast'; @@ -290,7 +290,7 @@ const getComponentPackageImports = function ({ }; const getIndexPath = function (entry: string) { - for (const affix of ['', '.js', '.ts']) { + for (const affix of ['', '.js', '.cjs', 'mjs', '.ts']) { const filePath = `${entry}${affix}`; if (isFile(filePath)) { return filePath; @@ -469,7 +469,7 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string if (isDirectory(moduleName)) { if (!fs.existsSync(path.join(moduleName, './package.json'))) { - ['index.js', 'index.ts'].forEach((index) => { + ['index.js', 'index.ts', 'index.cjs', 'index.mjs', 'index.json'].forEach((index) => { const indexFile = path.join(moduleName!, `./${index}`); if (fs.existsSync(indexFile)) { moduleName = indexFile; @@ -493,7 +493,17 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string // 组件&插件&数据源包 if (result.type === PackageType.COMPONENT_PACKAGE) { result.imports.forEach((i) => { - setPackages(packages, app, i.indexPath, moduleName!, i.type); + if (!moduleName) { + return; + } + + let componentCwd = moduleName; + + if (!isDirectory(moduleName)) { + componentCwd = path.join(cwd, `node_modules/${moduleName}`); + } + + setPackages(packages, app, i.indexPath, componentCwd, i.type); }); return;