@rspack/core 0.7.5-canary-0d03907-20240624125011 → 0.7.5

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.
Files changed (46) hide show
  1. package/dist/Chunk.d.ts +14 -19
  2. package/dist/Chunk.js +17 -22
  3. package/dist/ChunkGraph.d.ts +1 -1
  4. package/dist/ChunkGraph.js +5 -5
  5. package/dist/ChunkGroup.d.ts +7 -17
  6. package/dist/ChunkGroup.js +2 -12
  7. package/dist/Compilation.d.ts +22 -18
  8. package/dist/Compilation.js +43 -20
  9. package/dist/Compiler.js +2 -18
  10. package/dist/Entrypoint.d.ts +1 -1
  11. package/dist/Entrypoint.js +2 -2
  12. package/dist/Module.d.ts +6 -7
  13. package/dist/Module.js +0 -1
  14. package/dist/NormalModule.d.ts +1 -0
  15. package/dist/NormalModule.js +7 -0
  16. package/dist/NormalModuleFactory.js +22 -0
  17. package/dist/Stats.d.ts +2 -2
  18. package/dist/builtin-loader/swc/emotion.d.ts +17 -0
  19. package/dist/builtin-loader/swc/emotion.js +22 -0
  20. package/dist/builtin-loader/swc/index.d.ts +4 -0
  21. package/dist/builtin-loader/swc/index.js +5 -1
  22. package/dist/builtin-loader/swc/preact.d.ts +4 -3
  23. package/dist/builtin-loader/swc/relay.d.ts +5 -0
  24. package/dist/builtin-loader/swc/relay.js +48 -0
  25. package/dist/builtin-loader/swc/types.d.ts +17 -2
  26. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +9 -15
  27. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -50
  28. package/dist/builtin-plugin/css-extract/index.d.ts +2 -2
  29. package/dist/config/adapter.js +10 -23
  30. package/dist/config/adapterRuleUse.js +11 -0
  31. package/dist/config/defaults.js +0 -1
  32. package/dist/config/normalization.js +2 -12
  33. package/dist/config/zod.d.ts +10 -114
  34. package/dist/config/zod.js +6 -8
  35. package/dist/exports.d.ts +1 -2
  36. package/dist/exports.js +1 -4
  37. package/dist/loader-runner/index.js +6 -27
  38. package/dist/stats/DefaultStatsFactoryPlugin.js +2 -19
  39. package/dist/stats/DefaultStatsPrinterPlugin.js +2 -2
  40. package/dist/stats/statsFactoryUtils.d.ts +2 -4
  41. package/dist/util/index.d.ts +2 -2
  42. package/dist/util/index.js +3 -4
  43. package/dist/util/memoize.js +1 -5
  44. package/package.json +4 -8
  45. package/dist/RspackError.d.ts +0 -8
  46. package/dist/RspackError.js +0 -21
package/dist/Chunk.d.ts CHANGED
@@ -3,19 +3,19 @@ import { Compilation } from ".";
3
3
  import { ChunkGroup } from "./ChunkGroup";
