fix: in the dev environment, all plugins are loaded locally (#3309)

* fix: cna plugin load

* fix: support storage

* fix: storage plugins

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
jack zhang 2024-01-03 17:31:58 +08:00 committed by GitHub
parent c4c7b7a6b6
commit 4c42dd8a13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 106 deletions

View File

@ -107,7 +107,13 @@ function resolveNocobasePackagesAlias(config) {
}
}
function getNodeModulesPath(packageDir) {
const node_modules_dir = path.join(process.cwd(), 'node_modules');
return path.join(node_modules_dir, packageDir);
}
class IndexGenerator {
nocobaseDir = getNodeModulesPath('@nocobase');
constructor(outputPath, pluginsPath) {
this.outputPath = outputPath;
this.pluginsPath = pluginsPath;
@ -189,23 +195,45 @@ export default function devDynamicImport(packageName: string): Promise<any> {
}
getContent(pluginsPath) {
const pluginFolders = glob
.sync(['*/package.json', '*/*/package.json'], { cwd: pluginsPath, onlyFiles: true, absolute: true })
.map((item) => path.dirname(item));
const pluginInfos = pluginFolders
.filter((folder) => {
const pluginPackageJsonPath = path.join(folder, 'package.json');
const pluginSrcClientPath = path.join(folder, 'src', 'client');
return fs.existsSync(pluginPackageJsonPath) && fs.existsSync(pluginSrcClientPath);
const pluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
cwd: pluginsPath,
onlyFiles: true,
absolute: true,
});
const storagePluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
cwd: process.env.PLUGIN_STORAGE_PATH,
onlyFiles: true,
absolute: true,
});
const nocobasePluginFolders = glob
.sync(['plugin-*/package.json'], { cwd: this.nocobaseDir, onlyFiles: true, absolute: true })
.map((item) => fs.realpathSync(item));
const pluginInfos = Array.from(new Set([...pluginFolders, ...storagePluginFolders, ...nocobasePluginFolders]))
.filter((item) => {
const dirname = path.dirname(item);
const clientJs = path.join(dirname, 'client.js');
return fs.existsSync(clientJs);
})
.map((folder) => {
const pluginPackageJsonPath = path.join(folder, 'package.json');
.map((pluginPackageJsonPath) => {
const pluginPackageJson = require(pluginPackageJsonPath);
const pluginSrcClientPath = path
.relative(this.packagesPath, path.join(folder, 'src', 'client'))
.replaceAll('\\', '/');
const pluginFileName = `${path.basename(pluginsPath)}_${path.basename(folder).replaceAll('-', '_')}`;
const exportStatement = `export { default } from '${pluginSrcClientPath}';`;
const pluginPathArr = pluginPackageJsonPath.replaceAll(path.sep, '/').split('/');
const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith('@');
const pluginFileName = (hasNamespace
? `${pluginPathArr[pluginPathArr.length - 3].replace('@', '')}_${pluginPathArr[pluginPathArr.length - 2]}`
: pluginPathArr[pluginPathArr.length - 2]
).replaceAll('-', '_');
let exportStatement = '';
if (pluginPackageJsonPath.includes('packages')) {
const pluginSrcClientPath = path
.relative(this.packagesPath, path.join(path.dirname(pluginPackageJsonPath), 'src', 'client'))
.replaceAll(path.sep, '/');
exportStatement = `export { default } from '${pluginSrcClientPath}';`;
} else {
exportStatement = `export { default } from '${pluginPackageJson.name}/client';`;
}
return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
});

View File

@ -0,0 +1,2 @@
export * from './dist/client';
export { default } from './dist/client';

View File

@ -0,0 +1 @@
module.exports = require('./dist/client/index.js');

View File

@ -0,0 +1,2 @@
export * from './dist/server';
export { default } from './dist/server';

View File

@ -0,0 +1 @@
module.exports = require('./dist/server/index.js');

View File

@ -4471,15 +4471,6 @@
dependencies:
"@opentelemetry/semantic-conventions" "1.19.0"
"@opentelemetry/exporter-prometheus@^0.46.0":
version "0.46.0"
resolved "https://registry.npmjs.org/@opentelemetry/exporter-prometheus/-/exporter-prometheus-0.46.0.tgz#c411a1e8a5266f9f3ddc44a088a538c3c1ee4830"
integrity sha512-AXcoCHG31K2PLGizlJJWcfQqZsGfUZkT7ik6C8VJu7U2Cenk0Xhvd3rO+vVNSSjP1+LHkP4MQtqEXpIZttw5cw==
dependencies:
"@opentelemetry/core" "1.19.0"
"@opentelemetry/resources" "1.19.0"
"@opentelemetry/sdk-metrics" "1.19.0"
"@opentelemetry/instrumentation@^0.46.0":
version "0.46.0"
resolved "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.46.0.tgz#a8a252306f82e2eace489312798592a14eb9830e"
@ -4513,7 +4504,7 @@
"@opentelemetry/core" "1.19.0"
"@opentelemetry/semantic-conventions" "1.19.0"
"@opentelemetry/sdk-metrics@1.19.0", "@opentelemetry/sdk-metrics@^1.19.0":
"@opentelemetry/sdk-metrics@^1.19.0":
version "1.19.0"
resolved "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.19.0.tgz#fe8029af29402563eb8dba75a85fc02006ea92c4"
integrity sha512-FiMii40zr0Fmys4F1i8gmuCvbinBnBsDeGBr4FQemOf0iPCLytYQm5AZJ/nn4xSc71IgKBQwTFQRAGJI7JvZ4Q==
@ -6403,15 +6394,6 @@
dependencies:
"@types/express" "*"
"@types/pg@^8.10.9":
version "8.10.9"
resolved "https://registry.npmjs.org/@types/pg/-/pg-8.10.9.tgz#d20bb948c6268c5bd847e2bf968f1194c5a2355a"
integrity sha512-UksbANNE/f8w0wOMxVKKIrLCbEMV+oM1uKejmwXr39olg4xqcfBDbXxObJAt6XxHbDa4XTKOlUEcEltXDX+XLQ==
dependencies:
"@types/node" "*"
pg-protocol "*"
pg-types "^4.0.1"
"@types/picomatch@*":
version "2.3.3"
resolved "https://registry.npmmirror.com/@types/picomatch/-/picomatch-2.3.3.tgz#be60498568c19e989e43fb39aa84be1ed3655e92"
@ -8557,7 +8539,7 @@ bessel@^1.0.2:
resolved "https://registry.npmmirror.com/bessel/-/bessel-1.0.2.tgz#828812291e0b62e94959cdea43fac186e8a7202d"
integrity sha512-Al3nHGQGqDYqqinXhQzmwmcRToe/3WyBv4N8aZc5Pef8xw2neZlR9VPi84Sa23JtgWcucu18HxVZrnI0fn2etw==
big-integer@^1.6.44, big-integer@^1.6.48:
big-integer@^1.6.44:
version "1.6.52"
resolved "https://registry.npmmirror.com/big-integer/-/big-integer-1.6.52.tgz#60a887f3047614a8e1bffe5d7173490a97dc8c85"
integrity sha512-QxD8cf2eVqJOOz63z6JIN9BzvVs/dlySa5HGSBH5xtR8dPteIRQnBxxKqkNTiT6jbDTF6jAfrd4oMcND9RGbQg==
@ -15915,11 +15897,6 @@ jest-worker@^29.7.0:
merge-stream "^2.0.0"
supports-color "^8.0.0"
jmespath@^0.16.0:
version "0.16.0"
resolved "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076"
integrity sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==
jose@^4.15.1:
version "4.15.4"
resolved "https://registry.npmmirror.com/jose/-/jose-4.15.4.tgz#02a9a763803e3872cf55f29ecef0dfdcc218cc03"
@ -16109,11 +16086,6 @@ json5@^2.1.2, json5@^2.2.2, json5@^2.2.3:
resolved "https://registry.npmmirror.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
jsonata@^2.0.3:
version "2.0.3"
resolved "https://registry.npmjs.org/jsonata/-/jsonata-2.0.3.tgz#f8971c2891cb1d6ebfeecbfe657ecc38c1b843a5"
integrity sha512-Up2H81MUtjqI/dWwWX7p4+bUMfMrQJVMN/jW6clFMTiYP528fBOBNtRu944QhKTs3+IsVWbgMeUTny5fw2VMUA==
jsonc-parser@^3.2.0:
version "3.2.0"
resolved "https://registry.npmmirror.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
@ -16147,11 +16119,6 @@ jsonparse@^1.2.0, jsonparse@^1.3.1:
resolved "https://registry.npmmirror.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
integrity sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==
jsonpath-plus@^7.2.0:
version "7.2.0"
resolved "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz#7ad94e147b3ed42f7939c315d2b9ce490c5a3899"
integrity sha512-zBfiUPM5nD0YZSBT/o/fbCUlCcepMIdP0CJZxM1+KgA4f2T206f6VAg9e7mX35+KlMaIc5qXW34f3BnwJ3w+RA==
jsonwebtoken@^8.5.1:
version "8.5.1"
resolved "https://registry.npmmirror.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
@ -18593,13 +18560,6 @@ node-releases@^2.0.14:
resolved "https://registry.npmmirror.com/node-releases/-/node-releases-2.0.14.tgz#2ffb053bceb8b2be8495ece1ab6ce600c4461b0b"
integrity sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==
node-sql-parser@^4.11.0:
version "4.17.0"
resolved "https://registry.npmjs.org/node-sql-parser/-/node-sql-parser-4.17.0.tgz#00d31b9943edd93f5a33cd2db2691df41a1e2225"
integrity sha512-3IhovpmUBpcETnoKK/KBdkz2mz53kVG5E1dnqz1QuYvtzdxYZW5xaGGEvW9u6Yyy2ivwR3eUZrn9inmEVef02w==
dependencies:
big-integer "^1.6.48"
node-xlsx@^0.16.1:
version "0.16.2"
resolved "https://registry.npmmirror.com/node-xlsx/-/node-xlsx-0.16.2.tgz#40f580187eae0e032cac96e958e97cb6ceca09f6"
@ -19068,7 +19028,7 @@ object.values@^1.1.6, object.values@^1.1.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"
obuf@^1.0.0, obuf@^1.1.2, obuf@~1.1.2:
obuf@^1.0.0, obuf@^1.1.2:
version "1.1.2"
resolved "https://registry.npmmirror.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
integrity sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==
@ -19897,17 +19857,12 @@ pg-int8@1.0.1:
resolved "https://registry.npmmirror.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
pg-numeric@1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz#816d9a44026086ae8ae74839acd6a09b0636aa3a"
integrity sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==
pg-pool@^3.6.1:
version "3.6.1"
resolved "https://registry.npmmirror.com/pg-pool/-/pg-pool-3.6.1.tgz#5a902eda79a8d7e3c928b77abf776b3cb7d351f7"
integrity sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==
pg-protocol@*, pg-protocol@^1.6.0:
pg-protocol@^1.6.0:
version "1.6.0"
resolved "https://registry.npmmirror.com/pg-protocol/-/pg-protocol-1.6.0.tgz#4c91613c0315349363af2084608db843502f8833"
integrity sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==
@ -19923,20 +19878,7 @@ pg-types@^2.1.0:
postgres-date "~1.0.4"
postgres-interval "^1.1.0"
pg-types@^4.0.1:
version "4.0.1"
resolved "https://registry.npmjs.org/pg-types/-/pg-types-4.0.1.tgz#31857e89d00a6c66b06a14e907c3deec03889542"
integrity sha512-hRCSDuLII9/LE3smys1hRHcu5QGcLs9ggT7I/TCs0IE+2Eesxi9+9RWAAwZ0yaGjxoWICF/YHLOEjydGujoJ+g==
dependencies:
pg-int8 "1.0.1"
pg-numeric "1.0.2"
postgres-array "~3.0.1"
postgres-bytea "~3.0.0"
postgres-date "~2.0.1"
postgres-interval "^3.0.0"
postgres-range "^1.1.1"
pg@^8.11.3, pg@^8.7.3:
pg@^8.7.3:
version "8.11.3"
resolved "https://registry.npmmirror.com/pg/-/pg-8.11.3.tgz#d7db6e3fe268fcedd65b8e4599cda0b8b4bf76cb"
integrity sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g==
@ -20534,33 +20476,16 @@ postgres-array@~2.0.0:
resolved "https://registry.npmmirror.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==
postgres-array@~3.0.1:
version "3.0.2"
resolved "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.2.tgz#68d6182cb0f7f152a7e60dc6a6889ed74b0a5f98"
integrity sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==
postgres-bytea@~1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
integrity sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==
postgres-bytea@~3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz#9048dc461ac7ba70a6a42d109221619ecd1cb089"
integrity sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==
dependencies:
obuf "~1.1.2"
postgres-date@~1.0.4:
version "1.0.7"
resolved "https://registry.npmmirror.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==
postgres-date@~2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/postgres-date/-/postgres-date-2.0.1.tgz#638b62e5c33764c292d37b08f5257ecb09231457"
integrity sha512-YtMKdsDt5Ojv1wQRvUhnyDJNSr2dGIC96mQVKz7xufp07nfuFONzdaowrMHjlAzY6GDLd4f+LUHHAAM1h4MdUw==
postgres-interval@^1.1.0:
version "1.2.0"
resolved "https://registry.npmmirror.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
@ -20568,16 +20493,6 @@ postgres-interval@^1.1.0:
dependencies:
xtend "^4.0.0"
postgres-interval@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz#baf7a8b3ebab19b7f38f07566c7aab0962f0c86a"
integrity sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==
postgres-range@^1.1.1:
version "1.1.3"
resolved "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.3.tgz#9ccd7b01ca2789eb3c2e0888b3184225fa859f76"
integrity sha512-VdlZoocy5lCP0c/t66xAfclglEapXPCIVhqqJRncYpvbCgImF0w67aPKfbqUMr72tO2k5q0TdTZwCLjPTI6C9g==
prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.npmmirror.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
@ -22824,7 +22739,7 @@ sequelize-pool@^7.1.0:
resolved "https://registry.npmmirror.com/sequelize-pool/-/sequelize-pool-7.1.0.tgz#210b391af4002762f823188fd6ecfc7413020768"
integrity sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==
sequelize@^6.26.0, sequelize@^6.35.0:
sequelize@^6.26.0:
version "6.35.2"
resolved "https://registry.npmmirror.com/sequelize/-/sequelize-6.35.2.tgz#9276d24055a9a07bd6812c89ab402659f5853e70"
integrity sha512-EdzLaw2kK4/aOnWQ7ed/qh3B6/g+1DvmeXr66RwbcqSm/+QRS9X0LDI5INBibsy4eNJHWIRPo3+QK0zL+IPBHg==