From d973ed8dbac37bcb9893e57d52444f83ba30f154 Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Thu, 30 Nov 2023 12:41:15 +0800 Subject: [PATCH] fix(pm): create plugin bug (#3117) * fix: build bug * fix: app template package.json add workspaces * fix: plugin manager packageName * fix: remove template tsconfig paths --- packages/core/build/src/utils/getPackages.ts | 41 +++++++++++-------- .../templates/app/package.json.tpl | 3 +- .../templates/app/tsconfig.json.tpl | 10 +---- .../src/plugin-manager/plugin-manager.ts | 2 +- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/core/build/src/utils/getPackages.ts b/packages/core/build/src/utils/getPackages.ts index d74ac22e6..5bcd45f44 100644 --- a/packages/core/build/src/utils/getPackages.ts +++ b/packages/core/build/src/utils/getPackages.ts @@ -7,28 +7,37 @@ import { Package } from '@lerna/package'; import { toUnixPath } from './utils'; /** + * 获取构建包的绝对路径,支持项目路径和 npm 两种形式 * @example - * yarn build app/client,plugins/acl,core/* => ['app/client', 'plugins/acl', ...all core dir's packages] - * yarn build app/client plugins/acl core/* => ['app/client', 'plugins/acl', ...all core dir's packages] + * yarn build packages/core/client @nocobase/acl => ['/home/xx/packages/core/client', '/home/xx/packages/core/acl'] * yarn build => all packages */ function getPackagesPath(pkgs: string[]) { - if (pkgs.length === 0) { - return fg - .sync(['*/*/package.json', '*/*/*/package.json'], { - cwd: PACKAGES_PATH, - absolute: true, - onlyFiles: true, - }) - .map(toUnixPath).map(item => path.dirname(item)) - } - return fg - .sync(pkgs, { + const allPackageJson = fg + .sync(['*/*/package.json', '*/*/*/package.json'], { cwd: PACKAGES_PATH, absolute: true, - onlyDirectories: true, - }) - .map(toUnixPath); + onlyFiles: true, + }); + + if (pkgs.length === 0) { + return allPackageJson + .map(toUnixPath).map(item => path.dirname(item)); + } + + const allPackageInfo = allPackageJson + .map(packageJsonPath => ({ name: require(packageJsonPath).name, path: path.dirname(toUnixPath(packageJsonPath)) })) + .reduce((acc, cur) => { + acc[cur.name] = cur.path; + return acc; + }, {}); + const allPackagePaths: string[] = Object.values(allPackageInfo); + + const pkgNames = pkgs.filter(item => allPackageInfo[item]); + const relativePaths = pkgNames.length ? pkgs.filter(item => !pkgNames.includes(item)) : pkgs; + const pkgPaths = pkgs.map(item => allPackageInfo[item]) + const absPaths = allPackagePaths.filter(absPath => relativePaths.some((relativePath) => absPath.endsWith(relativePath))); + return [...pkgPaths, ...absPaths]; } export function getPackages(pkgs: string[]) { diff --git a/packages/core/create-nocobase-app/templates/app/package.json.tpl b/packages/core/create-nocobase-app/templates/app/package.json.tpl index c041c39ab..4aef8a6e6 100644 --- a/packages/core/create-nocobase-app/templates/app/package.json.tpl +++ b/packages/core/create-nocobase-app/templates/app/package.json.tpl @@ -2,7 +2,8 @@ "name": "{{{name}}}", "private": true, "workspaces": [ - "packages/*/*" + "packages/*/*", + "packages/*/*/*" ], "engines": { "node": ">=18" diff --git a/packages/core/create-nocobase-app/templates/app/tsconfig.json.tpl b/packages/core/create-nocobase-app/templates/app/tsconfig.json.tpl index b0b36ae8f..06a2ab60e 100644 --- a/packages/core/create-nocobase-app/templates/app/tsconfig.json.tpl +++ b/packages/core/create-nocobase-app/templates/app/tsconfig.json.tpl @@ -16,14 +16,6 @@ "declaration": true, "experimentalDecorators": true, "downlevelIteration": true, - "baseUrl": ".", - "paths": { - "@{{{name}}}/app-*": [ - "packages/app/*/src" - ], - "@{{{name}}}/plugin-*": [ - "packages/plugins/plugin-*/src" - ] - } + "baseUrl": "." } } diff --git a/packages/core/server/src/plugin-manager/plugin-manager.ts b/packages/core/server/src/plugin-manager/plugin-manager.ts index f9e7df26a..8f0bd2f2f 100644 --- a/packages/core/server/src/plugin-manager/plugin-manager.ts +++ b/packages/core/server/src/plugin-manager/plugin-manager.ts @@ -570,7 +570,7 @@ export class PluginManager { if (model) { opts['name'] = model.name; } - if (!opts['name']) { + if (!opts['packageName']) { opts['packageName'] = urlOrName; } await this.add(opts['name'] || urlOrName, opts, true);