Skip to content

Commit

Permalink
feat: align webpack target and stats api (#7027)
Browse files Browse the repository at this point in the history
* feat: support keys for namedChunks

* feat: target support es6

* feat: add startTime and endTime in stats
  • Loading branch information
SyMind committed Jul 3, 2024
1 parent ec2b316 commit b05f523
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class JsCompilation {
getModules(): Array<JsModule>
getOptimizationBailout(): Array<JsStatsOptimizationBailout>
getChunks(): Array<JsChunk>
getNamedChunkKeys(): Array<string>
getNamedChunk(name: string): JsChunk | null
setAssetSource(name: string, source: JsCompatSource): void
deleteAssetSource(name: string): void
Expand Down
5 changes: 5 additions & 0 deletions crates/rspack_binding_values/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ impl JsCompilation {
.collect::<Vec<_>>()
}

#[napi]
pub fn get_named_chunk_keys(&self) -> Vec<String> {
self.0.named_chunks.keys().cloned().collect::<Vec<_>>()
}

#[napi]
pub fn get_named_chunk(&self, name: String) -> Option<JsChunk> {
self
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/options/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Target {
"browserslist" => TargetEsVersion::BrowsersList,
"es3" => TargetEsVersion::Esx(EsVersion::Es3),
"es5" => TargetEsVersion::Esx(EsVersion::Es5),
"es6" => TargetEsVersion::Esx(EsVersion::Es2015),
"es2015" => TargetEsVersion::Esx(EsVersion::Es2015),
"es2016" => TargetEsVersion::Esx(EsVersion::Es2016),
"es2017" => TargetEsVersion::Esx(EsVersion::Es2017),
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12382,12 +12382,16 @@ export class Stats {
// (undocumented)
compilation: Compilation;
// (undocumented)
get endTime(): number | undefined;
// (undocumented)
hasErrors(): boolean;
// (undocumented)
get hash(): Readonly<string | null>;
// (undocumented)
hasWarnings(): boolean;
// (undocumented)
get startTime(): number | undefined;
// (undocumented)
toJson(opts?: StatsValue, forToString?: boolean): StatsCompilation;
// (undocumented)
toString(opts?: StatsValue): string;
Expand Down
9 changes: 6 additions & 3 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
type JsModule,
type JsPathData,
JsRspackSeverity,
type JsRuntimeModule,
type JsStatsError
type JsRuntimeModule
} from "@rspack/binding";
import * as liteTapable from "@rspack/lite-tapable";
import { Source } from "webpack-sources";
Expand Down Expand Up @@ -376,10 +375,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
/**
* Get the named chunks.
*
* Note: This is a proxy for webpack internal API, only method `get` is supported now.
* Note: This is a proxy for webpack internal API, only method `get` and `keys` is supported now.
*/
get namedChunks(): ReadonlyMap<string, Readonly<Chunk>> {
return {
keys: (): IterableIterator<string> => {
const names = this.#inner.getNamedChunkKeys();
return names[Symbol.iterator]();
},
get: (property: unknown) => {
if (typeof property === "string") {
const chunk = this.#inner.getNamedChunk(property) || undefined;
Expand Down
8 changes: 8 additions & 0 deletions packages/rspack/src/Stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export class Stats {
return this.compilation.hash;
}

get startTime() {
return this.compilation.startTime;
}

get endTime() {
return this.compilation.endTime;
}

hasErrors() {
return this.#inner.getErrors().length > 0;
}
Expand Down

2 comments on commit b05f523

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ❌ failure
compat ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-03 453c208) Current Change
10000_development-mode + exec 2.14 s ± 12 ms 2.15 s ± 20 ms +0.18 %
10000_development-mode_hmr + exec 688 ms ± 4.5 ms 694 ms ± 5.3 ms +0.80 %
10000_production-mode + exec 2.76 s ± 23 ms 2.78 s ± 23 ms +0.72 %
arco-pro_development-mode + exec 1.87 s ± 84 ms 1.89 s ± 73 ms +0.95 %
arco-pro_development-mode_hmr + exec 434 ms ± 0.81 ms 435 ms ± 0.98 ms +0.29 %
arco-pro_production-mode + exec 3.45 s ± 83 ms 3.45 s ± 87 ms -0.02 %
threejs_development-mode_10x + exec 1.58 s ± 19 ms 1.59 s ± 16 ms +0.77 %
threejs_development-mode_10x_hmr + exec 799 ms ± 8.8 ms 818 ms ± 5.3 ms +2.44 %
threejs_production-mode_10x + exec 5.6 s ± 36 ms 5.63 s ± 29 ms +0.42 %

Please sign in to comment.