@nocobase/build 2.1.0-alpha.2 → 2.1.0-alpha.21

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) {
@@ -51,10 +51,29 @@ 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"]
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,19 @@ const external = [
141
160
  "ahooks",
142
161
  "lodash",
143
162
  "china-division",
144
- "file-saver"
163
+ "file-saver",
164
+ // langChain
165
+ "langchain",
166
+ "@langchain/core",
167
+ "@langchain/classic",
168
+ "@langchain/langgraph",
169
+ "@langchain/langgraph-checkpoint",
170
+ "@langchain/openai",
171
+ "@langchain/anthropic",
172
+ "@langchain/google-genai",
173
+ "@langchain/deepseek",
174
+ "@langchain/ollama",
175
+ "@langchain/mcp-adapters"
145
176
  ];
146
177
  const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
147
178
  const target_dir = "dist";
@@ -232,7 +263,19 @@ function deleteServerFiles(cwd, log) {
232
263
  deep: 1,
233
264
  onlyDirectories: true
234
265
  });
235
- [...files, ...dirs].forEach((item) => {
266
+ const extraClientDirs = import_fast_glob.default.globSync(["client-v2"], {
267
+ cwd: import_path.default.join(cwd, target_dir),
268
+ absolute: true,
269
+ deep: 1,
270
+ onlyDirectories: true
271
+ });
272
+ [...files, ...dirs.filter((item) => !extraClientDirs.includes(item)), ...extraClientDirs].forEach((item) => {
273
+ if (item.endsWith(`${import_path.default.sep}client-v2`)) {
274
+ return;
275
+ }
276
+ if (item.endsWith(`${import_path.default.sep}client`)) {
277
+ return;
278
+ }
236
279
  import_fs_extra.default.removeSync(item);
237
280
  });
238
281
  }
@@ -457,9 +500,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
457
500
  import_fs_extra.default.removeSync(tsconfig.path);
458
501
  await buildServerDeps(cwd, serverFiles, log);
459
502
  }
460
- async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
461
- log("build plugin client");
503
+ async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
504
+ const laneConfig = pluginClientLaneConfig[lane];
505
+ const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
506
+ const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
507
+ if (!import_fs_extra.default.existsSync(rootEntryFile)) {
508
+ log("skip plugin %s build, root entry not found", lane);
509
+ return false;
510
+ }
511
+ if (!import_fs_extra.default.existsSync(entryDir)) {
512
+ log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
513
+ process.exit(-1);
514
+ }
515
+ const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
516
+ if (!entry[0]) {
517
+ log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
518
+ process.exit(-1);
519
+ return false;
520
+ }
521
+ log("build plugin %s", lane);
462
522
  const packageJson = (0, import_utils.getPackageJson)(cwd);
523
+ const clientGlobalFiles = getClientGlobalFiles(lane);
463
524
  const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
