@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.
- package/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/build.js +258 -70
- package/lib/buildClient.js +113 -53
- package/lib/buildDeclaration.js +17 -2
- package/lib/buildPlugin.js +79 -47
- package/lib/constant.js +15 -3
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +109 -0
- package/lib/utils/buildPluginUtils.js +1 -1
- package/lib/utils/getDepsConfig.js +1 -1
- package/lib/utils/getPackages.js +48 -0
- package/lib/utils/utils.js +123 -1
- package/package.json +8 -6
package/lib/utils/getPackages.js
CHANGED
|
@@ -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
|
});
|
package/lib/utils/utils.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "2.1.0-alpha.21",
|
|
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.
|
|
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",
|
|
@@ -42,14 +46,12 @@
|
|
|
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": "
|
|
51
|
+
"license": "Apache-2.0",
|
|
50
52
|
"scripts": {
|
|
51
53
|
"build": "tsup",
|
|
52
54
|
"build:watch": "tsup --watch"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b4c2b469f321ecaec7863a8ae371a02fe6a35aa2"
|
|
55
57
|
}
|