@nocobase/build 2.1.0-alpha.1 → 2.1.0-alpha.11
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/buildClient.js +113 -53
- package/lib/buildDeclaration.js +67 -23
- package/lib/buildPlugin.js +176 -63
- package/lib/constant.js +6 -2
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +88 -0
- package/lib/utils/utils.js +1 -1
- package/package.json +8 -9
package/lib/buildPlugin.js
CHANGED
|
@@ -51,16 +51,32 @@ 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
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const serverGlobalFiles = ["src/**", "!src/client/**", "!src/client-v2/**", ...import_constant.globExcludeFiles];
|
|
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"]
|
|
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
|
+
}
|
|
62
77
|
const external = [
|
|
63
78
|
// nocobase
|
|
79
|
+
"@nocobase/ai",
|
|
64
80
|
"@nocobase/acl",
|
|
65
81
|
"@nocobase/actions",
|
|
66
82
|
"@nocobase/auth",
|
|
@@ -144,10 +160,96 @@ const external = [
|
|
|
144
160
|
"ahooks",
|
|
145
161
|
"lodash",
|
|
146
162
|
"china-division",
|
|
147
|
-
"file-saver"
|
|
163
|
+
"file-saver",
|
|
164
|
+
// langChain
|
|
165
|
+
"langchain",
|
|
166
|
+
"@langchain/core",
|
|
167
|
+
"@langchain/classic",
|
|
168
|
+
"@langchain/langgraph",
|
|
169
|
+
"@langchain/langgraph-checkpoint",
|
|
170
|
+
"@langchain/community",
|
|
171
|
+
"@langchain/openai",
|
|
172
|
+
"@langchain/anthropic",
|
|
173
|
+
"@langchain/google-genai",
|
|
174
|
+
"@langchain/deepseek",
|
|
175
|
+
"@langchain/ollama",
|
|
176
|
+
"@langchain/mcp-adapters"
|
|
148
177
|
];
|
|
149
178
|
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
|
|
150
179
|
const target_dir = "dist";
|
|
180
|
+
function appendAiFiles(cwd, files) {
|
|
181
|
+
const aiFiles = import_fast_glob.default.globSync(["src/ai/**/*.md"], { cwd, absolute: true });
|
|
182
|
+
if (!aiFiles.length) return files;
|
|
183
|
+
return Array.from(/* @__PURE__ */ new Set([...files, ...aiFiles]));
|
|
184
|
+
}
|
|
185
|
+
function normalizeAiMetaEntries(meta, fallbackModule) {
|
|
186
|
+
if (Array.isArray(meta)) {
|
|
187
|
+
return meta.filter((item) => item && typeof item.module === "string").map((item) => ({
|
|
188
|
+
module: item.module.trim(),
|
|
189
|
+
description: typeof item.description === "string" ? item.description.trim() : "",
|
|
190
|
+
source: typeof item.source === "string" ? item.source.trim() : ""
|
|
191
|
+
})).filter((item) => item.module);
|
|
192
|
+
}
|
|
193
|
+
if (meta && typeof meta.module === "string") {
|
|
194
|
+
return [
|
|
195
|
+
{
|
|
196
|
+
module: meta.module.trim() || fallbackModule,
|
|
197
|
+
description: typeof meta.description === "string" ? meta.description.trim() : "",
|
|
198
|
+
source: typeof meta.source === "string" ? meta.source.trim() : ""
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
return [
|
|
203
|
+
{
|
|
204
|
+
module: fallbackModule,
|
|
205
|
+
description: "",
|
|
206
|
+
source: ""
|
|
207
|
+
}
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
async function copyAiDocSources(cwd, log) {
|
|
211
|
+
const metaFiles = import_fast_glob.default.globSync(["src/ai/docs/**/meta.json"], { cwd, absolute: true });
|
|
212
|
+
if (!metaFiles.length) return;
|
|
213
|
+
const rootMetaMap = /* @__PURE__ */ new Map();
|
|
214
|
+
for (const metaFile of metaFiles) {
|
|
215
|
+
let entries = [];
|
|
216
|
+
try {
|
|
217
|
+
const meta = await import_fs_extra.default.readJson(metaFile);
|
|
218
|
+
const fallbackModule = import_path.default.basename(import_path.default.dirname(metaFile));
|
|
219
|
+
entries = normalizeAiMetaEntries(meta, fallbackModule);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
log("failed to read ai docs meta.json", metaFile, error);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
for (const entry of entries) {
|
|
225
|
+
const source = entry.source?.trim();
|
|
226
|
+
if (!source) continue;
|
|
227
|
+
const absoluteSource = import_path.default.isAbsolute(source) ? source : import_path.default.resolve(process.cwd(), source);
|
|
228
|
+
const fallbackSource = import_path.default.isAbsolute(source) ? "" : import_path.default.resolve(cwd, source);
|
|
229
|
+
const resolvedSource = await import_fs_extra.default.pathExists(absoluteSource) ? absoluteSource : fallbackSource && await import_fs_extra.default.pathExists(fallbackSource) ? fallbackSource : "";
|
|
230
|
+
if (!resolvedSource) {
|
|
231
|
+
log("ai docs source not found", source, metaFile);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const targetRoot = import_path.default.join(cwd, target_dir, "ai", "docs", entry.module);
|
|
235
|
+
await import_fs_extra.default.remove(targetRoot);
|
|
236
|
+
await import_fs_extra.default.ensureDir(targetRoot);
|
|
237
|
+
await import_fs_extra.default.copy(resolvedSource, targetRoot, {
|
|
238
|
+
overwrite: true,
|
|
239
|
+
filter: (src) => import_path.default.basename(src) !== "_meta.json"
|
|
240
|
+
});
|
|
241
|
+
rootMetaMap.set(entry.module, {
|
|
242
|
+
module: entry.module,
|
|
243
|
+
description: entry.description ?? ""
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (rootMetaMap.size) {
|
|
248
|
+
const rootMetaPath = import_path.default.join(cwd, target_dir, "ai", "docs", "meta.json");
|
|
249
|
+
await import_fs_extra.default.ensureDir(import_path.default.dirname(rootMetaPath));
|
|
250
|
+
await import_fs_extra.default.writeJSON(rootMetaPath, Array.from(rootMetaMap.values()), { spaces: 2 });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
151
253
|
function deleteServerFiles(cwd, log) {
|
|
152
254
|
log("delete server files");
|
|
153
255
|
const files = import_fast_glob.default.globSync(["*"], {
|
|
@@ -162,7 +264,19 @@ function deleteServerFiles(cwd, log) {
|
|
|
162
264
|
deep: 1,
|
|
163
265
|
onlyDirectories: true
|
|
164
266
|
});
|
|
165
|
-
|
|
267
|
+
const extraClientDirs = import_fast_glob.default.globSync(["client-v2"], {
|
|
268
|
+
cwd: import_path.default.join(cwd, target_dir),
|
|
269
|
+
absolute: true,
|
|
270
|
+
deep: 1,
|
|
271
|
+
onlyDirectories: true
|
|
272
|
+
});
|
|
273
|
+
[...files, ...dirs.filter((item) => !extraClientDirs.includes(item)), ...extraClientDirs].forEach((item) => {
|
|
274
|
+
if (item.endsWith(`${import_path.default.sep}client-v2`)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (item.endsWith(`${import_path.default.sep}client`)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
166
280
|
import_fs_extra.default.removeSync(item);
|
|
167
281
|
});
|
|
168
282
|
}
|
|
@@ -258,7 +372,8 @@ async function buildServerDeps(cwd, serverFiles, log) {
|
|
|
258
372
|
async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
259
373
|
log("build plugin server source");
|
|
260
374
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
261
|
-
|
|
375
|
+
let serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
|
|
376
|
+
serverFiles = appendAiFiles(cwd, serverFiles);
|
|
262
377
|
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
|
|
263
378
|
const otherExts = Array.from(
|
|
264
379
|
new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
|
|
@@ -286,12 +401,14 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
286
401
|
}
|
|
287
402
|
})
|
|
288
403
|
);
|
|
404
|
+
await copyAiDocSources(cwd, log);
|
|
289
405
|
await buildServerDeps(cwd, serverFiles, log);
|
|
290
406
|
}
|
|
291
407
|
async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
292
408
|
log("build pro plugin server source");
|
|
293
409
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
294
|
-
|
|
410
|
+
let serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
|
|
411
|
+
serverFiles = appendAiFiles(cwd, serverFiles);
|
|
295
412
|
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
|
|
296
413
|
const otherExts = Array.from(
|
|
297
414
|
new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
|
|
@@ -301,10 +418,17 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
301
418
|
}
|
|
302
419
|
deleteServerFiles(cwd, log);
|
|
303
420
|
let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
304
|
-
import_fs_extra.default.writeFileSync(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
421
|
+
import_fs_extra.default.writeFileSync(
|
|
422
|
+
import_path.default.join(cwd, "tsconfig.json"),
|
|
423
|
+
JSON.stringify(
|
|
424
|
+
{
|
|
425
|
+
...tsconfig.data,
|
|
426
|
+
compilerOptions: { ...tsconfig.data.compilerOptions, paths: [] }
|
|
427
|
+
},
|
|
428
|
+
null,
|
|
429
|
+
2
|
|
430
|
+
)
|
|
431
|
+
);
|
|
308
432
|
tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
309
433
|
await (0, import_tsup.build)(
|
|
310
434
|
userConfig.modifyTsupConfig({
|
|
@@ -325,6 +449,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
325
449
|
}
|
|
326
450
|
})
|
|
327
451
|
);
|
|
452
|
+
await copyAiDocSources(cwd, log);
|
|
328
453
|
const entryFile = import_path.default.join(cwd, "src/server/index.ts");
|
|
329
454
|
if (!import_fs_extra.default.existsSync(entryFile)) {
|
|
330
455
|
log("server entry file not found", entryFile);
|
|
@@ -339,11 +464,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
339
464
|
};
|
|
340
465
|
if (!cwd.includes(import_constant.PLUGIN_COMMERCIAL)) {
|
|
341
466
|
externalOptions.external = [/^[./]/];
|
|
342
|
-
externalOptions.noExternal = [
|
|
343
|
-
entryFile,
|
|
344
|
-
/@nocobase\/plugin-commercial\/server/,
|
|
345
|
-
/dist\/server\/index\.js/
|
|
346
|
-
];
|
|
467
|
+
externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
|
|
347
468
|
externalOptions.onSuccess = async () => {
|
|
348
469
|
const serverFiles2 = [import_path.default.join(cwd, target_dir, "server", "index.js")];
|
|
349
470
|
serverFiles2.forEach((file) => {
|
|
@@ -380,34 +501,56 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
380
501
|
import_fs_extra.default.removeSync(tsconfig.path);
|
|
381
502
|
await buildServerDeps(cwd, serverFiles, log);
|
|
382
503
|
}
|
|
383
|
-
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
384
|
-
|
|
504
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
|
|
505
|
+
const laneConfig = pluginClientLaneConfig[lane];
|
|
506
|
+
const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
|
|
507
|
+
const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
|
|
508
|
+
if (!import_fs_extra.default.existsSync(rootEntryFile)) {
|
|
509
|
+
log("skip plugin %s build, root entry not found", lane);
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (!import_fs_extra.default.existsSync(entryDir)) {
|
|
513
|
+
log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
|
|
514
|
+
process.exit(-1);
|
|
515
|
+
}
|
|
516
|
+
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
|
|
517
|
+
if (!entry[0]) {
|
|
518
|
+
log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
|
|
519
|
+
process.exit(-1);
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
log("build plugin %s", lane);
|
|
385
523
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
524
|
+
const clientGlobalFiles = getClientGlobalFiles(lane);
|
|
386
525
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
387
526
|
if (isCommercial) {
|
|
388
|
-
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
527
|
+
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
528
|
+
cwd: import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL),
|
|
529
|
+
absolute: true
|
|
530
|
+
});
|
|
389
531
|
clientFiles.push(...commercialFiles);
|
|
390
532
|
}
|
|
391
533
|
const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
|
|
392
534
|
const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
|
|
393
535
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
394
536
|
(0, import_buildPluginUtils.checkRequire)(clientFiles, log);
|
|
395
|
-
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry:
|
|
396
|
-
const outDir = import_path.default.join(cwd, target_dir,
|
|
537
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
|
|
538
|
+
const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
|
|
397
539
|
const globals = excludePackages.reduce((prev, curr) => {
|
|
398
540
|
if (curr.startsWith("@nocobase")) {
|
|
399
|
-
|
|
541
|
+
laneConfig.externalSubpaths.forEach((subpath) => {
|
|
542
|
+
prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
|
|
543
|
+
});
|
|
400
544
|
}
|
|
401
545
|
prev[curr] = curr;
|
|
402
546
|
return prev;
|
|
403
547
|
}, {});
|
|
404
|
-
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
|
|
405
548
|
const outputFileName = "index.js";
|
|
406
549
|
const compiler = (0, import_core.rspack)({
|
|
407
550
|
mode: "production",
|
|
408
551
|
// mode: "development",
|
|
409
552
|
context: cwd,
|
|
410
|
-
entry:
|
|
553
|
+
entry: `./src/${laneConfig.entryDir}/` + entry[0],
|
|
411
554
|
target: ["web", "es5"],
|
|
412
555
|
output: {
|
|
413
556
|
path: outDir,
|
|
@@ -489,18 +632,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
489
632
|
// *.svg?react
|
|
490
633
|
use: ["@svgr/webpack"]
|
|
491
634
|
},
|
|
492
|
-
{
|
|
493
|
-
test: /\.(?:js|mjs|cjs|ts|tsx)$/,
|
|
494
|
-
exclude: /node_modules/,
|
|
495
|
-
use: {
|
|
496
|
-
loader: "babel-loader",
|
|
497
|
-
options: {
|
|
498
|
-
targets: "defaults",
|
|
499
|
-
// presets: [['@babel/preset-env']],
|
|
500
|
-
plugins: ["react-imported-component/babel"]
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
635
|
{
|
|
505
636
|
test: /\.jsx$/,
|
|
506
637
|
exclude: /[\\/]node_modules[\\/]/,
|
|
@@ -580,27 +711,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
580
711
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
581
712
|
"process.env.NODE_DEBUG": false
|
|
582
713
|
}),
|
|
583
|
-
|
|
584
|
-
apply(compiler2) {
|
|
585
|
-
compiler2.hooks.compilation.tap("CustomPublicPathPlugin", (compilation) => {
|
|
586
|
-
compilation.hooks.runtimeModule.tap("CustomPublicPathPlugin", (module2) => {
|
|
587
|
-
if (module2.name === "auto_public_path") {
|
|
588
|
-
module2.source = {
|
|
589
|
-
source: `
|
|
590
|
-
__webpack_require__.p = (function() {
|
|
591
|
-
var publicPath = window['__nocobase_public_path__'] || '/';
|
|
592
|
-
// \u786E\u4FDD\u8DEF\u5F84\u4EE5 / \u7ED3\u5C3E
|
|
593
|
-
if (!publicPath.endsWith('/')) {
|
|
594
|
-
publicPath += '/';
|
|
595
|
-
}
|
|
596
|
-
return publicPath + 'static/plugins/${packageJson.name}/dist/client/';
|
|
597
|
-
})();`
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
},
|
|
714
|
+
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
|
|
604
715
|
process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
|
|
605
716
|
// plugin options
|
|
606
717
|
// supports: {
|
|
@@ -637,10 +748,12 @@ __webpack_require__.p = (function() {
|
|
|
637
748
|
}
|
|
638
749
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
639
750
|
if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
|
|
640
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log, true);
|
|
751
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
|
|
752
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
|
|
641
753
|
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
642
754
|
} else {
|
|
643
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
755
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
|
|
756
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
|
|
644
757
|
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
645
758
|
}
|
|
646
759
|
writeExternalPackageVersion(cwd, log);
|
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,11 +91,13 @@ 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");
|
|
93
|
-
const
|
|
94
|
+
const CORE_CLIENT_V2 = import_path.default.join(PACKAGES_PATH, "core/client-v2");
|
|
95
|
+
const ESM_PACKAGES = ["@nocobase/client-v2", "@nocobase/test"];
|
|
94
96
|
const CJS_EXCLUDE_PACKAGES = [
|
|
95
97
|
import_path.default.join(PACKAGES_PATH, "core/build"),
|
|
96
98
|
import_path.default.join(PACKAGES_PATH, "core/cli"),
|
|
97
|
-
CORE_CLIENT
|
|
99
|
+
CORE_CLIENT,
|
|
100
|
+
CORE_CLIENT_V2
|
|
98
101
|
];
|
|
99
102
|
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
103
|
const tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules"];
|
|
@@ -104,6 +107,7 @@ const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path
|
|
|
104
107
|
CJS_EXCLUDE_PACKAGES,
|
|
105
108
|
CORE_APP,
|
|
106
109
|
CORE_CLIENT,
|
|
110
|
+
CORE_CLIENT_V2,
|
|
107
111
|
ESM_PACKAGES,
|
|
108
112
|
EsbuildSupportExts,
|
|
109
113
|
NODE_MODULES,
|
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,88 @@
|
|
|
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 = window['__nocobase_public_path__'] || '';
|
|
26
|
+
if (!publicPath && window.location && window.location.pathname) {
|
|
27
|
+
var marker = '/v2/';
|
|
28
|
+
var pathname = window.location.pathname || '/';
|
|
29
|
+
var index = pathname.indexOf(marker);
|
|
30
|
+
publicPath = index >= 0 ? pathname.slice(0, index + 1) : '/';
|
|
31
|
+
}
|
|
32
|
+
if (publicPath) {
|
|
33
|
+
publicPath = publicPath.replace(/\\/v2\\/?$/, '/');
|
|
34
|
+
}
|
|
35
|
+
if (!publicPath) {
|
|
36
|
+
publicPath = '/';
|
|
37
|
+
}
|
|
38
|
+
if (publicPath.charAt(publicPath.length - 1) !== '/') {
|
|
39
|
+
publicPath += '/';
|
|
40
|
+
}
|
|
41
|
+
__webpack_public_path__ = publicPath + 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
42
|
+
`;
|
|
43
|
+
return `data:text/javascript,${encodeURIComponent(code)}`;
|
|
44
|
+
}
|
|
45
|
+
function prependPluginClientPublicPathEntry(entry, packageName, clientDistDir) {
|
|
46
|
+
const dataUri = createPluginClientPublicPathDataUri(packageName, clientDistDir);
|
|
47
|
+
if (typeof entry === "string") {
|
|
48
|
+
return [dataUri, entry];
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(entry)) {
|
|
51
|
+
return [dataUri, ...entry];
|
|
52
|
+
}
|
|
53
|
+
if (!entry || typeof entry !== "object") {
|
|
54
|
+
return entry;
|
|
55
|
+
}
|
|
56
|
+
const entryConfig = entry;
|
|
57
|
+
if (entryConfig.import) {
|
|
58
|
+
return {
|
|
59
|
+
...entryConfig,
|
|
60
|
+
import: Array.isArray(entryConfig.import) ? [dataUri, ...entryConfig.import] : [dataUri, entryConfig.import]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return Object.fromEntries(
|
|
64
|
+
Object.entries(entryConfig).map(([name, value]) => [
|
|
65
|
+
name,
|
|
66
|
+
prependPluginClientPublicPathEntry(value, packageName, clientDistDir)
|
|
67
|
+
])
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
class AutoInjectPublicPathPlugin {
|
|
71
|
+
constructor(pluginName, clientDistDir = "client") {
|
|
72
|
+
this.pluginName = pluginName;
|
|
73
|
+
this.clientDistDir = clientDistDir;
|
|
74
|
+
}
|
|
75
|
+
apply(compiler) {
|
|
76
|
+
compiler.hooks.environment.tap("AutoInjectPublicPathPlugin", () => {
|
|
77
|
+
compiler.options.entry = prependPluginClientPublicPathEntry(
|
|
78
|
+
compiler.options.entry,
|
|
79
|
+
this.pluginName,
|
|
80
|
+
this.clientDistDir
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
AutoInjectPublicPathPlugin
|
|
88
|
+
});
|
package/lib/utils/utils.js
CHANGED
|
@@ -86,7 +86,7 @@ function defineConfig(config) {
|
|
|
86
86
|
function getUserConfig(cwd) {
|
|
87
87
|
const config = defineConfig({
|
|
88
88
|
modifyTsupConfig: (config2) => config2,
|
|
89
|
-
|
|
89
|
+
modifyRsbuildConfig: (config2) => config2
|
|
90
90
|
});
|
|
91
91
|
const buildConfigs = import_fast_glob.default.sync(["build.config.js", "build.config.ts"], { cwd });
|
|
92
92
|
if (buildConfigs.length > 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/build",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.11",
|
|
4
4
|
"description": "Library build tool based on rollup.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -15,11 +15,14 @@
|
|
|
15
15
|
"@babel/preset-env": "^7.26.0",
|
|
16
16
|
"@hapi/topo": "^6.0.0",
|
|
17
17
|
"@lerna/project": "4.0.0",
|
|
18
|
+
"@rsbuild/core": "1.7.3",
|
|
18
19
|
"@rsbuild/plugin-babel": "^1.0.3",
|
|
20
|
+
"@rsbuild/plugin-less": "^1.6.2",
|
|
21
|
+
"@rsbuild/plugin-react": "1.4.6",
|
|
22
|
+
"@rsbuild/plugin-svgr": "^1.3.1",
|
|
19
23
|
"@rsdoctor/rspack-plugin": "^0.4.8",
|
|
20
|
-
"@rspack/core": "1.
|
|
24
|
+
"@rspack/core": "1.7.8",
|
|
21
25
|
"@svgr/webpack": "^8.1.0",
|
|
22
|
-
"@types/gulp": "^4.0.13",
|
|
23
26
|
"@types/lerna__package": "5.1.0",
|
|
24
27
|
"@types/lerna__project": "5.1.0",
|
|
25
28
|
"@types/tar": "^6.1.5",
|
|
@@ -31,8 +34,6 @@
|
|
|
31
34
|
"css-loader": "^6.8.1",
|
|
32
35
|
"esbuild-register": "^3.4.2",
|
|
33
36
|
"fast-glob": "^3.3.1",
|
|
34
|
-
"gulp": "4.0.2",
|
|
35
|
-
"gulp-typescript": "6.0.0-alpha.1",
|
|
36
37
|
"javascript-obfuscator": "^4.1.1",
|
|
37
38
|
"less": "^4.2.0",
|
|
38
39
|
"less-loader": "^12.2.0",
|
|
@@ -45,14 +46,12 @@
|
|
|
45
46
|
"tsup": "8.2.4",
|
|
46
47
|
"typescript": "5.1.3",
|
|
47
48
|
"update-notifier": "3.0.0",
|
|
48
|
-
"vite-plugin-css-injected-by-js": "^3.2.1",
|
|
49
|
-
"vite-plugin-lib-inject-css": "1.2.0",
|
|
50
49
|
"yargs-parser": "13.1.2"
|
|
51
50
|
},
|
|
52
|
-
"license": "
|
|
51
|
+
"license": "Apache-2.0",
|
|
53
52
|
"scripts": {
|
|
54
53
|
"build": "tsup",
|
|
55
54
|
"build:watch": "tsup --watch"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "bb96d633a6371afb586072ff516bd0613c757db0"
|
|
58
57
|
}
|