464
525
  if (isCommercial) {
465
526
  const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
@@ -472,27 +533,28 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
472
533
  const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
473
534
  const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
474
535
  (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");
536
+ (0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
537
+ const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
477
538
  const globals = excludePackages.reduce((prev, curr) => {
478
539
  if (curr.startsWith("@nocobase")) {
479
- prev[`${curr}/client`] = `${curr}/client`;
540
+ laneConfig.externalSubpaths.forEach((subpath) => {
541
+ prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
542
+ });
480
543
  }
481
544
  prev[curr] = curr;
482
545
  return prev;
483
546
  }, {});
484
- const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
485
547
  const outputFileName = "index.js";
486
548
  const compiler = (0, import_core.rspack)({
487
549
  mode: "production",
488
550
  // mode: "development",
489
551
  context: cwd,
490
- entry: "./src/client/" + entry[0],
552
+ entry: `./src/${laneConfig.entryDir}/` + entry[0],
491
553
  target: ["web", "es5"],
492
554
  output: {
493
555
  path: outDir,
494
556
  filename: outputFileName,
495
- chunkFilename: "[chunkhash].js",
557
+ chunkFilename: "[name].[contenthash].js",
496
558
  publicPath: `auto`,
497
559
  // will be generated by the custom plugin
498
560
  clean: true,
@@ -569,18 +631,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
569
631
  // *.svg?react
570
632
  use: ["@svgr/webpack"]
571
633
  },
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
634
  {
585
635
  test: /\.jsx$/,
586
636
  exclude: /[\\/]node_modules[\\/]/,
@@ -660,27 +710,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
660
710
  "process.env.NODE_ENV": JSON.stringify("production"),
661
711
  "process.env.NODE_DEBUG": false
662
712
  }),
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
- },
713
+ new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
684
714
  process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
685
715
  // plugin options
686
716
  // supports: {
@@ -717,10 +747,12 @@ __webpack_require__.p = (function() {
717
747
  }
718
748
  async function buildPlugin(cwd, userConfig, sourcemap, log) {
719
749
  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);
750
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
751
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
721
752
  await buildProPluginServer(cwd, userConfig, sourcemap, log);
722
753
  } else {
723
- await buildPluginClient(cwd, userConfig, sourcemap, log);
754
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
755
+ await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
724
756
  await buildPluginServer(cwd, userConfig, sourcemap, log);
725
757
  }
726
758
  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,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");
93
- const ESM_PACKAGES = ["@nocobase/test"];
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"),
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,
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
- modifyViteConfig?: (config: ViteConfig) => ViteConfig;
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,109 @@
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
+ publicPath = window['__nocobase_public_path__'] || '';
45
+ if (!publicPath && window.location && window.location.pathname) {
46
+ var marker = '/v2/';
47
+ var pathname = window.location.pathname || '/';
48
+ var index = pathname.indexOf(marker);
49
+ publicPath = index >= 0 ? pathname.slice(0, index + 1) : '/';
50
+ }
51
+ if (publicPath) {
52
+ publicPath = publicPath.replace(/\\/v2\\/?$/, '/');
53
+ }
54
+ if (!publicPath) {
55
+ publicPath = '/';
56
+ }
57
+ if (publicPath.charAt(publicPath.length - 1) !== '/') {
58
+ publicPath += '/';
59
+ }
60
+ publicPath += 'static/plugins/${packageName}/dist/${clientDistDir}/';
61
+ }
62
+ __webpack_public_path__ = publicPath;
63
+ `;
64
+ return `data:text/javascript,${encodeURIComponent(code)}`;
65
+ }
66
+ function prependPluginClientPublicPathEntry(entry, packageName, clientDistDir) {
67
+ const dataUri = createPluginClientPublicPathDataUri(packageName, clientDistDir);
68
+ if (typeof entry === "string") {
69
+ return [dataUri, entry];
70
+ }
71
+ if (Array.isArray(entry)) {
72
+ return [dataUri, ...entry];
73
+ }
74
+ if (!entry || typeof entry !== "object") {
75
+ return entry;
76
+ }
77
+ const entryConfig = entry;
78
+ if (entryConfig.import) {
79
+ return {
80
+ ...entryConfig,
81
+ import: Array.isArray(entryConfig.import) ? [dataUri, ...entryConfig.import] : [dataUri, entryConfig.import]
82
+ };
83
+ }
84
+ return Object.fromEntries(
85
+ Object.entries(entryConfig).map(([name, value]) => [
86
+ name,
87
+ prependPluginClientPublicPathEntry(value, packageName, clientDistDir)
88
+ ])
89
+ );
90
+ }
91
+ class AutoInjectPublicPathPlugin {
92
+ constructor(pluginName, clientDistDir = "client") {
93
+ this.pluginName = pluginName;
94
+ this.clientDistDir = clientDistDir;
95
+ }
96
+ apply(compiler) {
97
+ compiler.hooks.environment.tap("AutoInjectPublicPathPlugin", () => {
98
+ compiler.options.entry = prependPluginClientPublicPathEntry(
99
+ compiler.options.entry,
100
+ this.pluginName,
101
+ this.clientDistDir
102
+ );
103
+ });
104
+ }
105
+ }
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ AutoInjectPublicPathPlugin
109
+ });
@@ -54,7 +54,7 @@ function isNotBuiltinModule(packageName) {
54
54
  return !import_module.builtinModules.includes(packageName);
55
55
  }
56
56
  const isValidPackageName = (str) => {
57
- const pattern = /^(?:@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+$/;
57
+ const pattern = /^(?:@[a-zA-Z0-9._-]+\/)?[a-zA-Z0-9._-]+$/;
58
58
  return pattern.test(str);
59
59
  };
60
60
  function getPackageNameFromString(str) {
@@ -76,7 +76,7 @@ function getDepsConfig(cwd, outDir, depsName, external) {
76
76
  acc[depEntryPath] = {
77
77
  nccConfig: {
78
78
  minify: true,
79
- target: "es5",
79
+ target: "es2020",
80
80
  quiet: true,
81
81
  externals: {}
82
82
  },