@nocobase/build 2.1.0-alpha.4 → 2.1.0-alpha.45

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.
@@ -31,13 +31,14 @@ __export(buildClient_exports, {
31
31
  buildLocale: () => buildLocale
32
32
  });
33
33
  module.exports = __toCommonJS(buildClient_exports);
34
- var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
34
+ var import_core = require("@rsbuild/core");
35
+ var import_plugin_less = require("@rsbuild/plugin-less");
36
+ var import_plugin_react = require("@rsbuild/plugin-react");
37
+ var import_plugin_svgr = require("@rsbuild/plugin-svgr");
35
38
  var import_fast_glob = __toESM(require("fast-glob"));
36
39
  var import_fs_extra = __toESM(require("fs-extra"));
37
40
  var import_path = __toESM(require("path"));
38
41
  var import_tsup = require("tsup");
39
- var import_vite = require("vite");
40
- var import_vite_plugin_lib_inject_css = require("vite-plugin-lib-inject-css");
41
42
  var import_constant = require("./constant");
42
43
  var import_utils = require("./utils");
43
44
  async function buildClient(cwd, userConfig, sourcemap = false, log) {
@@ -45,7 +46,7 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
45
46
  const cwdWin = cwd.replaceAll(/\\/g, "/");
46
47
  const cwdUnix = cwd.replaceAll(/\//g, "\\");
47
48
  const external = function(id) {
48
- if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
49
+ if (!id || import_path.default.isAbsolute(id) || id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
49
50
  return false;
50
51
  }
51
52
  return true;
@@ -54,35 +55,12 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
54
55
  await buildClientLib(cwd, userConfig, sourcemap, external, log);
55
56
  await buildLocale(cwd, userConfig, log);
56
57
  }
57
- function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
58
+ async function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
58
59
  log("build client esm");
59
60
  const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
60
61
  const outDir = import_path.default.resolve(cwd, "es");
61
- return (0, import_vite.build)(
62
- userConfig.modifyViteConfig({
63
- mode: process.env.NODE_ENV || "production",
64
- define: (0, import_utils.getEnvDefine)(),
65
- build: {
66
- minify: process.env.NODE_ENV === "production",
67
- outDir,
68
- cssCodeSplit: true,
69
- emptyOutDir: true,
70
- sourcemap,
71
- lib: {
72
- entry,
73
- formats: ["es"],
74
- fileName: "index"
75
- },
76
- target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
77
- rollupOptions: {
78
- cache: true,
79
- treeshake: true,
80
- external
81
- }
82
- },
83
- plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_lib_inject_css.libInjectCss)()]
84
- })
85
- );
62
+ await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "esm");
63
+ await injectEntryStyleReference(import_path.default.join(outDir, "index.mjs"), 'import "./index.css";');
86
64
  }
87
65
  async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
88
66
  log("build client lib");
@@ -91,32 +69,114 @@ async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
91
69
  const entry = import_path.default.join(esDir, "index.ts");
92
70
  import_fs_extra.default.removeSync(entry);
93
71
  import_fs_extra.default.linkSync(import_path.default.join(cwd, "es/index.mjs"), entry);
