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

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.
@@ -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
+ });
@@ -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-9_-]+\/)?[a-zA-Z0-9_-]+$/;
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
@@ -33,6 +33,7 @@ __export(getDepsConfig_exports, {
33
33
  winPath: () => winPath
34
34
  });
35
35
  module.exports = __toCommonJS(getDepsConfig_exports);
36
+ var import_fs = __toESM(require("fs"));
36
37
  var import_path = __toESM(require("path"));
37
38
  function winPath(path2) {
38
39
  const isExtendedLengthPath = /^\\\\\?\\/.test(path2);
@@ -41,6 +42,9 @@ function winPath(path2) {
41
42
  }
42
43
  return path2.replace(/\\/g, "/");
43
44
  }
45
+ function realpathSync(filePath) {
46
+ return import_fs.default.realpathSync.native?.(filePath) ?? import_fs.default.realpathSync(filePath);
47
+ }
44
48
  function getRltExternalsFromDeps(depExternals, current) {
45
49
  return Object.entries(depExternals).reduce(
46
50
  (r, [dep, target]) => {
@@ -56,27 +60,27 @@ function getRltExternalsFromDeps(depExternals, current) {
56
60
  }
57
61
  function getDepPkgPath(dep, cwd) {
58
62
  try {
59
- return require.resolve(`${dep}/package.json`, { paths: [cwd] });
63
+ return realpathSync(require.resolve(`${dep}/package.json`, { paths: [cwd] }));
60
64
  } catch {
61
65
  const mainFile = require.resolve(`${dep}`, { paths: cwd ? [cwd] : void 0 });
62
66
  const packageDir = mainFile.slice(0, mainFile.indexOf(dep.replace("/", import_path.default.sep)) + dep.length);
63
- return import_path.default.join(packageDir, "package.json");
67
+ return realpathSync(import_path.default.join(packageDir, "package.json"));
64
68
  }
65
69
  }
66
70
  function getDepsConfig(cwd, outDir, depsName, external) {
67
71
  const pkgExternals = external.reduce((r, dep) => ({ ...r, [dep]: dep }), {});
68
72
  const depExternals = {};
69
73
  const deps = depsName.reduce((acc, packageName) => {
70
- const depEntryPath = require.resolve(packageName, { paths: [cwd] });
74
+ const depEntryPath = realpathSync(require.resolve(packageName, { paths: [cwd] }));
71
75
  const depPkgPath = getDepPkgPath(packageName, cwd);
72
76
  const depPkg = require(depPkgPath);
73
77
  const depDir = import_path.default.dirname(depPkgPath);
74
78
  const outputDir = import_path.default.join(outDir, packageName);
75
- const mainFile = import_path.default.join(outputDir, depEntryPath.replace(depDir, ""));
79
+ const mainFile = import_path.default.join(outputDir, import_path.default.relative(depDir, depEntryPath));
76
80
  acc[depEntryPath] = {
77
81
  nccConfig: {
78
82
  minify: true,
79
- target: "es5",
83
+ target: "es2020",
80
84
  quiet: true,
81
85
  externals: {}
82
86
  },
@@ -28,6 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var getPackages_exports = {};
29
29
  __export(getPackages_exports, {
30
30
  getPackages: () => getPackages,
31
+ groupPackagesByTopoLevel: () => groupPackagesByTopoLevel,
31
32
  sortPackages: () => sortPackages
32
33
  });
33
34
  module.exports = __toCommonJS(getPackages_exports);
@@ -76,8 +77,55 @@ function sortPackages(packages) {
76
77
  }
77
78
  return sorter.nodes;
78
79
  }
80
+ function groupPackagesByTopoLevel(packages) {
81
+ const filteredPackages = packages.filter((pkg) => pkg.name !== "@nocobase/docs");
82
+ const packageMap = new Map(filteredPackages.map((pkg) => [pkg.name, pkg]));
83
+ const dependencyMap = /* @__PURE__ */ new Map();
84
+ const reverseDependencyMap = /* @__PURE__ */ new Map();
85
+ for (const pkg of filteredPackages) {
86
+ const pkgJson = require(`${pkg.location}/package.json`);
87
+ const internalDeps = Object.keys({
88
+ ...pkgJson.dependencies,
89
+ ...pkgJson.devDependencies,
90
+ ...pkgJson.peerDependencies
91
+ }).filter((dep) => packageMap.has(dep));
92
+ dependencyMap.set(pkg.name, new Set(internalDeps));
93
+ for (const dep of internalDeps) {
94
+ if (!reverseDependencyMap.has(dep)) {
95
+ reverseDependencyMap.set(dep, /* @__PURE__ */ new Set());
96
+ }
97
+ reverseDependencyMap.get(dep).add(pkg.name);
98
+ }
99
+ }
100
+ const remainingDeps = new Map(
101
+ Array.from(dependencyMap.entries()).map(([name, deps]) => [name, new Set(deps)])
102
+ );
103
+ const pending = new Set(filteredPackages.map((pkg) => pkg.name));
104
+ const layers = [];
105
+ while (pending.size > 0) {
106
+ const layer = Array.from(pending).filter((name) => (remainingDeps.get(name)?.size ?? 0) === 0).map((name) => packageMap.get(name)).filter(Boolean);
107
+ if (layer.length === 0) {
108
+ throw new Error(
109
+ `Unable to group packages by topo level, possible circular dependency among: ${Array.from(pending).join(", ")}`
110
+ );
111
+ }
112
+ layers.push(layer);
113
+ for (const pkg of layer) {
114
+ pending.delete(pkg.name);
115
+ const dependents = reverseDependencyMap.get(pkg.name);
116
+ if (!dependents) {
117
+ continue;
118
+ }
119
+ for (const dependent of dependents) {
120
+ remainingDeps.get(dependent)?.delete(pkg.name);
121
+ }
122
+ }
123
+ }
124
+ return layers;
125
+ }
79
126
  // Annotate the CommonJS export names for ESM import in node:
80
127
  0 && (module.exports = {
81
128
  getPackages,
129
+ groupPackagesByTopoLevel,
82
130
  sortPackages
83
131
  });
@@ -27,17 +27,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var utils_exports = {};
29
29
  __export(utils_exports, {
30
+ createBuildProfileCollector: () => createBuildProfileCollector,
30
31
  defineConfig: () => defineConfig,
32
+ formatDuration: () => formatDuration,
31
33
  getEnvDefine: () => getEnvDefine,
32
34
  getPackageJson: () => getPackageJson,
33
35
  getPkgLog: () => getPkgLog,
34
36
  getUserConfig: () => getUserConfig,
37
+ nowMs: () => nowMs,
38
+ printBuildProfile: () => printBuildProfile,
35
39
  readFromCache: () => readFromCache,
40
+ runProfiledStage: () => runProfiledStage,
41
+ runScript: () => runScript,
42
+ runWithConcurrency: () => runWithConcurrency,
36
43
  toUnixPath: () => toUnixPath,
37
44
  writeToCache: () => writeToCache
38
45
  });
39
46
  module.exports = __toCommonJS(utils_exports);
40
47
  var import_chalk = __toESM(require("chalk"));
48
+ var import_execa = __toESM(require("execa"));
41
49
  var import_path = __toESM(require("path"));
42
50
  var import_fast_glob = __toESM(require("fast-glob"));
43
51
  var import_fs_extra = __toESM(require("fs-extra"));
@@ -86,7 +94,7 @@ function defineConfig(config) {
86
94
  function getUserConfig(cwd) {
87
95
  const config = defineConfig({
88
96
  modifyTsupConfig: (config2) => config2,
89
- modifyViteConfig: (config2) => config2
97
+ modifyRsbuildConfig: (config2) => config2
90
98
  });
91
99
  const buildConfigs = import_fast_glob.default.sync(["build.config.js", "build.config.ts"], { cwd });
92
100
  if (buildConfigs.length > 1) {
@@ -121,14 +129,128 @@ function getEnvDefine() {
121
129
  "process.env.APP_ENV": process.env.APP_ENV
122
130
  };
123
131
  }
132
+ function createBuildProfileCollector() {
133
+ return {
134
+ stages: [],
135
+ layers: [],
136
+ packages: []
137
+ };
138
+ }
139
+ async function runProfiledStage(profile, stageName, task) {
140
+ const startedAt = nowMs();
141
+ await task();
142
+ if (profile) {
143
+ profile.stages.push({
144
+ name: stageName,
145
+ durationMs: nowMs() - startedAt
146
+ });
147
+ }
148
+ }
149
+ async function runWithConcurrency(items, concurrency, worker) {
150
+ const queue = [...items];
151
+ const workers = Array.from({ length: Math.min(concurrency, queue.length) }, async () => {
152
+ while (queue.length > 0) {
153
+ const item = queue.shift();
154
+ if (!item) {
155
+ return;
156
+ }
157
+ await worker(item);
158
+ }
159
+ });
160
+ await Promise.all(workers);
161
+ }
162
+ function printBuildProfile(profile, totalDurationMs) {
163
+ const phaseTotals = /* @__PURE__ */ new Map();
164
+ for (const pkg of profile.packages) {
165
+ for (const [phaseName, duration] of Object.entries(pkg.phases)) {
166
+ phaseTotals.set(phaseName, (phaseTotals.get(phaseName) || 0) + duration);
167
+ }
168
+ }
169
+ console.log(import_chalk.default.cyan(`[@nocobase/build:profile] total build time ${formatDuration(totalDurationMs)}`));
170
+ if (profile.stages.length > 0) {
171
+ console.log(import_chalk.default.cyan("[@nocobase/build:profile] stage totals"));
172
+ for (const stage of [...profile.stages].sort((a, b) => b.durationMs - a.durationMs)) {
173
+ console.log(import_chalk.default.gray(` ${stage.name}: ${formatDuration(stage.durationMs)}`));
174
+ }
175
+ }
176
+ if (profile.layers.length > 0) {
177
+ console.log(import_chalk.default.cyan("[@nocobase/build:profile] slowest layers"));
178
+ for (const layer of [...profile.layers].sort((a, b) => b.durationMs - a.durationMs).slice(0, 12)) {
179
+ console.log(
180
+ import_chalk.default.gray(
181
+ ` ${layer.stageName} layer ${layer.layerIndex}/${layer.layerCount} (${layer.packageCount} packages): ${formatDuration(layer.durationMs)}`
182
+ )
183
+ );
184
+ }
185
+ }
186
+ if (phaseTotals.size > 0) {
187
+ console.log(import_chalk.default.cyan("[@nocobase/build:profile] aggregated package phases"));
188
+ for (const [phaseName, duration] of [...phaseTotals.entries()].sort((a, b) => b[1] - a[1])) {
189
+ console.log(import_chalk.default.gray(` ${phaseName}: ${formatDuration(duration)}`));
190
+ }
191
+ }
192
+ if (profile.packages.length > 0) {
193
+ const sourcePackages = profile.packages.filter((pkg) => pkg.kind === "source");
194
+ const declarationPackages = profile.packages.filter((pkg) => pkg.kind === "declaration");
195
+ console.log(import_chalk.default.cyan("[@nocobase/build:profile] slowest source packages"));
196
+ for (const pkg of [...sourcePackages].sort((a, b) => b.durationMs - a.durationMs).slice(0, 20)) {
197
+ const summary = Object.entries(pkg.phases).sort((a, b) => b[1] - a[1]).slice(0, 4).map(([name, duration]) => `${name}=${formatDuration(duration)}`).join(", ");
198
+ console.log(
199
+ import_chalk.default.gray(
200
+ ` ${pkg.name} [${pkg.status}] ${formatDuration(pkg.durationMs)}${summary ? ` (${summary})` : ""}`
201
+ )
202
+ );
203
+ }
204
+ console.log(import_chalk.default.cyan("[@nocobase/build:profile] slowest declaration packages"));
205
+ for (const pkg of [...declarationPackages].sort((a, b) => b.durationMs - a.durationMs).slice(0, 20)) {
206
+ const summary = Object.entries(pkg.phases).sort((a, b) => b[1] - a[1]).slice(0, 4).map(([name, duration]) => `${name}=${formatDuration(duration)}`).join(", ");
207
+ console.log(
208
+ import_chalk.default.gray(
209
+ ` ${pkg.name} [${pkg.status}] ${formatDuration(pkg.durationMs)}${summary ? ` (${summary})` : ""}`
210
+ )
211
+ );
212
+ }
213
+ }
214
+ }
215
+ function nowMs() {
216
+ return Date.now();
217
+ }
218
+ function formatDuration(durationMs) {
219
+ if (durationMs >= 6e4) {
220
+ return `${(durationMs / 6e4).toFixed(2)}m`;
221
+ }
222
+ if (durationMs >= 1e3) {
223
+ return `${(durationMs / 1e3).toFixed(2)}s`;
224
+ }
225
+ return `${Math.round(durationMs)}ms`;
226
+ }
227
+ function runScript(args, cwd, envs = {}) {
228
+ return (0, import_execa.default)("yarn", args, {
229
+ cwd,
230
+ stdio: "inherit",
231
+ env: {
232
+ ...process.env,
233
+ ...envs,
234
+ sourcemap: process.argv.includes("--sourcemap") ? "sourcemap" : void 0,
235
+ NODE_ENV: process.env.NODE_ENV || "production"
236
+ }
237
+ });
238
+ }
124
239
  // Annotate the CommonJS export names for ESM import in node:
125
240
  0 && (module.exports = {
241
+ createBuildProfileCollector,
126
242
  defineConfig,
243
+ formatDuration,
127
244
  getEnvDefine,
128
245
  getPackageJson,
129
246
  getPkgLog,
130
247
  getUserConfig,
248
+ nowMs,
249
+ printBuildProfile,
131
250
  readFromCache,
251
+ runProfiledStage,
252
+ runScript,
253
+ runWithConcurrency,
132
254
  toUnixPath,
133
255
  writeToCache
134
256
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/build",
3
- "version": "2.1.0-alpha.4",
3
+ "version": "2.1.0-alpha.40",
4
4
  "description": "Library build tool based on rollup.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -15,9 +15,13 @@
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.3.2",
24
+ "@rspack/core": "1.7.8",
21
25
  "@svgr/webpack": "^8.1.0",
22
26
  "@types/lerna__package": "5.1.0",
23
27
  "@types/lerna__project": "5.1.0",
@@ -38,18 +42,16 @@
38
42
  "postcss-preset-env": "^9.1.2",
39
43
  "react-imported-component": "^6.5.4",
40
44
  "style-loader": "^3.3.3",
41
- "tar": "^7.4.3",
45
+ "tar": "^7.5.15",
42
46
  "tsup": "8.2.4",
43
47
  "typescript": "5.1.3",
44
48
  "update-notifier": "3.0.0",
45
- "vite-plugin-css-injected-by-js": "^3.2.1",
46
- "vite-plugin-lib-inject-css": "1.2.0",
47
49
  "yargs-parser": "13.1.2"
48
50
  },
49
- "license": "AGPL-3.0",
51
+ "license": "Apache-2.0",
50
52
  "scripts": {
51
53
  "build": "tsup",
52
54
  "build:watch": "tsup --watch"
53
55
  },
54
- "gitHead": "32c682485e5f1878b9165be2e9de18000d98f935"
56
+ "gitHead": "e73f99dd0abefe847f2e50ff0fea1f41a82fd048"
55
57
  }