fix: support pro plugins

This commit is contained in:
chenos 2022-11-03 15:56:27 +08:00
parent 8e182a6add
commit def0f642d7
5 changed files with 19 additions and 5 deletions

View File

@ -12,6 +12,7 @@
"strict": true,
"paths": {
"@nocobase/plugin-sample-*/client": ["../../samples/*/src/client"],
"@nocobase/plugin-pro-*/client": ["../../pro-plugins/*/src/client"],
"@nocobase/plugin-*/client": ["../../plugins/*/src/client"],
"@nocobase/utils/client": ["../../core/utils/src/client"],
"@nocobase/*": ["../../core/*/src/"],

View File

@ -73,6 +73,14 @@ function resolveNocobasePackagesAlias(config) {
config.resolve.alias.set(`@nocobase/plugin-sample-${package}`, packageSrc);
}
}
const pros = fs.readdirSync(resolve(process.cwd(), './packages/pro-plugins'));
for (const package of pros) {
const packageSrc = resolve(process.cwd(), './packages/pro-plugins/', package, 'src');
if (existsSync(packageSrc)) {
config.module.rules.get('ts-in-node_modules').include.add(packageSrc);
config.resolve.alias.set(`@nocobase/plugin-pro-${package}`, packageSrc);
}
}
}
exports.getUmiConfig = getUmiConfig;

View File

@ -194,8 +194,9 @@ export class PluginManager {
throw error;
}
}
// console.log(`adding ${plugin} plugin`);
console.log(`adding ${plugin} plugin`);
const packageName = await PluginManager.findPackage(plugin);
console.log(`adding ${packageName}`);
const packageJson = require(`${packageName}/package.json`);
const instance = this.addStatic(plugin, {
...options,
@ -317,7 +318,7 @@ export class PluginManager {
}
static getPackageName(name: string) {
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-').split(',');
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
for (const prefix of prefixes) {
try {
require.resolve(`${prefix}${name}`);
@ -334,7 +335,7 @@ export class PluginManager {
const packageName = this.getPackageName(name);
return packageName;
} catch (error) {
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-').split(',');
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
for (const prefix of prefixes) {
try {
const packageName = `${prefix}${name}`;

View File

@ -1,4 +1,4 @@
import { Plugin } from '@nocobase/server';
import { Plugin, PluginManager } from '@nocobase/server';
import send from 'koa-send';
import serve from 'koa-static';
import { isAbsolute, resolve } from 'path';
@ -64,7 +64,8 @@ export class ClientPlugin extends Plugin {
ctx.body = items
.filter((item) => {
try {
require.resolve(`@nocobase/plugin-${item.name}/client`);
const packageName = PluginManager.getPackageName(item.name);
require.resolve(`${packageName}/client`);
return true;
} catch (error) {}
return false;

View File

@ -23,6 +23,9 @@
"@nocobase/plugin-sample-*": [
"packages/samples/*/src"
],
"@nocobase/plugin-pro-*": [
"packages/pro-plugins/*/src"
],
"@nocobase/plugin-*": [
"packages/plugins/*/src"
],