94
- await (0, import_vite.build)(
95
- userConfig.modifyViteConfig({
96
- mode: process.env.NODE_ENV || "production",
97
- esbuild: {
98
- format: "cjs"
72
+ try {
73
+ await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "cjs");
74
+ } finally {
75
+ import_fs_extra.default.removeSync(entry);
76
+ }
77
+ await injectEntryStyleReference(import_path.default.join(outDir, "index.js"), 'require("./index.css");');
78
+ }
79
+ async function buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, format) {
80
+ const config = createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format);
81
+ const rsbuild = await (0, import_core.createRsbuild)({
82
+ cwd,
83
+ config: userConfig.modifyRsbuildConfig?.(config) ?? config
84
+ });
85
+ const result = await rsbuild.build();
86
+ await result.close();
87
+ }
88
+ function createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format) {
89
+ return {
90
+ plugins: [(0, import_plugin_react.pluginReact)(), (0, import_plugin_less.pluginLess)(), (0, import_plugin_svgr.pluginSvgr)()],
91
+ source: {
92
+ entry: {
93
+ index: {
94
+ import: entry,
95
+ html: false
96
+ }
97
+ },
98
+ tsconfigPath: import_path.default.join(cwd, "tsconfig.json"),
99
+ define: (0, import_utils.getEnvDefine)(),
100
+ decorators: {
101
+ version: "legacy"
102
+ }
103
+ },
104
+ output: {
105
+ target: "web",
106
+ distPath: {
107
+ root: outDir,
108
+ js: ".",
109
+ jsAsync: ".",
110
+ css: ".",
111
+ cssAsync: ".",
112
+ svg: ".",
113
+ font: ".",
114
+ image: ".",
115
+ media: ".",
116
+ assets: "."
99
117
  },
100
- build: {
101
- outDir,
102
- minify: process.env.NODE_ENV === "production",
103
- sourcemap,
104
- lib: {
105
- entry: import_path.default.join(cwd, "es/index.ts"),
106
- formats: ["cjs"],
107
- fileName: "index"
108
- },
109
- rollupOptions: {
110
- external
118
+ filename: {
119
+ js: format === "esm" ? "[name].mjs" : "[name].js",
120
+ css: "[name].css",
121
+ svg: "[name][ext][query]",
122
+ font: "[name][ext][query]",
123
+ image: "[name][ext][query]",
124
+ media: "[name][ext][query]",
125
+ assets: "[name][ext][query]"
126
+ },
127
+ cleanDistPath: true,
128
+ sourceMap: sourcemap,
129
+ minify: process.env.NODE_ENV === "production",
130
+ emitCss: true,
131
+ externals: [
132
+ function({ request }, callback) {
133
+ if (request && external(request)) {
134
+ return callback(null, true);
135
+ }
136
+ callback();
111
137
  }
138
+ ]
139
+ },
140
+ performance: {
141
+ chunkSplit: {
142
+ strategy: "all-in-one"
112
143
  }
113
- })
114
- );
115
- import_fs_extra.default.removeSync(entry);
116
- const css = import_fast_glob.default.sync("*.css", { cwd: esDir, absolute: true });
117
- css.forEach((file) => {
118
- import_fs_extra.default.copySync(file, import_path.default.join(outDir, import_path.default.basename(file)));
119
- });
144
+ },
145
+ tools: {
146
+ rspack(config) {
147
+ config.output = config.output || {};
148
+ config.output.asyncChunks = false;
149
+ if (format === "esm") {
150
+ config.output.library = { type: "module" };
151
+ config.output.module = true;
152
+ config.output.chunkFormat = "module";
153
+ config.output.chunkLoading = "import";
154
+ config.output.workerChunkLoading = "import";
155
+ config.experiments = {
156
+ ...config.experiments,
157
+ outputModule: true
158
+ };
159
+ config.externalsType = "module-import";
160
+ } else {
161
+ config.output.library = { type: "commonjs-static" };
162
+ }
163
+ config.performance = false;
164
+ config.stats = "errors-warnings";
165
+ }
166
+ }
167
+ };
168
+ }
169
+ async function injectEntryStyleReference(entryFile, styleReference) {
170
+ const cssFile = import_path.default.join(import_path.default.dirname(entryFile), "index.css");
171
+ if (!import_fs_extra.default.existsSync(entryFile) || !import_fs_extra.default.existsSync(cssFile)) {
172
+ return;
173
+ }
174
+ const content = await import_fs_extra.default.readFile(entryFile, "utf8");
175
+ if (content.startsWith(styleReference)) {
176
+ return;
177
+ }
178
+ await import_fs_extra.default.writeFile(entryFile, `${styleReference}
179
+ ${content}`);
120
180
  }
121
181
  function buildLocale(cwd, userConfig, log) {
122
182
  log("build client locale");
@@ -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
- return options;
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 program = import_typescript.default.createProgram(files, compilerOptions);
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) {
@@ -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,7 +160,18 @@ const external = [
141
160
  "ahooks",
142
161
  "lodash",
143
162
  "china-division",
144
- "file-saver"
163
+ // langChain
164
+ "langchain",
165
+ "@langchain/core",
166
+ "@langchain/classic",
167
+ "@langchain/langgraph",
168
+ "@langchain/langgraph-checkpoint",
169
+ "@langchain/openai",
170
+ "@langchain/anthropic",
171
+ "@langchain/google-genai",
172
+ "@langchain/deepseek",
173
+ "@langchain/ollama",
174
+ "@langchain/mcp-adapters"
145
175
  ];
146
176
  const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
147
177
  const target_dir = "dist";
@@ -218,24 +248,6 @@ async function copyAiDocSources(cwd, log) {
218
248
  await import_fs_extra.default.writeJSON(rootMetaPath, Array.from(rootMetaMap.values()), { spaces: 2 });
219
249
  }
220
250
  }
