mirror of
https://github.com/nocobase/nocobase.git
synced 2026-08-29 02:03:53 +08:00
fix: plugin build error
This commit is contained in:
@@ -33,7 +33,7 @@ import {
|
||||
checkRequire,
|
||||
getExcludePackages,
|
||||
getIncludePackages,
|
||||
getPackagesFromFiles,
|
||||
getPluginBrowserSourcePackages,
|
||||
getSourcePackages,
|
||||
} from './utils/buildPluginUtils';
|
||||
import { getDepPkgPath, getDepsConfig } from './utils/getDepsConfig';
|
||||
@@ -630,8 +630,7 @@ export async function buildPluginClient(
|
||||
});
|
||||
clientFiles.push(...commercialFiles);
|
||||
}
|
||||
const clientFileSource = clientFiles.map((item) => fs.readFileSync(item, 'utf-8'));
|
||||
const sourcePackages = getPackagesFromFiles(clientFileSource);
|
||||
const sourcePackages = getPluginBrowserSourcePackages(cwd, globExcludeFiles);
|
||||
const excludePackages = getExcludePackages(sourcePackages, external, pluginPrefix);
|
||||
|
||||
checkRequire(clientFiles, log);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import chalk from 'chalk';
|
||||
import fg from 'fast-glob';
|
||||
import { builtinModules } from 'module';
|
||||
import path from 'path';
|
||||
|
||||
@@ -73,6 +74,16 @@ export function getPackagesFromFiles(files: string[]): string[] {
|
||||
return [...new Set(packageNames)];
|
||||
}
|
||||
|
||||
export function getPluginBrowserSourcePackages(cwd: string, excludeFiles: string[]): string[] {
|
||||
const files = fg.globSync(['src/**/*.{ts,js,tsx,jsx,mjs}', '!src/server/**', ...excludeFiles], {
|
||||
cwd,
|
||||
absolute: true,
|
||||
});
|
||||
const source = files.map((item) => fs.readFileSync(item, 'utf-8'));
|
||||
|
||||
return getPackagesFromFiles(source);
|
||||
}
|
||||
|
||||
export function getSourcePackages(fileSources: string[]): string[] {
|
||||
return getPackagesFromFiles(fileSources);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import {
|
||||
getPluginBrowserSourcePackages,
|
||||
getPackageNameFromString,
|
||||
getPackagesFromFiles,
|
||||
isValidPackageName,
|
||||
@@ -32,4 +36,35 @@ describe('buildPluginUtils package extraction', () => {
|
||||
|
||||
expect(packages).toEqual(expect.arrayContaining(['big.js', '@scope/pkg.name', 'json-pointer']));
|
||||
});
|
||||
|
||||
it('should discover client-v2 runtime packages for client lane relative imports', () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'nocobase-plugin-browser-source-'));
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path.join(tempRoot, 'src/client'), { recursive: true });
|
||||
fs.mkdirSync(path.join(tempRoot, 'src/client-v2/flow'), { recursive: true });
|
||||
fs.mkdirSync(path.join(tempRoot, 'src/server'), { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(tempRoot, 'src/client/index.tsx'),
|
||||
["import React from 'react';", "import '../client-v2/flow/model';", 'export default React;'].join('\n'),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(tempRoot, 'src/client-v2/flow/model.ts'),
|
||||
[
|
||||
"import { titleField } from '@nocobase/client-v2';",
|
||||
"import { defineAction } from '@nocobase/flow-engine';",
|
||||
'export const model = defineAction({ ...titleField, name: "bulkEditTitleField" });',
|
||||
].join('\n'),
|
||||
);
|
||||
fs.writeFileSync(path.join(tempRoot, 'src/server/plugin.ts'), "import Koa from 'koa';\nexport default Koa;");
|
||||
|
||||
const packages = getPluginBrowserSourcePackages(tempRoot, []);
|
||||
|
||||
expect(packages).toEqual(expect.arrayContaining(['react', '@nocobase/client-v2', '@nocobase/flow-engine']));
|
||||
expect(packages).not.toContain('koa');
|
||||
} finally {
|
||||
fs.rmSync(tempRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user