4
4
  export declare class Chunk {
5
5
  #private;
6
- name?: Readonly<string>;
7
- id?: Readonly<string>;
8
- ids: ReadonlyArray<string>;
9
- idNameHints: ReadonlyArray<string>;
10
- filenameTemplate?: Readonly<string>;
11
- cssFilenameTemplate?: Readonly<string>;
12
- files: ReadonlySet<string>;
13
- runtime: ReadonlySet<string>;
14
- hash?: Readonly<string>;
15
- contentHash: Readonly<Record<string, string>>;
16
- renderedHash?: Readonly<string>;
17
- chunkReason?: Readonly<string>;
18
- auxiliaryFiles: ReadonlySet<string>;
6
+ name?: string;
7
+ id?: string;
8
+ ids: Array<string>;
9
+ idNameHints: Array<string>;
10
+ filenameTemplate?: string;
11
+ cssFilenameTemplate?: string;
12
+ files: Array<string>;
13
+ runtime: Array<string>;
14
+ hash?: string;
15
+ contentHash: Record<string, string>;
16
+ renderedHash?: string;
17
+ chunkReasons: Array<string>;
18
+ auxiliaryFiles: Array<string>;
19
19
  static __from_binding(chunk: JsChunk, compilation: Compilation): Chunk;
20
20
  static __from_binding(chunk: JsChunk, compilation: JsCompilation): Chunk;
21
21
  constructor(chunk: JsChunk, compilation: JsCompilation);
@@ -26,10 +26,5 @@ export declare class Chunk {
26
26
  getAllAsyncChunks(): Iterable<Chunk>;
27
27
  getAllInitialChunks(): Iterable<Chunk>;
28
28
  getAllReferencedChunks(): Iterable<Chunk>;
29
- /**
30
- * Note: This is not a webpack public API, maybe removed in future.
31
- *
32
- * @internal
33
- */
34
- __internal__innerUkey(): number;
29
+ __internal_innerUkey(): number;
35
30
  }
package/dist/Chunk.js CHANGED
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Chunk_inner, _Chunk_innerCompilation;
13
+ var _Chunk_inner, _Chunk_inner_compilation;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Chunk = void 0;
16
16
  const binding_1 = require("@rspack/binding");
@@ -26,57 +26,52 @@ class Chunk {
26
26
  }
27
27
  constructor(chunk, compilation) {
28
28
  _Chunk_inner.set(this, void 0);
29
- _Chunk_innerCompilation.set(this, void 0);
29
+ _Chunk_inner_compilation.set(this, void 0);
30
30
  __classPrivateFieldSet(this, _Chunk_inner, chunk, "f");
31
- __classPrivateFieldSet(this, _Chunk_innerCompilation, compilation, "f");
31
+ __classPrivateFieldSet(this, _Chunk_inner_compilation, compilation, "f");
32
32
  this.name = chunk.name;
33
33
  this.id = chunk.id;
34
34
  this.ids = chunk.ids;
35
35
  this.idNameHints = chunk.idNameHints;
36
36
  this.filenameTemplate = chunk.filenameTemplate;
37
37
  this.cssFilenameTemplate = chunk.cssFilenameTemplate;
38
- this.files = new Set(chunk.files);
39
- this.runtime = new Set(chunk.runtime);
38
+ this.files = chunk.files;
39
+ this.runtime = chunk.runtime;
40
40
  this.hash = chunk.hash;
41
41
  this.contentHash = chunk.contentHash;
42
42
  this.renderedHash = chunk.renderedHash;
43
- this.chunkReason = chunk.chunkReason;
44
- this.auxiliaryFiles = new Set(chunk.auxiliaryFiles);
43
+ this.chunkReasons = chunk.chunkReasons;
44
+ this.auxiliaryFiles = chunk.auxiliaryFiles;
45
45
  }
46
46
  isOnlyInitial() {
47
- return (0, binding_1.__chunk_inner_is_only_initial)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"));
47
+ return (0, binding_1.__chunk_inner_is_only_initial)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"));
48
48
  }
49
49
  canBeInitial() {
50
- return (0, binding_1.__chunk_inner_can_be_initial)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"));
50
+ return (0, binding_1.__chunk_inner_can_be_initial)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"));
51
51
  }
52
52
  hasRuntime() {
53
- return (0, binding_1.__chunk_inner_has_runtime)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"));
53
+ return (0, binding_1.__chunk_inner_has_runtime)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"));
54
54
  }
55
55
  get groupsIterable() {
56
56
  const chunk_groups = __classPrivateFieldGet(this, _Chunk_inner, "f").__inner_groups.map(ukey => {
57
- const cg = (0, binding_1.__chunk_group_inner_get_chunk_group)(ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"));
58
- return ChunkGroup_1.ChunkGroup.__from_binding(cg, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"));
57
+ const cg = (0, binding_1.__chunk_group_inner_get_chunk_group)(ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"));
58
+ return ChunkGroup_1.ChunkGroup.__from_binding(cg, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"));
59
59
  });
60
60
  chunk_groups.sort(comparators_1.compareChunkGroupsByIndex);
61
61
  return new Set(chunk_groups);
62
62
  }
63
63
  getAllAsyncChunks() {
64
- return new Set((0, binding_1.__chunk_inner_get_all_async_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"))));
64
+ return new Set((0, binding_1.__chunk_inner_get_all_async_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"))));
65
65
  }
66
66
  getAllInitialChunks() {
67
- return new Set((0, binding_1.__chunk_inner_get_all_initial_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"))));
67
+ return new Set((0, binding_1.__chunk_inner_get_all_initial_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"))));
68
68
  }
69
69
  getAllReferencedChunks() {
70
- return new Set((0, binding_1.__chunk_inner_get_all_referenced_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_innerCompilation, "f"))));
70
+ return new Set((0, binding_1.__chunk_inner_get_all_referenced_chunks)(__classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f")).map(c => Chunk.__from_binding(c, __classPrivateFieldGet(this, _Chunk_inner_compilation, "f"))));
71
71
  }
72
- /**
73
- * Note: This is not a webpack public API, maybe removed in future.
74
- *
75
- * @internal
76
- */
77
- __internal__innerUkey() {
72
+ __internal_innerUkey() {
78
73
  return __classPrivateFieldGet(this, _Chunk_inner, "f").__inner_ukey;
79
74
  }
80
75
  }
81
76
  exports.Chunk = Chunk;
82
- _Chunk_inner = new WeakMap(), _Chunk_innerCompilation = new WeakMap();
77
+ _Chunk_inner = new WeakMap(), _Chunk_inner_compilation = new WeakMap();
@@ -4,7 +4,7 @@ import { Module } from "./Module";
4
4
  export declare class ChunkGraph {
5
5
  private compilation;
6
6
  constructor(compilation: Compilation);
7
- getChunkModules(chunk: Chunk): Readonly<Module[]>;
7
+ getChunkModules(chunk: Chunk): Module[];
8
8
  getChunkModulesIterable(chunk: Chunk): Iterable<Module>;
9
9
  getChunkEntryModulesIterable(chunk: Chunk): Iterable<Module>;
10
10
  getChunkEntryDependentChunksIterable(chunk: Chunk): Iterable<Chunk>;
@@ -9,19 +9,19 @@ class ChunkGraph {
9
9
  this.compilation = compilation;
10
10
  }
11
11
  getChunkModules(chunk) {
12
- return (0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal__innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation));
12
+ return (0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation));
13
13
  }
14
14
  getChunkModulesIterable(chunk) {
15
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal__innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
15
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
16
16
  }
17
17
  getChunkEntryModulesIterable(chunk) {
18
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_modules)(chunk.__internal__innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
18
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_modules)(chunk.__internal_innerUkey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
19
19
  }
20
20
  getChunkEntryDependentChunksIterable(chunk) {
21
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable)(chunk.__internal__innerUkey(), this.compilation.__internal_getInner()).map(c => Chunk_1.Chunk.__from_binding(c, this.compilation.__internal_getInner())));
21
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable)(chunk.__internal_innerUkey(), this.compilation.__internal_getInner()).map(c => Chunk_1.Chunk.__from_binding(c, this.compilation.__internal_getInner())));
22
22
  }
23
23
  getChunkModulesIterableBySourceType(chunk, sourceType) {
24
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules_iterable_by_source_type)(chunk.__internal__innerUkey(), sourceType, this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
24
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules_iterable_by_source_type)(chunk.__internal_innerUkey(), sourceType, this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
25
25
  }
26
26
  }
27
27
  exports.ChunkGraph = ChunkGraph;
@@ -4,21 +4,11 @@ export declare class ChunkGroup {
4
4
  #private;
5
5
  static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation): ChunkGroup;
6
6
  protected constructor(inner: JsChunkGroup, compilation: JsCompilation);
7
- getFiles(): ReadonlyArray<string>;
8
- getParents(): ReadonlyArray<ChunkGroup>;
9
- get chunks(): ReadonlyArray<Chunk>;
10
- get index(): Readonly<number | undefined>;
11
- get name(): Readonly<string | undefined>;
12
- /**
13
- * Note: This is not a webpack public API, maybe removed in future.
14
- *
15
- * @internal
16
- */
17
- __internal__innerUkey(): number;
18
- /**
19
- * Note: This is not a webpack public API, maybe removed in future.
20
- *
21
- * @internal
22
- */
23
- __internal__innerCompilation(): JsCompilation;
7
+ getFiles(): string[];
8
+ getParents(): ChunkGroup[];
9
+ get chunks(): Chunk[];
10
+ get index(): number | undefined;
11
+ get name(): string | undefined;
12
+ __internal_innerUkey(): number;
13
+ __internal_innerCompilation(): JsCompilation;
24
14
  }
@@ -49,20 +49,10 @@ class ChunkGroup {
49
49
  get name() {
50
50
  return __classPrivateFieldGet(this, _ChunkGroup_inner, "f").name;
51
51
  }
52
- /**
53
- * Note: This is not a webpack public API, maybe removed in future.
54
- *
55
- * @internal
56
- */
57
- __internal__innerUkey() {
52
+ __internal_innerUkey() {
58
53
  return __classPrivateFieldGet(this, _ChunkGroup_inner, "f").__inner_ukey;
59
54
  }
60
- /**
61
- * Note: This is not a webpack public API, maybe removed in future.
62
- *
63
- * @internal
64
- */
65
- __internal__innerCompilation() {
55
+ __internal_innerCompilation() {
66
56
  return __classPrivateFieldGet(this, _ChunkGroup_innerCompilation, "f");
67
57
  }
68
58
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * The following code is modified based on
3
4
  * https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Compilation.js
@@ -7,8 +8,7 @@
7
8
  * Copyright (c) JS Foundation and other contributors
8
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
10
  */
10
- import type * as binding from "@rspack/binding";
11
- import { type ExternalObject, type JsCompilation, type JsModule, type JsPathData, type JsRuntimeModule } from "@rspack/binding";
11
+ import type { ExternalObject, JsCompilation, JsModule, JsPathData, JsRuntimeModule, JsStatsError, JsStatsWarning } from "@rspack/binding";
12
12
  import * as tapable from "tapable";
13
13
  import { Source } from "webpack-sources";
14
14
  import { ContextModuleFactory } from "./ContextModuleFactory";
@@ -26,8 +26,7 @@ import { Logger } from "./logging/Logger";
26
26
  import { StatsFactory } from "./stats/StatsFactory";
27
27
  import { StatsPrinter } from "./stats/StatsPrinter";
28
28
  import { type AssetInfo } from "./util/AssetInfo";
29
- import Hash = require("./util/hash");
30
- import { RspackError } from "./RspackError";
29
+ import MergeCaller from "./util/MergeCaller";
31
30
  export { type AssetInfo } from "./util/AssetInfo";
32
31
  export type Assets = Record<string, Source>;
33
32
  export interface Asset {
@@ -103,7 +102,7 @@ export type CreateStatsOptionsContext = KnownCreateStatsOptionsContext & Record<
103
102
  export type NormalizedStatsOptions = KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, any>;
104
103
  export declare class Compilation {
105
104
  #private;
106
- hooks: Readonly<{
105
+ hooks: {
107
106
  processAssets: liteTapable.AsyncSeriesHook<Assets>;
108
107
  afterProcessAssets: liteTapable.SyncHook<Assets>;
109
108
  childCompiler: tapable.SyncHook<[Compiler, string, number]>;
@@ -120,7 +119,6 @@ export declare class Compilation {
120
119
  Iterable<Module>
121
120
  ], void>;
122
121
  finishModules: liteTapable.AsyncSeriesHook<[Iterable<Module>], void>;
123
- chunkHash: liteTapable.SyncHook<[Chunk, Hash], void>;
124
122
  chunkAsset: liteTapable.SyncHook<[Chunk, string], void>;
125
123
  processWarnings: tapable.SyncWaterfallHook<[Error[]]>;
126
124
  succeedModule: liteTapable.SyncHook<[Module], void>;
@@ -143,7 +141,7 @@ export declare class Compilation {
143
141
  ], void>;
144
142
  runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>;
145
143
  afterSeal: liteTapable.AsyncSeriesHook<[], void>;
146
- }>;
144
+ };
147
145
  name?: string;
148
146
  startTime?: number;
149
147
  endTime?: number;
@@ -160,8 +158,13 @@ export declare class Compilation {
160
158
  createSnapshot(): null;
161
159
  };
162
160
  constructor(compiler: Compiler, inner: JsCompilation);
163
- get hash(): Readonly<string | null>;
164
- get fullHash(): Readonly<string | null>;
161
+ get currentNormalModuleHooks(): {
162
+ loader: tapable.SyncHook<[import("./config").LoaderContext<{}>], void, tapable.UnsetAdditionalOptions>;
163
+ readResourceForScheme: any;
164
+ readResource: tapable.HookMap<tapable.AsyncSeriesBailHook<[import("./config").LoaderContext<{}>], string | Buffer, tapable.UnsetAdditionalOptions>>;
165
+ };
166
+ get hash(): string | null;
167
+ get fullHash(): string | null;
165
168
  /**
166
169
  * Get a map of all assets.
167
170
  */
@@ -170,14 +173,14 @@ export declare class Compilation {
170
173
  * Get a map of all entrypoints.
171
174
  */
172
175
  get entrypoints(): ReadonlyMap<string, Entrypoint>;
173
- get modules(): ReadonlySet<Module>;
174
- get chunks(): ReadonlySet<Chunk>;
176
+ get modules(): Module[];
177
+ get chunks(): Chunk[];
175
178
  /**
176
179
  * Get the named chunks.
177
180
  *
178
181
  * Note: This is a proxy for webpack internal API, only method `get` is supported now.
179
182
  */
180
- get namedChunks(): ReadonlyMap<string, Readonly<Chunk>>;
183
+ get namedChunks(): Map<string, Readonly<Chunk>>;
181
184
  /**
182
185
  * Note: This is not a webpack public API, maybe removed in future.
183
186
  *
@@ -217,19 +220,19 @@ export declare class Compilation {
217
220
  *
218
221
  * @internal
219
222
  */
220
- __internal__pushDiagnostic(diagnostic: binding.JsDiagnostic): void;
223
+ __internal__pushDiagnostic(severity: "error" | "warning", title: string, message: string): void;
221
224
  /**
222
225
  * Note: This is not a webpack public API, maybe removed in future.
223
226
  *
224
227
  * @internal
225
228
  */
226
229
  __internal__pushNativeDiagnostics(diagnostics: ExternalObject<"Diagnostic[]">): void;
227
- get errors(): RspackError[];
228
- get warnings(): RspackError[];
230
+ get errors(): JsStatsError[];
231
+ get warnings(): JsStatsWarning[];
229
232
  getPath(filename: Filename, data?: PathData): string;
230
- getPathWithInfo(filename: Filename, data?: PathData): binding.PathWithInfo;
233
+ getPathWithInfo(filename: Filename, data?: PathData): import("@rspack/binding").PathWithInfo;
231
234
  getAssetPath(filename: Filename, data?: PathData): string;
232
- getAssetPathWithInfo(filename: Filename, data?: PathData): binding.PathWithInfo;
235
+ getAssetPathWithInfo(filename: Filename, data?: PathData): import("@rspack/binding").PathWithInfo;
233
236
  getLogger(name: string | (() => string)): Logger;
234
237
  fileDependencies: {
235
238
  [Symbol.iterator](): Generator<string, void, unknown>;
@@ -257,6 +260,7 @@ export declare class Compilation {
257
260
  };
258
261
  getStats(): Stats;
259
262
  createChildCompiler(name: string, outputOptions: OutputNormalized, plugins: RspackPluginInstance[]): Compiler;
263
+ _rebuildModuleCaller: MergeCaller<[string, (err: Error, m: Module) => void]>;
260
264
  rebuildModule(m: Module, f: (err: Error, m: Module) => void): void;
261
265
  /**
262
266
  * Get the `Source` of a given asset filename.
@@ -315,7 +319,7 @@ export declare class Compilation {
315
319
  *
316
320
  * @internal
317
321
  */
318
- __internal_getInner(): binding.JsCompilation;
322
+ __internal_getInner(): JsCompilation;
319
323
  seal(): void;
320
324
  unseal(): void;
321
325
  static PROCESS_ASSETS_STAGE_ADDITIONAL: number;
@@ -36,10 +36,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_customModules, _Compilation_createCachedAssets, _Compilation_rebuildModuleCaller;
39
+ var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_customModules, _Compilation_createCachedAssets;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compilation = void 0;
42
- const binding_1 = require("@rspack/binding");
43
42
  const tapable = __importStar(require("tapable"));
44
43
  const liteTapable = __importStar(require("./lite-tapable"));
45
44
  const Chunk_1 = require("./Chunk");
@@ -47,16 +46,17 @@ const ChunkGraph_1 = require("./ChunkGraph");
47
46
  const Entrypoint_1 = require("./Entrypoint");
48
47
  const ErrorHelpers_1 = __importDefault(require("./ErrorHelpers"));
49
48
  const Module_1 = require("./Module");
49
+ const NormalModule_1 = require("./NormalModule");
50
50
  const Stats_1 = require("./Stats");
51
51
  const Logger_1 = require("./logging/Logger");
52
52
  const StatsFactory_1 = require("./stats/StatsFactory");
53
53
  const StatsPrinter_1 = require("./stats/StatsPrinter");
54
+ const util_1 = require("./util");
54
55
  const AssetInfo_1 = require("./util/AssetInfo");
55
56
  const MergeCaller_1 = __importDefault(require("./util/MergeCaller"));
56
57
  const fake_1 = require("./util/fake");
57
58
  const memoize_1 = require("./util/memoize");
58
59
  const source_1 = require("./util/source");
59
- const RspackError_1 = require("./RspackError");
60
60
  class Compilation {
61
61
  constructor(compiler, inner) {
62
62
  _Compilation_instances.add(this);
@@ -77,7 +77,7 @@ class Compilation {
77
77
  this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getContextDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
78
78
  this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getMissingDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
79
79
  this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getBuildDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
80
- _Compilation_rebuildModuleCaller.set(this, (function (compilation) {
80
+ this._rebuildModuleCaller = (function (compilation) {
81
81
  return new MergeCaller_1.default((args) => {
82
82
  __classPrivateFieldGet(compilation, _Compilation_inner, "f").rebuildModule(args.map(item => item[0]), function (err, modules) {
83
83
  for (const [id, callback] of args) {
@@ -91,7 +91,7 @@ class Compilation {
91
91
  }
92
92
  });
93
93
  }, 10);
94
- })(this));
94
+ })(this);
95
95
  __classPrivateFieldSet(this, _Compilation_inner, inner, "f");
96
96
  __classPrivateFieldSet(this, _Compilation_cachedAssets, __classPrivateFieldGet(this, _Compilation_instances, "m", _Compilation_createCachedAssets).call(this), "f");
97
97
  __classPrivateFieldSet(this, _Compilation_customModules, {}, "f");
@@ -145,7 +145,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
145
145
  "modules"
146
146
  ]),
147
147
  finishModules: new liteTapable.AsyncSeriesHook(["modules"]),
148
- chunkHash: new liteTapable.SyncHook(["chunk", "hash"]),
149
148
  chunkAsset: new liteTapable.SyncHook(["chunk", "filename"]),
150
149
  processWarnings: new tapable.SyncWaterfallHook(["warnings"]),
151
150
  succeedModule: new liteTapable.SyncHook(["module"]),
@@ -173,6 +172,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
173
172
  this.children = [];
174
173
  this.chunkGraph = new ChunkGraph_1.ChunkGraph(this);
175
174
  }
175
+ get currentNormalModuleHooks() {
176
+ return NormalModule_1.NormalModule.getCompilationHooks(this);
177
+ }
176
178
  get hash() {
177
179
  return __classPrivateFieldGet(this, _Compilation_inner, "f").hash;
178
180
  }
@@ -195,10 +197,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
195
197
  ]));
196
198
  }
197
199
  get modules() {
198
- return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getModules().map(item => Module_1.Module.__from_binding(item, this))));
200
+ return (0, memoize_1.memoizeValue)(() => {
201
+ return this.__internal__getModules().map(item => Module_1.Module.__from_binding(item, this));
202
+ });
199
203
  }
204
+ // FIXME: Webpack returns a `Set`
200
205
  get chunks() {
201
- return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getChunks()));
206
+ return (0, memoize_1.memoizeValue)(() => {
207
+ return this.__internal__getChunks();
208
+ });
202
209
  }
203
210
  /**
204
211
  * Get the named chunks.
@@ -340,8 +347,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
340
347
  *
341
348
  * @internal
342
349
  */
343
- __internal__pushDiagnostic(diagnostic) {
344
- __classPrivateFieldGet(this, _Compilation_inner, "f").pushDiagnostic(diagnostic);
350
+ __internal__pushDiagnostic(severity, title, message) {
351
+ __classPrivateFieldGet(this, _Compilation_inner, "f").pushDiagnostic(severity, title, message);
345
352
  }
346
353
  /**
347
354
  * Note: This is not a webpack public API, maybe removed in future.
@@ -353,14 +360,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
353
360
  }
354
361
  get errors() {
355
362
  const inner = __classPrivateFieldGet(this, _Compilation_inner, "f");
356
- const errors = inner.getErrors();
363
+ const errors = inner.getStats().getErrors();
357
364
  const proxyMethod = [
358
365
  {
359
366
  method: "push",
360
367
  handler(target, thisArg, errs) {
361
368
  for (let i = 0; i < errs.length; i++) {
362
369
  const error = errs[i];
363
- inner.pushDiagnostic(RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error));
370
+ inner.pushDiagnostic("error", error instanceof Error ? error.name : "Error", (0, util_1.concatErrorMsgAndStack)(error));
364
371
  }
365
372
  return Reflect.apply(target, thisArg, errs);
366
373
  }
@@ -383,7 +390,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
383
390
  method: "unshift",
384
391
  handler(target, thisArg, errs) {
385
392
  const errList = errs.map(error => {
386
- return RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error);
393
+ return {
394
+ severity: "error",
395
+ title: error instanceof Error ? error.name : "Error",
396
+ message: (0, util_1.concatErrorMsgAndStack)(error)
397
+ };
387
398
  });
388
399
  inner.spliceDiagnostic(0, 0, errList);
389
400
  return Reflect.apply(target, thisArg, errs);
@@ -393,7 +404,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
393
404
  method: "splice",
394
405
  handler(target, thisArg, [startIdx, delCount, ...errors]) {
395
406
  const errList = errors.map(error => {
396
- return RspackError_1.JsDiagnostic.__to_binding(error, binding_1.JsRspackSeverity.Error);
407
+ return {
408
+ severity: "error",
409
+ title: error instanceof Error ? error.name : "Error",
410
+ message: (0, util_1.concatErrorMsgAndStack)(error)
411
+ };
397
412
  });
398
413
  inner.spliceDiagnostic(startIdx, startIdx + delCount, errList);
399
414
  return Reflect.apply(target, thisArg, [
@@ -415,7 +430,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
415
430
  get warnings() {
416
431
  const inner = __classPrivateFieldGet(this, _Compilation_inner, "f");
417
432
  const processWarningsHook = this.hooks.processWarnings;
418
- const warnings = inner.getWarnings();
433
+ const warnings = inner.getStats().getWarnings();
419
434
  const proxyMethod = [
420
435
  {
421
436
  method: "push",
@@ -423,7 +438,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
423
438
  warns = processWarningsHook.call(warns);
424
439
  for (let i = 0; i < warns.length; i++) {
425
440
  const warn = warns[i];
426
- inner.pushDiagnostic(RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn));
441
+ inner.pushDiagnostic("warning", warn instanceof Error ? warn.name : "Warning", (0, util_1.concatErrorMsgAndStack)(warn));
427
442
  }
428
443
  return Reflect.apply(target, thisArg, warns);
429
444
  }
@@ -447,7 +462,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
447
462
  handler(target, thisArg, warns) {
448
463
  warns = processWarningsHook.call(warns);
449
464
  const warnList = warns.map(warn => {
450
- return RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn);
465
+ return {
466
+ severity: "warning",
467
+ title: warn instanceof Error ? warn.name : "Warning",
468
+ message: (0, util_1.concatErrorMsgAndStack)(warn)
469
+ };
451
470
  });
452
471
  inner.spliceDiagnostic(0, 0, warnList);
453
472
  return Reflect.apply(target, thisArg, warns);
@@ -458,7 +477,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
458
477
  handler(target, thisArg, [startIdx, delCount, ...warns]) {
459
478
  warns = processWarningsHook.call(warns);
460
479
  const warnList = warns.map(warn => {
461
- return RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn);
480
+ return {
481
+ severity: "warning",
482
+ title: warn instanceof Error ? warn.name : "Warning",
483
+ message: (0, util_1.concatErrorMsgAndStack)(warn)
484
+ };
462
485
  });
463
486
  inner.spliceDiagnostic(startIdx, startIdx + delCount, warnList);
464
487
  return Reflect.apply(target, thisArg, [
@@ -596,7 +619,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
596
619
  return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
597
620
  }
598
621
  rebuildModule(m, f) {
599
- __classPrivateFieldGet(this, _Compilation_rebuildModuleCaller, "f").push([m.identifier(), f]);
622
+ this._rebuildModuleCaller.push([m.identifier(), f]);
600
623
  }
601
624
  /**
602
625
  * Get the `Source` of a given asset filename.
@@ -681,7 +704,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
681
704
  seal() { }
682
705
  unseal() { }
683
706
  }
684
- _Compilation_inner = new WeakMap(), _Compilation_cachedAssets = new WeakMap(), _Compilation_customModules = new WeakMap(), _Compilation_rebuildModuleCaller = new WeakMap(), _Compilation_instances = new WeakSet(), _Compilation_createCachedAssets = function _Compilation_createCachedAssets() {
707
+ _Compilation_inner = new WeakMap(), _Compilation_cachedAssets = new WeakMap(), _Compilation_customModules = new WeakMap(), _Compilation_instances = new WeakSet(), _Compilation_createCachedAssets = function _Compilation_createCachedAssets() {
685
708
  return new Proxy({}, {
686
709
  get: (_, property) => {
687
710
  if (typeof property === "string") {
package/dist/Compiler.js CHANGED
@@ -77,7 +77,6 @@ const Logger_1 = require("./logging/Logger");
77
77
  const util_1 = require("./util");
78
78
  const assertNotNil_1 = require("./util/assertNotNil");
79
79
  const bindingVersionCheck_1 = require("./util/bindingVersionCheck");
80
- const createHash_1 = require("./util/createHash");
81
80
  const identifier_1 = require("./util/identifier");
82
81
  class Compiler {
83
82
  constructor(context, options) {
@@ -652,18 +651,10 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
652
651
  __classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
653
652
  }),
654
653
  registerCompilationFinishModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationFinishModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.finishModules, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
655
- registerCompilationOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules.values())),
656
- registerCompilationAfterOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterOptimizeModules, queried => () => {
657
- queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules.values());
658
- }),
654
+ registerCompilationOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
655
+ registerCompilationAfterOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterOptimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
659
656
  registerCompilationOptimizeTreeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeTree, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeTree, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").chunks, __classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
660
657
  registerCompilationOptimizeChunkModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeChunkModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeChunkModules, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").chunks, __classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
661
- registerCompilationChunkHashTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkHash, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.chunkHash, queried => (chunk) => {
662
- const hash = (0, createHash_1.createHash)(this.options.output.hashFunction);
663
- queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), hash);
664
- const digestResult = hash.digest(this.options.output.hashDigest);
665
- return Buffer.from(digestResult);
666
- }),
667
658
  registerCompilationChunkAssetTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkAsset, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.chunkAsset, queried => ({ chunk, filename }) => queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), filename)),
668
659
  registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.processAssets, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
669
660
  registerCompilationAfterProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterProcessAssets, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
@@ -737,13 +728,6 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
737
728
  })
738
729
  : false;
739
730
  return result;
740
- }),
741
- registerJavascriptModulesChunkHashTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.JavascriptModulesChunkHash, () => builtin_plugin_1.JavascriptModulesPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
742
- .chunkHash, queried => (chunk) => {
743
- const hash = (0, createHash_1.createHash)(this.options.output.hashFunction);
744
- queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), hash);
745
- const digestResult = hash.digest(this.options.output.hashDigest);
746
- return Buffer.from(digestResult);
747
731
  })
748
732
  }, "f");
749
733
  __classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, __classPrivateFieldGet(this, _Compiler_builtinPlugins, "f"), __classPrivateFieldGet(this, _Compiler_registers, "f"), FileSystem_1.ThreadsafeWritableNodeFS.__to_binding(this.outputFileSystem)), "f");
@@ -4,5 +4,5 @@ import { ChunkGroup } from "./ChunkGroup";
4
4
  export declare class Entrypoint extends ChunkGroup {
5
5
  static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation): Entrypoint;
6
6
  protected constructor(inner: JsChunkGroup, compilation: JsCompilation);
7
- getRuntimeChunk(): Readonly<Chunk | null>;
7
+ getRuntimeChunk(): Chunk | null;
8
8
  }
@@ -12,9 +12,9 @@ class Entrypoint extends ChunkGroup_1.ChunkGroup {
12
12
  super(inner, compilation);
13
13
  }
14
14
  getRuntimeChunk() {
15
- const c = (0, binding_1.__entrypoint_inner_get_runtime_chunk)(this.__internal__innerUkey(), this.__internal__innerCompilation());
15
+ const c = (0, binding_1.__entrypoint_inner_get_runtime_chunk)(this.__internal_innerUkey(), this.__internal_innerCompilation());
16
16
  if (c)
17
- return Chunk_1.Chunk.__from_binding(c, this.__internal__innerCompilation());
17
+ return Chunk_1.Chunk.__from_binding(c, this.__internal_innerCompilation());
18
18
  return null;
19
19
  }
20
20
  }
package/dist/Module.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsFactoryMeta, JsModule } from "@rspack/binding";
1
+ import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsModule } from "@rspack/binding";
2
2
  import { Source } from "webpack-sources";
3
3
  import { Compilation } from "./Compilation";
4
4
  export type ResourceData = {
@@ -32,12 +32,11 @@ export type ContextModuleFactoryAfterResolveResult = false | {
32
32
  };
33
33
  export declare class Module {
34
34
  #private;
35
- context?: Readonly<string>;
36
- resource?: Readonly<string>;
37
- request?: Readonly<string>;
38
- userRequest?: Readonly<string>;
39
- rawRequest?: Readonly<string>;
40
- factoryMeta?: Readonly<JsFactoryMeta>;
35
+ context?: string;
36
+ resource?: string;
37
+ request?: string;
38
+ userRequest?: string;
39
+ rawRequest?: string;
41
40
  /**
42
41
  * Records the dynamically added fields for Module on the JavaScript side.
43
42
  * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.