221
- function deleteServerFiles(cwd, log) {
222
- log("delete server files");
223
- const files = import_fast_glob.default.globSync(["*"], {
224
- cwd: import_path.default.join(cwd, target_dir),
225
- absolute: true,
226
- deep: 1,
227
- onlyFiles: true
228
- });
229
- const dirs = import_fast_glob.default.globSync(["*", "!client", "!node_modules"], {
230
- cwd: import_path.default.join(cwd, target_dir),
231
- absolute: true,
232
- deep: 1,
233
- onlyDirectories: true
234
- });
235
- [...files, ...dirs].forEach((item) => {
236
- import_fs_extra.default.removeSync(item);
237
- });
238
- }
239
251
  function writeExternalPackageVersion(cwd, log) {
240
252
  log("write external version");
241
253
  const sourceFiles = import_fast_glob.default.globSync(sourceGlobalFiles, { cwd, absolute: true }).map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
@@ -257,7 +269,7 @@ async function buildServerDeps(cwd, serverFiles, log) {
257
269
  const sourcePackages = (0, import_buildPluginUtils.getSourcePackages)(serverFileSource);
258
270
  const includePackages = (0, import_buildPluginUtils.getIncludePackages)(sourcePackages, external, pluginPrefix);
259
271
  const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
260
- let tips = [];
272
+ const tips = [];
261
273
  if (includePackages.length) {
262
274
  tips.push(
263
275
  `These packages ${import_chalk.default.yellow(includePackages.join(", "))} will be ${import_chalk.default.italic(
@@ -306,8 +318,10 @@ async function buildServerDeps(cwd, serverFiles, log) {
306
318
  });
307
319
  await (0, import_ncc.default)(dep, nccConfig).then(
308
320
  ({ code, assets }) => {
321
+ import_fs_extra.default.ensureDirSync(import_path.default.dirname(mainFile));
309
322
  import_fs_extra.default.writeFileSync(mainFile, code, "utf-8");
310
323
  Object.entries(assets).forEach(([name, item]) => {
324
+ import_fs_extra.default.ensureDirSync(import_path.default.dirname(import_path.default.join(outputDir, name)));
311
325
  import_fs_extra.default.writeFileSync(import_path.default.join(outputDir, name), item.source, {
312
326
  encoding: "utf-8",
313
327
  mode: item.permissions
@@ -337,7 +351,7 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
337
351
  if (otherExts.length) {
338
352
  log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
339
353
  }
340
- deleteServerFiles(cwd, log);
354
+ (0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
341
355
  await (0, import_tsup.build)(
342
356
  userConfig.modifyTsupConfig({
343
357
  entry: serverFiles,
@@ -353,7 +367,8 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
353
367
  skipNodeModulesBundle: true,
354
368
  loader: {
355
369
  ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
356
- ".json": "copy"
370
+ ".json": "copy",
371
+ ".txt": "copy"
357
372
  }
358
373
  })
359
374
  );
@@ -372,7 +387,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
372
387
  if (otherExts.length) {
373
388
  log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
374
389
  }
375
- deleteServerFiles(cwd, log);
390
+ (0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
376
391
  let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
377
392
  import_fs_extra.default.writeFileSync(
378
393
  import_path.default.join(cwd, "tsconfig.json"),
@@ -401,7 +416,8 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
401
416
  skipNodeModulesBundle: true,
402
417
  loader: {
403
418
  ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
404
- ".json": "copy"
419
+ ".json": "copy",
420
+ ".txt": "copy"
405
421
  }
406
422
  })
407
423
  );
@@ -449,7 +465,8 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
449
465
  tsconfig: tsconfig.path,
450
466
  loader: {
451
467
  ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
452
- ".json": "copy"
468
+ ".json": "copy",
469
+ ".txt": "copy"
453
470
  },
454
471
  ...externalOptions
455
472
  })
@@ -457,9 +474,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
457
474
  import_fs_extra.default.removeSync(tsconfig.path);
458
475
  await buildServerDeps(cwd, serverFiles, log);
459
476
  }
460
- async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
461
- log("build plugin client");
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);
462
496
  const packageJson = (0, import_utils.getPackageJson)(cwd);
497
+ const clientGlobalFiles = getClientGlobalFiles(lane);
463
498
  const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
464
499
  if (isCommercial) {
465
500
  const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
@@ -468,36 +503,41 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
468
503
  });
469
504
  clientFiles.push(...commercialFiles);
470
505
  }
471
- const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
472
- const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
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);
473
511
  const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
512
+ const browserExternalPackages = excludePackages.filter((packageName) => packageName !== "file-saver");
474
513
  (0, import_buildPluginUtils.checkRequire)(clientFiles, log);
475
- (0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "client", files: clientFiles, log });
476
- const outDir = import_path.default.join(cwd, target_dir, "client");
477
- const globals = excludePackages.reduce((prev, curr) => {
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) => {
478
517
  if (curr.startsWith("@nocobase")) {
479
- prev[`${curr}/client`] = `${curr}/client`;
518
+ laneConfig.externalSubpaths.forEach((subpath) => {
519
+ prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
520
+ });
480
521
  }
481
522
  prev[curr] = curr;
482
523
  return prev;
483
524
  }, {});
484
- const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
485
525
  const outputFileName = "index.js";
486
526
  const compiler = (0, import_core.rspack)({
487
527
  mode: "production",
488
528
  // mode: "development",
489
529
  context: cwd,
490
- entry: "./src/client/" + entry[0],
530
+ entry: `./src/${laneConfig.entryDir}/` + entry[0],
491
531
  target: ["web", "es5"],
492
532
  output: {
493
533
  path: outDir,
494
534
  filename: outputFileName,
495
- chunkFilename: "[chunkhash].js",
535
+ chunkFilename: "[name].[contenthash].js",
496
536
  publicPath: `auto`,
497
537
  // will be generated by the custom plugin
498
538
  clean: true,
499
539
  library: {
500
- name: packageJson.name,
540
+ name: lane === "client-v2" ? `${packageJson.name}/client-v2` : packageJson.name,
501
541
  type: "umd",
502
542
  umdNamedDefine: true
503
543
  }
@@ -569,18 +609,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
569
609
  // *.svg?react
570
610
  use: ["@svgr/webpack"]
571
611
  },
572
- {
573
- test: /\.(?:js|mjs|cjs|ts|tsx)$/,
574
- exclude: /node_modules/,
575
- use: {
576
- loader: "babel-loader",
577
- options: {
578
- targets: "defaults",
579
- // presets: [['@babel/preset-env']],
580
- plugins: ["react-imported-component/babel"]
581
- }
582
- }
583
- },
584
612
  {
585
613
  test: /\.jsx$/,
586
614
  exclude: /[\\/]node_modules[\\/]/,
@@ -660,27 +688,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
660
688
  "process.env.NODE_ENV": JSON.stringify("production"),
661
689
  "process.env.NODE_DEBUG": false
662
690
  }),
663
- {
664
- apply(compiler2) {
665
- compiler2.hooks.compilation.tap("CustomPublicPathPlugin", (compilation) => {
666
- compilation.hooks.runtimeModule.tap("CustomPublicPathPlugin", (module2) => {
667
- if (module2.name === "auto_public_path") {
668
- module2.source = {
669
- source: `
670
- __webpack_require__.p = (function() {
671
- var publicPath = window['__webpack_public_path__'] || '/';
672
- // \u786E\u4FDD\u8DEF\u5F84\u4EE5 / \u7ED3\u5C3E
673
- if (!publicPath.endsWith('/')) {
674
- publicPath += '/';
675
- }
676
- return publicPath + 'static/plugins/${packageJson.name}/dist/client/';
677
- })();`
678
- };
679
- }
680
- });
681
- });
682
- }
683
- },
691
+ new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
684
692
  process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
685
693
  // plugin options
686
694
  // supports: {
@@ -717,10 +725,12 @@ __webpack_require__.p = (function() {
717
725
  }
718
726
  async function buildPlugin(cwd, userConfig, sourcemap, log) {
719
727
  if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
720
- 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);
721
730
  await buildProPluginServer(cwd, userConfig, sourcemap, log);
722
731
  } else {
723
- await buildPluginClient(cwd, userConfig, sourcemap, log);
732
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
733
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
724
734
  await buildPluginServer(cwd, userConfig, sourcemap, log);
725
735
  }
726
736
  writeExternalPackageVersion(cwd, log);
@@ -732,6 +742,5 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
732
742
  buildPluginServer,
733
743
  buildProPluginServer,
734
744
  buildServerDeps,
735
- deleteServerFiles,
736
745
  writeExternalPackageVersion
737
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
- const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path.default.join(ROOT_PATH, "storage", "tar");
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
+ });