Skip to content

Commit d04485d

Browse files
authored
feat: stats for timings and builtAt (#2425)
1 parent eb7051f commit d04485d

File tree

13 files changed

+85
-36
lines changed

13 files changed

+85
-36
lines changed

.changeset/stale-ways-drum.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rspack/core": patch
3+
"@rspack/cli": patch
4+
---
5+
6+
feat: stats for timings and builtAt

packages/rspack-cli/src/commands/build.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ export class BuildCommand implements RspackCommand {
8383
}
8484
}
8585
};
86-
console.time("build");
86+
8787
let rspackOptions = { ...options, argv: { ...options } };
8888

8989
const errorHandler = (err, Stats) => {
9090
callback(err, Stats);
91-
console.timeEnd("build");
9291
};
9392

9493
const compiler = await cli.createCompiler(

packages/rspack-cli/src/rspack-cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class RspackCLI {
155155
}
156156

157157
if (typeof item.stats === "undefined") {
158-
item.stats = { preset: "errors-warnings" };
158+
item.stats = { preset: "errors-warnings", timings: true };
159159
} else if (typeof item.stats === "boolean") {
160160
item.stats = item.stats ? { preset: "normal" } : { preset: "none" };
161161
} else if (typeof item.stats === "string") {

packages/rspack/scripts/precompile-schema.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,23 @@ ajv.addKeyword({
7777

7878
const validate = ajv.compile(require(configSchema));
7979
const code = standaloneCode(ajv, validate);
80-
terser
81-
.minify(code, {
82-
compress: {
83-
passes: 3
84-
},
85-
mangle: true,
86-
ecma: 2015,
87-
toplevel: true
88-
})
89-
.then(minified => {
90-
const code =
91-
"/** This file was automatically generated, Run `pnpm precompile-schema` to update */\n" +
92-
minified.code;
93-
fs.promises.writeFile(configCheck, code);
94-
});
80+
const generated =
81+
"/** This file was automatically generated, Run `pnpm precompile-schema` to update */\n" +
82+
code;
83+
fs.writeFileSync(configCheck, generated);
84+
85+
// terser
86+
// .minify(code, {
87+
// compress: {
88+
// passes: 3
89+
// },
90+
// mangle: true,
91+
// ecma: 2015,
92+
// toplevel: true
93+
// })
94+
// .then(minified => {
95+
// const code =
96+
// "/** This file was automatically generated, Run `pnpm precompile-schema` to update */\n" +
97+
// minified.code;
98+
// fs.promises.writeFile(configCheck, code);
99+
// });

packages/rspack/src/compilation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ export class Compilation {
8585
inputFileSystem: any;
8686
logging: Map<string, LogEntry[]>;
8787
name?: string;
88+
startTime?: number;
89+
endTime?: number;
8890
normalModuleFactory?: NormalModuleFactory;
8991

9092
constructor(compiler: Compiler, inner: JsCompilation) {
9193
this.name = undefined;
94+
this.startTime = undefined;
95+
this.endTime = undefined;
9296
let processAssetsHooks = createFakeProcessAssetsHook(this);
9397
this.hooks = {
9498
processAssets: processAssetsHooks,
@@ -227,6 +231,11 @@ export class Compilation {
227231
options.outputPath,
228232
!context.forToString
229233
);
234+
options.timings = optionOrLocalFallback(options.timings, true);
235+
options.builtAt = optionOrLocalFallback(
236+
options.builtAt,
237+
!context.forToString
238+
);
230239

231240
return options;
232241
}

packages/rspack/src/compiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ class Compiler {
381381
if (this.running) {
382382
return callback(new ConcurrentCompilationError());
383383
}
384+
const startTime = Date.now();
384385
this.running = true;
385386
const doRun = () => {
386387
// @ts-expect-error
@@ -407,6 +408,8 @@ class Compiler {
407408
if (err) {
408409
return finalCallback(err);
409410
}
411+
this.compilation.startTime = startTime;
412+
this.compilation.endTime = Date.now();
410413
const stats = new Stats(this.compilation);
411414
this.hooks.done.callAsync(stats, err => {
412415
if (err) {

packages/rspack/src/config/adapter-rule-use.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ function composeJsUse(
591591
typeof sourceMap === "string"
592592
? sourceMap
593593
: JSON.stringify(sourceMap)
594-
)
594+
)
595595
: undefined,
596596
additionalData: additionalData
597597
? toBuffer(JSON.stringify(additionalData))

packages/rspack/src/config/schema.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,27 @@ module.exports = {
15841584
warningsCount: {
15851585
description: "Add warnings count.",
15861586
type: "boolean"
1587+
},
1588+
outputPath: {
1589+
description: "Add output path information.",
1590+
type: "boolean"
1591+
},
1592+
chunkModules: {
1593+
description: "Add built modules information to chunk information.",
1594+
type: "boolean"
1595+
},
1596+
chunkRelations: {
1597+
description:
1598+
"Add information about parent, children and sibling chunks to chunk information.",
1599+
type: "boolean"
1600+
},
1601+
timings: {
1602+
description: "Add timing information.",
1603+
type: "boolean"
1604+
},
1605+
builtAt: {
1606+
description: "Add built at time information.",
1607+
type: "boolean"
15871608
}
15881609
}
15891610
},

packages/rspack/src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ export interface StatsOptions {
426426
outputPath?: boolean;
427427
chunkModules?: boolean;
428428
chunkRelations?: boolean;
429+
timings?: boolean;
430+
builtAt?: boolean;
429431
}
430432

431433
///// Optimization /////

packages/rspack/src/stats.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { LogType } from "./logging/Logger";
1515
export type StatsCompilation = {
1616
name?: string;
1717
hash?: string;
18+
time?: number;
19+
builtAt?: number;
1820
publicPath?: string;
1921
outputPath?: string;
2022
assets?: binding.JsStatsAsset[];
@@ -62,6 +64,12 @@ export class Stats {
6264
if (options.hash) {
6365
obj.hash = this.#inner.getHash();
6466
}
67+
if (options.timings) {
68+
obj.time = this.compilation.endTime! - this.compilation.startTime!;
69+
}
70+
if (options.builtAt) {
71+
obj.builtAt = this.compilation.endTime;
72+
}
6573
if (options.publicPath) {
6674
obj.publicPath = this.compilation.outputOptions.publicPath;
6775
}

0 commit comments

Comments
 (0)