@nocobase/build 2.1.0-beta.9 → 2.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build.js +274 -70
- package/lib/buildCjs.js +24 -19
- package/lib/buildClient.js +113 -53
- package/lib/buildDeclaration.js +17 -2
- package/lib/buildPlugin.js +76 -79
- package/lib/constant.js +14 -2
- package/lib/deleteServerFiles.js +68 -0
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +111 -0
- package/lib/plugins/pluginRspackCommercialLoader.js +3 -2
- package/lib/utils/buildPluginUtils.js +14 -1
- package/lib/utils/getDepsConfig.js +9 -5
- package/lib/utils/getPackages.js +48 -0
- package/lib/utils/obfuscationResult.js +2 -1
- package/lib/utils/utils.js +123 -1
- package/package.json +8 -6
package/lib/buildDeclaration.js
CHANGED
|
@@ -53,7 +53,11 @@ const diagnosticHost = {
|
|
|
53
53
|
getCanonicalFileName: (fileName) => import_typescript.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
54
54
|
getNewLine: () => import_typescript.default.sys.newLine
|
|
55
55
|
};
|
|
56
|
+
let cachedBaseCompilerOptions = null;
|
|
56
57
|
function loadCompilerOptions() {
|
|
58
|
+
if (cachedBaseCompilerOptions) {
|
|
59
|
+
return { ...cachedBaseCompilerOptions };
|
|
60
|
+
}
|
|
57
61
|
const configPath = import_path.default.join(import_constant.ROOT_PATH, "tsconfig.json");
|
|
58
62
|
const configFile = import_typescript.default.readConfigFile(configPath, import_typescript.default.sys.readFile);
|
|
59
63
|
if (configFile.error) {
|
|
@@ -70,7 +74,8 @@ function loadCompilerOptions() {
|
|
|
70
74
|
...parsedConfig.options
|
|
71
75
|
};
|
|
72
76
|
delete options.paths;
|
|
73
|
-
|
|
77
|
+
cachedBaseCompilerOptions = Object.freeze({ ...options });
|
|
78
|
+
return { ...cachedBaseCompilerOptions };
|
|
74
79
|
}
|
|
75
80
|
const buildDeclaration = async (cwd, targetDir) => {
|
|
76
81
|
const srcPath = import_path.default.join(cwd, "src");
|
|
@@ -92,7 +97,17 @@ const buildDeclaration = async (cwd, targetDir) => {
|
|
|
92
97
|
outDir: targetPath,
|
|
93
98
|
rootDir: srcPath
|
|
94
99
|
};
|
|
95
|
-
const
|
|
100
|
+
const host = import_typescript.default.createCompilerHost(compilerOptions);
|
|
101
|
+
const originalDirectoryExists = host.directoryExists?.bind(host);
|
|
102
|
+
const rootPrefix = import_constant.ROOT_PATH.endsWith(import_path.default.sep) ? import_constant.ROOT_PATH : import_constant.ROOT_PATH + import_path.default.sep;
|
|
103
|
+
host.directoryExists = (dirPath) => {
|
|
104
|
+
const resolved = import_path.default.resolve(dirPath);
|
|
105
|
+
if (resolved !== import_constant.ROOT_PATH && !resolved.startsWith(rootPrefix) && resolved.includes(`${import_path.default.sep}node_modules`)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return originalDirectoryExists ? originalDirectoryExists(dirPath) : import_typescript.default.sys.directoryExists(dirPath);
|
|
109
|
+
};
|
|
110
|
+
const program = import_typescript.default.createProgram(files, compilerOptions, host);
|
|
96
111
|
const emitResult = program.emit(void 0, void 0, void 0, true);
|
|
97
112
|
const diagnostics = import_typescript.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
98
113
|
if (diagnostics.length) {
|
package/lib/buildPlugin.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(buildPlugin_exports, {
|
|
|
32
32
|
buildPluginServer: () => buildPluginServer,
|
|
33
33
|
buildProPluginServer: () => buildProPluginServer,
|
|
34
34
|
buildServerDeps: () => buildServerDeps,
|
|
35
|
-
deleteServerFiles: () => deleteServerFiles,
|
|
36
35
|
writeExternalPackageVersion: () => writeExternalPackageVersion
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(buildPlugin_exports);
|
|
@@ -47,14 +46,34 @@ var import_path = __toESM(require("path"));
|
|
|
47
46
|
var import_tsup = require("tsup");
|
|
48
47
|
var import_constant = require("./constant");
|
|
49
48
|
var import_pluginEsbuildCommercialInject = __toESM(require("./plugins/pluginEsbuildCommercialInject"));
|
|
49
|
+
var import_deleteServerFiles = require("./deleteServerFiles");
|
|
50
50
|
var import_utils = require("./utils");
|
|
51
51
|
var import_buildPluginUtils = require("./utils/buildPluginUtils");
|
|
52
52
|
var import_getDepsConfig = require("./utils/getDepsConfig");
|
|
53
53
|
var import_obfuscationResult = require("./utils/obfuscationResult");
|
|
54
|
+
var import_injectPublicPathPlugin = require("./injectPublicPathPlugin");
|
|
54
55
|
const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
55
|
-
const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
|
|
56
|
-
const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
|
|
56
|
+
const serverGlobalFiles = ["src/**", "!src/client/**", "!src/client-v2/**", ...import_constant.globExcludeFiles];
|
|
57
57
|
const sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/**/__tests__", "!src/**/__benchmarks__"];
|
|
58
|
+
const pluginClientLaneConfig = {
|
|
59
|
+
client: {
|
|
60
|
+
distDir: "client",
|
|
61
|
+
entryDir: "client",
|
|
62
|
+
rootEntryFile: "client.js",
|
|
63
|
+
externalSubpaths: ["client", "client-v2"]
|
|
64
|
+
},
|
|
65
|
+
"client-v2": {
|
|
66
|
+
distDir: "client-v2",
|
|
67
|
+
entryDir: "client-v2",
|
|
68
|
+
rootEntryFile: "client-v2.js",
|
|
69
|
+
externalSubpaths: ["client", "client-v2"]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function getClientGlobalFiles(lane) {
|
|
73
|
+
const entryDir = pluginClientLaneConfig[lane].entryDir;
|
|
74
|
+
const excludedClientDirs = Object.values(pluginClientLaneConfig).map((item) => item.entryDir).filter((dir) => dir !== entryDir).map((dir) => `!src/${dir}/**`);
|
|
75
|
+
return ["src/**", "!src/server/**", ...excludedClientDirs, ...import_constant.globExcludeFiles];
|
|
76
|
+
}
|
|
58
77
|
const external = [
|
|
59
78
|
// nocobase
|
|
60
79
|
"@nocobase/ai",
|
|
@@ -141,21 +160,20 @@ const external = [
|
|
|
141
160
|
"ahooks",
|
|
142
161
|
"lodash",
|
|
143
162
|
"china-division",
|
|
144
|
-
"file-saver",
|
|
145
163
|
// langChain
|
|
146
164
|
"langchain",
|
|
147
165
|
"@langchain/core",
|
|
148
166
|
"@langchain/classic",
|
|
149
167
|
"@langchain/langgraph",
|
|
150
168
|
"@langchain/langgraph-checkpoint",
|
|
151
|
-
"@langchain/community",
|
|
152
169
|
"@langchain/openai",
|
|
153
170
|
"@langchain/anthropic",
|
|
154
171
|
"@langchain/google-genai",
|
|
155
172
|
"@langchain/deepseek",
|
|
156
|
-
"@langchain/ollama"
|
|
173
|
+
"@langchain/ollama",
|
|
174
|
+
"@langchain/mcp-adapters"
|
|
157
175
|
];
|
|
158
|
-
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset
|
|
176
|
+
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-").split(",");
|
|
159
177
|
const target_dir = "dist";
|
|
160
178
|
function appendAiFiles(cwd, files) {
|
|
161
179
|
const aiFiles = import_fast_glob.default.globSync(["src/ai/**/*.md"], { cwd, absolute: true });
|
|
@@ -230,24 +248,6 @@ async function copyAiDocSources(cwd, log) {
|
|
|
230
248
|
await import_fs_extra.default.writeJSON(rootMetaPath, Array.from(rootMetaMap.values()), { spaces: 2 });
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
|
-
function deleteServerFiles(cwd, log) {
|
|
234
|
-
log("delete server files");
|
|
235
|
-
const files = import_fast_glob.default.globSync(["*"], {
|
|
236
|
-
cwd: import_path.default.join(cwd, target_dir),
|
|
237
|
-
absolute: true,
|
|
238
|
-
deep: 1,
|
|
239
|
-
onlyFiles: true
|
|
240
|
-
});
|
|
241
|
-
const dirs = import_fast_glob.default.globSync(["*", "!client", "!node_modules"], {
|
|
242
|
-
cwd: import_path.default.join(cwd, target_dir),
|
|
243
|
-
absolute: true,
|
|
244
|
-
deep: 1,
|
|
245
|
-
onlyDirectories: true
|
|
246
|
-
});
|
|
247
|
-
[...files, ...dirs].forEach((item) => {
|
|
248
|
-
import_fs_extra.default.removeSync(item);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
251
|
function writeExternalPackageVersion(cwd, log) {
|
|
252
252
|
log("write external version");
|
|
253
253
|
const sourceFiles = import_fast_glob.default.globSync(sourceGlobalFiles, { cwd, absolute: true }).map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
|
|
@@ -269,7 +269,7 @@ async function buildServerDeps(cwd, serverFiles, log) {
|
|
|
269
269
|
const sourcePackages = (0, import_buildPluginUtils.getSourcePackages)(serverFileSource);
|
|
270
270
|
const includePackages = (0, import_buildPluginUtils.getIncludePackages)(sourcePackages, external, pluginPrefix);
|
|
271
271
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
272
|
-
|
|
272
|
+
const tips = [];
|
|
273
273
|
if (includePackages.length) {
|
|
274
274
|
tips.push(
|
|
275
275
|
`These packages ${import_chalk.default.yellow(includePackages.join(", "))} will be ${import_chalk.default.italic(
|
|
@@ -318,8 +318,10 @@ async function buildServerDeps(cwd, serverFiles, log) {
|
|
|
318
318
|
});
|
|
319
319
|
await (0, import_ncc.default)(dep, nccConfig).then(
|
|
320
320
|
({ code, assets }) => {
|
|
321
|
+
import_fs_extra.default.ensureDirSync(import_path.default.dirname(mainFile));
|
|
321
322
|
import_fs_extra.default.writeFileSync(mainFile, code, "utf-8");
|
|
322
323
|
Object.entries(assets).forEach(([name, item]) => {
|
|
324
|
+
import_fs_extra.default.ensureDirSync(import_path.default.dirname(import_path.default.join(outputDir, name)));
|
|
323
325
|
import_fs_extra.default.writeFileSync(import_path.default.join(outputDir, name), item.source, {
|
|
324
326
|
encoding: "utf-8",
|
|
325
327
|
mode: item.permissions
|
|
@@ -349,7 +351,7 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
349
351
|
if (otherExts.length) {
|
|
350
352
|
log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
|
|
351
353
|
}
|
|
352
|
-
deleteServerFiles(cwd, log);
|
|
354
|
+
(0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
|
|
353
355
|
await (0, import_tsup.build)(
|
|
354
356
|
userConfig.modifyTsupConfig({
|
|
355
357
|
entry: serverFiles,
|
|
@@ -365,7 +367,8 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
365
367
|
skipNodeModulesBundle: true,
|
|
366
368
|
loader: {
|
|
367
369
|
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
|
|
368
|
-
".json": "copy"
|
|
370
|
+
".json": "copy",
|
|
371
|
+
".txt": "copy"
|
|
369
372
|
}
|
|
370
373
|
})
|
|
371
374
|
);
|
|
@@ -384,7 +387,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
384
387
|
if (otherExts.length) {
|
|
385
388
|
log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
|
|
386
389
|
}
|
|
387
|
-
deleteServerFiles(cwd, log);
|
|
390
|
+
(0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
|
|
388
391
|
let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
389
392
|
import_fs_extra.default.writeFileSync(
|
|
390
393
|
import_path.default.join(cwd, "tsconfig.json"),
|
|
@@ -413,7 +416,8 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
413
416
|
skipNodeModulesBundle: true,
|
|
414
417
|
loader: {
|
|
415
418
|
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
|
|
416
|
-
".json": "copy"
|
|
419
|
+
".json": "copy",
|
|
420
|
+
".txt": "copy"
|
|
417
421
|
}
|
|
418
422
|
})
|
|
419
423
|
);
|
|
@@ -461,7 +465,8 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
461
465
|
tsconfig: tsconfig.path,
|
|
462
466
|
loader: {
|
|
463
467
|
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
|
|
464
|
-
".json": "copy"
|
|
468
|
+
".json": "copy",
|
|
469
|
+
".txt": "copy"
|
|
465
470
|
},
|
|
466
471
|
...externalOptions
|
|
467
472
|
})
|
|
@@ -469,9 +474,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
469
474
|
import_fs_extra.default.removeSync(tsconfig.path);
|
|
470
475
|
await buildServerDeps(cwd, serverFiles, log);
|
|
471
476
|
}
|
|
472
|
-
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
473
|
-
|
|
477
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
|
|
478
|
+
const laneConfig = pluginClientLaneConfig[lane];
|
|
479
|
+
const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
|
|
480
|
+
const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
|
|
481
|
+
if (!import_fs_extra.default.existsSync(rootEntryFile)) {
|
|
482
|
+
log("skip plugin %s build, root entry not found", lane);
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
if (!import_fs_extra.default.existsSync(entryDir)) {
|
|
486
|
+
log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
|
|
487
|
+
process.exit(-1);
|
|
488
|
+
}
|
|
489
|
+
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
|
|
490
|
+
if (!entry[0]) {
|
|
491
|
+
log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
|
|
492
|
+
process.exit(-1);
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
log("build plugin %s", lane);
|
|
474
496
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
497
|
+
const clientGlobalFiles = getClientGlobalFiles(lane);
|
|
475
498
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
476
499
|
if (isCommercial) {
|
|
477
500
|
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
@@ -480,36 +503,41 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
480
503
|
});
|
|
481
504
|
clientFiles.push(...commercialFiles);
|
|
482
505
|
}
|
|
483
|
-
const
|
|
484
|
-
|
|
506
|
+
const sourceCwds = [cwd];
|
|
507
|
+
if (isCommercial) {
|
|
508
|
+
sourceCwds.push(import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL));
|
|
509
|
+
}
|
|
510
|
+
const sourcePackages = (0, import_buildPluginUtils.getPluginBrowserSourcePackages)(sourceCwds, import_constant.globExcludeFiles);
|
|
485
511
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
512
|
+
const browserExternalPackages = excludePackages.filter((packageName) => packageName !== "file-saver");
|
|
486
513
|
(0, import_buildPluginUtils.checkRequire)(clientFiles, log);
|
|
487
|
-
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry:
|
|
488
|
-
const outDir = import_path.default.join(cwd, target_dir,
|
|
489
|
-
const globals =
|
|
514
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
|
|
515
|
+
const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
|
|
516
|
+
const globals = browserExternalPackages.reduce((prev, curr) => {
|
|
490
517
|
if (curr.startsWith("@nocobase")) {
|
|
491
|
-
|
|
518
|
+
laneConfig.externalSubpaths.forEach((subpath) => {
|
|
519
|
+
prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
|
|
520
|
+
});
|
|
492
521
|
}
|
|
493
522
|
prev[curr] = curr;
|
|
494
523
|
return prev;
|
|
495
524
|
}, {});
|
|
496
|
-
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
|
|
497
525
|
const outputFileName = "index.js";
|
|
498
526
|
const compiler = (0, import_core.rspack)({
|
|
499
527
|
mode: "production",
|
|
500
528
|
// mode: "development",
|
|
501
529
|
context: cwd,
|
|
502
|
-
entry:
|
|
530
|
+
entry: `./src/${laneConfig.entryDir}/` + entry[0],
|
|
503
531
|
target: ["web", "es5"],
|
|
504
532
|
output: {
|
|
505
533
|
path: outDir,
|
|
506
534
|
filename: outputFileName,
|
|
507
|
-
chunkFilename: "[
|
|
535
|
+
chunkFilename: "[name].[contenthash].js",
|
|
508
536
|
publicPath: `auto`,
|
|
509
537
|
// will be generated by the custom plugin
|
|
510
538
|
clean: true,
|
|
511
539
|
library: {
|
|
512
|
-
name: packageJson.name,
|
|
540
|
+
name: lane === "client-v2" ? `${packageJson.name}/client-v2` : packageJson.name,
|
|
513
541
|
type: "umd",
|
|
514
542
|
umdNamedDefine: true
|
|
515
543
|
}
|
|
@@ -581,18 +609,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
581
609
|
// *.svg?react
|
|
582
610
|
use: ["@svgr/webpack"]
|
|
583
611
|
},
|
|
584
|
-
{
|
|
585
|
-
test: /\.(?:js|mjs|cjs|ts|tsx)$/,
|
|
586
|
-
exclude: /node_modules/,
|
|
587
|
-
use: {
|
|
588
|
-
loader: "babel-loader",
|
|
589
|
-
options: {
|
|
590
|
-
targets: "defaults",
|
|
591
|
-
// presets: [['@babel/preset-env']],
|
|
592
|
-
plugins: ["react-imported-component/babel"]
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
},
|
|
596
612
|
{
|
|
597
613
|
test: /\.jsx$/,
|
|
598
614
|
exclude: /[\\/]node_modules[\\/]/,
|
|
@@ -672,27 +688,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
672
688
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
673
689
|
"process.env.NODE_DEBUG": false
|
|
674
690
|
}),
|
|
675
|
-
|
|
676
|
-
apply(compiler2) {
|
|
677
|
-
compiler2.hooks.compilation.tap("CustomPublicPathPlugin", (compilation) => {
|
|
678
|
-
compilation.hooks.runtimeModule.tap("CustomPublicPathPlugin", (module2) => {
|
|
679
|
-
if (module2.name === "auto_public_path") {
|
|
680
|
-
module2.source = {
|
|
681
|
-
source: `
|
|
682
|
-
__webpack_require__.p = (function() {
|
|
683
|
-
var publicPath = window['__webpack_public_path__'] || '/';
|
|
684
|
-
// \u786E\u4FDD\u8DEF\u5F84\u4EE5 / \u7ED3\u5C3E
|
|
685
|
-
if (!publicPath.endsWith('/')) {
|
|
686
|
-
publicPath += '/';
|
|
687
|
-
}
|
|
688
|
-
return publicPath + 'static/plugins/${packageJson.name}/dist/client/';
|
|
689
|
-
})();`
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
},
|
|
691
|
+
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
|
|
696
692
|
process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
|
|
697
693
|
// plugin options
|
|
698
694
|
// supports: {
|
|
@@ -729,10 +725,12 @@ __webpack_require__.p = (function() {
|
|
|
729
725
|
}
|
|
730
726
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
731
727
|
if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
|
|
732
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log, true);
|
|
728
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
|
|
729
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
|
|
733
730
|
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
734
731
|
} else {
|
|
735
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
732
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
|
|
733
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
|
|
736
734
|
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
737
735
|
}
|
|
738
736
|
writeExternalPackageVersion(cwd, log);
|
|
@@ -744,6 +742,5 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
|
744
742
|
buildPluginServer,
|
|
745
743
|
buildProPluginServer,
|
|
746
744
|
buildServerDeps,
|
|
747
|
-
deleteServerFiles,
|
|
748
745
|
writeExternalPackageVersion
|
|
749
746
|
});
|
package/lib/constant.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(constant_exports, {
|
|
|
30
30
|
CJS_EXCLUDE_PACKAGES: () => CJS_EXCLUDE_PACKAGES,
|
|
31
31
|
CORE_APP: () => CORE_APP,
|
|
32
32
|
CORE_CLIENT: () => CORE_CLIENT,
|
|
33
|
+
CORE_CLIENT_V2: () => CORE_CLIENT_V2,
|
|
33
34
|
ESM_PACKAGES: () => ESM_PACKAGES,
|
|
34
35
|
EsbuildSupportExts: () => EsbuildSupportExts,
|
|
35
36
|
NODE_MODULES: () => NODE_MODULES,
|
|
@@ -90,20 +91,31 @@ const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.so
|
|
|
90
91
|
const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
|
|
91
92
|
const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
|
|
92
93
|
const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
|
|
94
|
+
const CORE_CLIENT_V2 = import_path.default.join(PACKAGES_PATH, "core/client-v2");
|
|
93
95
|
const ESM_PACKAGES = ["@nocobase/test"];
|
|
94
96
|
const CJS_EXCLUDE_PACKAGES = [
|
|
95
97
|
import_path.default.join(PACKAGES_PATH, "core/build"),
|
|
98
|
+
import_path.default.join(PACKAGES_PATH, "core/cli-v1"),
|
|
96
99
|
import_path.default.join(PACKAGES_PATH, "core/cli"),
|
|
97
|
-
CORE_CLIENT
|
|
100
|
+
CORE_CLIENT,
|
|
101
|
+
CORE_CLIENT_V2
|
|
98
102
|
];
|
|
99
103
|
const getCjsPackages = (packages) => packages.filter((item) => !PLUGINS_DIR.some((dir) => item.location.startsWith(dir))).filter((item) => !item.location.startsWith(PRESETS_DIR)).filter((item) => !ESM_PACKAGES.includes(item.name)).filter((item) => !CJS_EXCLUDE_PACKAGES.includes(item.location));
|
|
100
104
|
const tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules"];
|
|
101
|
-
|
|
105
|
+
function resolveStorageRoot() {
|
|
106
|
+
const raw = process.env.STORAGE_PATH;
|
|
107
|
+
if (raw) {
|
|
108
|
+
return import_path.default.isAbsolute(raw) ? raw : import_path.default.resolve(process.cwd(), raw);
|
|
109
|
+
}
|
|
110
|
+
return import_path.default.join(ROOT_PATH, "storage");
|
|
111
|
+
}
|
|
112
|
+
const TAR_OUTPUT_DIR = process.env.TAR_PATH || import_path.default.join(resolveStorageRoot(), "tar");
|
|
102
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
114
|
0 && (module.exports = {
|
|
104
115
|
CJS_EXCLUDE_PACKAGES,
|
|
105
116
|
CORE_APP,
|
|
106
117
|
CORE_CLIENT,
|
|
118
|
+
CORE_CLIENT_V2,
|
|
107
119
|
ESM_PACKAGES,
|
|
108
120
|
EsbuildSupportExts,
|
|
109
121
|
NODE_MODULES,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var deleteServerFiles_exports = {};
|
|
29
|
+
__export(deleteServerFiles_exports, {
|
|
30
|
+
deleteServerFiles: () => deleteServerFiles,
|
|
31
|
+
shouldPreserveDistEntry: () => shouldPreserveDistEntry
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(deleteServerFiles_exports);
|
|
34
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
const targetDir = "dist";
|
|
38
|
+
const preservedDistEntries = /* @__PURE__ */ new Set(["client", "client-v2"]);
|
|
39
|
+
function shouldPreserveDistEntry(item) {
|
|
40
|
+
return preservedDistEntries.has(import_path.default.win32.basename(item));
|
|
41
|
+
}
|
|
42
|
+
function deleteServerFiles(cwd, log) {
|
|
43
|
+
log("delete server files");
|
|
44
|
+
const distDir = import_path.default.join(cwd, targetDir);
|
|
45
|
+
const files = import_fast_glob.default.globSync(["*"], {
|
|
46
|
+
cwd: distDir,
|
|
47
|
+
absolute: true,
|
|
48
|
+
deep: 1,
|
|
49
|
+
onlyFiles: true
|
|
50
|
+
});
|
|
51
|
+
const dirs = import_fast_glob.default.globSync(["*", "!node_modules"], {
|
|
52
|
+
cwd: distDir,
|
|
53
|
+
absolute: true,
|
|
54
|
+
deep: 1,
|
|
55
|
+
onlyDirectories: true
|
|
56
|
+
});
|
|
57
|
+
[...files, ...dirs].forEach((item) => {
|
|
58
|
+
if (shouldPreserveDistEntry(item)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
import_fs_extra.default.removeSync(item);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
deleteServerFiles,
|
|
67
|
+
shouldPreserveDistEntry
|
|
68
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import type { RsbuildConfig } from '@rsbuild/core'
|
|
11
11
|
import { Options as TsupConfig } from 'tsup'
|
|
12
|
-
import { InlineConfig as ViteConfig } from 'vite'
|
|
13
12
|
|
|
14
13
|
export type PkgLog = (msg: string, ...args: any[]) => void;
|
|
15
14
|
|
|
16
15
|
interface UserConfig {
|
|
17
16
|
modifyTsupConfig?: (config: TsupConfig) => TsupConfig;
|
|
18
|
-
|
|
17
|
+
modifyRsbuildConfig?: (config: RsbuildConfig) => RsbuildConfig;
|
|
19
18
|
beforeBuild?: (log: PkgLog) => void | Promise<void>;
|
|
20
19
|
afterBuild?: (log: PkgLog) => void | Promise<void>;
|
|
21
20
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var injectPublicPathPlugin_exports = {};
|
|
19
|
+
__export(injectPublicPathPlugin_exports, {
|
|
20
|
+
AutoInjectPublicPathPlugin: () => AutoInjectPublicPathPlugin
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(injectPublicPathPlugin_exports);
|
|
23
|
+
function createPluginClientPublicPathDataUri(packageName, clientDistDir) {
|
|
24
|
+
const code = `
|
|
25
|
+
var publicPath = '';
|
|
26
|
+
var currentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
27
|
+
if (currentScript && currentScript.src) {
|
|
28
|
+
publicPath = currentScript.src
|
|
29
|
+
.replace(/^blob:/, '')
|
|
30
|
+
.replace(/#.*$/, '')
|
|
31
|
+
.replace(/\\?.*$/, '')
|
|
32
|
+
.replace(/\\/[^\\/]+$/, '/');
|
|
33
|
+
}
|
|
34
|
+
if (!publicPath) {
|
|
35
|
+
var runtimeAssetBase = window['__webpack_public_path__'] || '';
|
|
36
|
+
if (runtimeAssetBase) {
|
|
37
|
+
if (runtimeAssetBase.charAt(runtimeAssetBase.length - 1) !== '/') {
|
|
38
|
+
runtimeAssetBase += '/';
|
|
39
|
+
}
|
|
40
|
+
publicPath = runtimeAssetBase + 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!publicPath) {
|
|
44
|
+
var modernPrefix = window['__nocobase_modern_client_prefix__'] || 'v';
|
|
45
|
+
modernPrefix = String(modernPrefix).replace(/^\\/+|\\/+$/g, '') || 'v';
|
|
46
|
+
var marker = '/' + modernPrefix + '/';
|
|
47
|
+
publicPath = window['__nocobase_public_path__'] || '';
|
|
48
|
+
if (!publicPath && window.location && window.location.pathname) {
|
|
49
|
+
var pathname = window.location.pathname || '/';
|
|
50
|
+
var index = pathname.indexOf(marker);
|
|
51
|
+
publicPath = index >= 0 ? pathname.slice(0, index + 1) : '/';
|
|
52
|
+
}
|
|
53
|
+
if (publicPath) {
|
|
54
|
+
publicPath = publicPath.replace(new RegExp('/' + modernPrefix + '/?$'), '/');
|
|
55
|
+
}
|
|
56
|
+
if (!publicPath) {
|
|
57
|
+
publicPath = '/';
|
|
58
|
+
}
|
|
59
|
+
if (publicPath.charAt(publicPath.length - 1) !== '/') {
|
|
60
|
+
publicPath += '/';
|
|
61
|
+
}
|
|
62
|
+
publicPath += 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
63
|
+
}
|
|
64
|
+
__webpack_public_path__ = publicPath;
|
|
65
|
+
`;
|
|
66
|
+
return `data:text/javascript,${encodeURIComponent(code)}`;
|
|
67
|
+
}
|
|
68
|
+
function prependPluginClientPublicPathEntry(entry, packageName, clientDistDir) {
|
|
69
|
+
const dataUri = createPluginClientPublicPathDataUri(packageName, clientDistDir);
|
|
70
|
+
if (typeof entry === "string") {
|
|
71
|
+
return [dataUri, entry];
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(entry)) {
|
|
74
|
+
return [dataUri, ...entry];
|
|
75
|
+
}
|
|
76
|
+
if (!entry || typeof entry !== "object") {
|
|
77
|
+
return entry;
|
|
78
|
+
}
|
|
79
|
+
const entryConfig = entry;
|
|
80
|
+
if (entryConfig.import) {
|
|
81
|
+
return {
|
|
82
|
+
...entryConfig,
|
|
83
|
+
import: Array.isArray(entryConfig.import) ? [dataUri, ...entryConfig.import] : [dataUri, entryConfig.import]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return Object.fromEntries(
|
|
87
|
+
Object.entries(entryConfig).map(([name, value]) => [
|
|
88
|
+
name,
|
|
89
|
+
prependPluginClientPublicPathEntry(value, packageName, clientDistDir)
|
|
90
|
+
])
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
class AutoInjectPublicPathPlugin {
|
|
94
|
+
constructor(pluginName, clientDistDir = "client") {
|
|
95
|
+
this.pluginName = pluginName;
|
|
96
|
+
this.clientDistDir = clientDistDir;
|
|
97
|
+
}
|
|
98
|
+
apply(compiler) {
|
|
99
|
+
compiler.hooks.environment.tap("AutoInjectPublicPathPlugin", () => {
|
|
100
|
+
compiler.options.entry = prependPluginClientPublicPathEntry(
|
|
101
|
+
compiler.options.entry,
|
|
102
|
+
this.pluginName,
|
|
103
|
+
this.clientDistDir
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
AutoInjectPublicPathPlugin
|
|
111
|
+
});
|
|
@@ -25,7 +25,8 @@ function myLoader(source) {
|
|
|
25
25
|
if (!options?.isCommercial) {
|
|
26
26
|
return source;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const isClientV2Plugin = this.resourcePath.match(/client-v2\/plugin\.(ts|tsx)/) && !this.resourcePath.includes("plugin-commercial");
|
|
29
|
+
const isEntry = (this.resourcePath.match(/client\/index\.(ts|tsx)/) || isClientV2Plugin) && !this.resourcePath.includes("plugin-commercial");
|
|
29
30
|
if (isEntry) {
|
|
30
31
|
const regex = /export\s+default\s+([a-zA-Z_0-9]+)\s*;?/;
|
|
31
32
|
const match = source.match(regex);
|
|
@@ -33,7 +34,7 @@ function myLoader(source) {
|
|
|
33
34
|
source = source.replace(regex, ``);
|
|
34
35
|
const moduleName = match[1];
|
|
35
36
|
source = `
|
|
36
|
-
import { withCommercial } from '@nocobase/plugin-commercial
|
|
37
|
+
import { withCommercial } from '@nocobase/plugin-commercial/${isClientV2Plugin ? "client-v2" : "client"}';
|
|
37
38
|
${source}
|
|
38
39
|
export default withCommercial(${moduleName});
|
|
39
40
|
`;
|
|
@@ -39,6 +39,7 @@ __export(buildPluginUtils_exports, {
|
|
|
39
39
|
getPackageJsonPackages: () => getPackageJsonPackages,
|
|
40
40
|
getPackageNameFromString: () => getPackageNameFromString,
|
|
41
41
|
getPackagesFromFiles: () => getPackagesFromFiles,
|
|
42
|
+
getPluginBrowserSourcePackages: () => getPluginBrowserSourcePackages,
|
|
42
43
|
getSourcePackages: () => getSourcePackages,
|
|
43
44
|
isNotBuiltinModule: () => isNotBuiltinModule,
|
|
44
45
|
isValidPackageName: () => isValidPackageName
|
|
@@ -46,6 +47,7 @@ __export(buildPluginUtils_exports, {
|
|
|
46
47
|
module.exports = __toCommonJS(buildPluginUtils_exports);
|
|
47
48
|
var import_fs = __toESM(require("fs"));
|
|
48
49
|
var import_chalk = __toESM(require("chalk"));
|
|
50
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
49
51
|
var import_module = require("module");
|
|
50
52
|
var import_path = __toESM(require("path"));
|
|
51
53
|
const requireRegex = /require\s*\(['"`](.*?)['"`]\)/g;
|
|
@@ -54,7 +56,7 @@ function isNotBuiltinModule(packageName) {
|
|
|
54
56
|
return !import_module.builtinModules.includes(packageName);
|
|
55
57
|
}
|
|
56
58
|
const isValidPackageName = (str) => {
|
|
57
|
-
const pattern = /^(?:@[a-zA-Z0-
|
|
59
|
+
const pattern = /^(?:@[a-zA-Z0-9._-]+\/)?[a-zA-Z0-9._-]+$/;
|
|
58
60
|
return pattern.test(str);
|
|
59
61
|
};
|
|
60
62
|
function getPackageNameFromString(str) {
|
|
@@ -76,6 +78,16 @@ function getPackagesFromFiles(files) {
|
|
|
76
78
|
]).flat().map(getPackageNameFromString).filter(Boolean).filter(isNotBuiltinModule);
|
|
77
79
|
return [...new Set(packageNames)];
|
|
78
80
|
}
|
|
81
|
+
function getPluginBrowserSourcePackages(cwds, excludeFiles) {
|
|
82
|
+
const files = cwds.flatMap(
|
|
83
|
+
(cwd) => import_fast_glob.default.globSync(["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/server/**", ...excludeFiles], {
|
|
84
|
+
cwd,
|
|
85
|
+
absolute: true
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
const source = files.map((item) => import_fs.default.readFileSync(item, "utf-8"));
|
|
89
|
+
return getPackagesFromFiles(source);
|
|
90
|
+
}
|
|
79
91
|
function getSourcePackages(fileSources) {
|
|
80
92
|
return getPackagesFromFiles(fileSources);
|
|
81
93
|
}
|
|
@@ -163,6 +175,7 @@ function checkFileSize(outDir, log) {
|
|
|
163
175
|
getPackageJsonPackages,
|
|
164
176
|
getPackageNameFromString,
|
|
165
177
|
getPackagesFromFiles,
|
|
178
|
+
getPluginBrowserSourcePackages,
|
|
166
179
|
getSourcePackages,
|
|
167
180
|
isNotBuiltinModule,
|
|
168
181
|
isValidPackageName
|