@nocobase/build 2.1.0-beta.9 → 2.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  });
@@ -40,7 +40,7 @@ const obfuscate = (filePath) => {
40
40
  deadCodeInjection: false,
41
41
  debugProtection: false,
42
42
  debugProtectionInterval: 0,
43
- disableConsoleOutput: true,
43
+ disableConsoleOutput: false,
44
44
  identifierNamesGenerator: "hexadecimal",
45
45
  log: false,
46
46
  numbersToExpressions: false,
@@ -59,6 +59,7 @@ const obfuscate = (filePath) => {
59
59
  stringArrayWrappersParametersMaxCount: 2,
60
60
  stringArrayWrappersType: "variable",
61
61
  stringArrayThreshold: 0.75,
62
+ target: "node",
62
63
  unicodeEscapeSequence: false
63
64
  });
64
65
  import_fs_extra.default.writeFileSync(filePath, obfuscationResult.getObfuscatedCode(), "utf8");
@@ -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-beta.9",
3
+ "version": "2.2.0-beta.1",
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,12 +42,10 @@
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
51
  "license": "Apache-2.0",
@@ -51,5 +53,5 @@
51
53
  "build": "tsup",
52
54
  "build:watch": "tsup --watch"
53
55
  },
54
- "gitHead": "c3a2875e4cbbb43b1f2361e6f9f5f84a7d3f3c3c"
56
+ "gitHead": "f82fa9d0c3aa8e00e53dd94e404a312483b4866b"
55
57
  }