@rspack/core 1.0.0-beta.3 → 1.0.0-beta.4

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.
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
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, type JsCompilation, type JsPathData, type JsRuntimeModule } from "@rspack/binding";
12
12
  import * as liteTapable from "@rspack/lite-tapable";
13
13
  import type { Source } from "../compiled/webpack-sources";
14
14
  import { Chunk } from "./Chunk";
@@ -338,12 +338,6 @@ export declare class Compilation {
338
338
  * @internal
339
339
  */
340
340
  __internal__hasAsset(name: string): boolean;
341
- /**
342
- * Note: This is not a webpack public API, maybe removed in future.
343
- *
344
- * @internal
345
- */
346
- __internal__getModules(): JsModule[];
347
341
  /**
348
342
  * Note: This is not a webpack public API, maybe removed in future.
349
343
  *
@@ -72,10 +72,10 @@ class Compilation {
72
72
  * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
73
73
  */
74
74
  _Compilation_customModules.set(this, void 0);
75
- this.fileDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getFileDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addFileDependencies(d));
76
- this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getContextDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
77
- this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getMissingDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
78
- this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getBuildDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
75
+ this.fileDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().fileDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addFileDependencies(d));
76
+ this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().contextDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
77
+ this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().missingDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
78
+ this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().buildDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
79
79
  _Compilation_rebuildModuleCaller.set(this, ((compilation) => new MergeCaller_1.default((args) => {
80
80
  __classPrivateFieldGet(compilation, _Compilation_inner, "f").rebuildModule(args.map(item => item[0]), (err, modules) => {
81
81
  for (const [id, callback] of args) {
@@ -216,7 +216,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
216
216
  };
217
217
  }
218
218
  get modules() {
219
- return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getModules().map(item => Module_1.Module.__from_binding(item, this))));
219
+ return new Set(__classPrivateFieldGet(this, _Compilation_inner, "f").modules.map(module => Module_1.Module.__from_binding(module, this)));
220
220
  }
221
221
  get chunks() {
222
222
  return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getChunks()));
@@ -679,14 +679,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
679
679
  __internal__hasAsset(name) {
680
680
  return __classPrivateFieldGet(this, _Compilation_inner, "f").hasAsset(name);
681
681
  }
682
- /**
683
- * Note: This is not a webpack public API, maybe removed in future.
684
- *
685
- * @internal
686
- */
687
- __internal__getModules() {
688
- return __classPrivateFieldGet(this, _Compilation_inner, "f").getModules();
689
- }
690
682
  /**
691
683
  * Note: This is not a webpack public API, maybe removed in future.
692
684
  *
@@ -0,0 +1,8 @@
1
+ import type { DependenciesBlockDTO } from "@rspack/binding";
2
+ import { Dependency } from "./Dependency";
3
+ export declare class DependenciesBlock {
4
+ #private;
5
+ constructor(binding: DependenciesBlockDTO);
6
+ get dependencies(): Dependency[];
7
+ get blocks(): DependenciesBlock[];
8
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _DependenciesBlock_binding;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DependenciesBlock = void 0;
16
+ const Dependency_1 = require("./Dependency");
17
+ class DependenciesBlock {
18
+ constructor(binding) {
19
+ _DependenciesBlock_binding.set(this, void 0);
20
+ __classPrivateFieldSet(this, _DependenciesBlock_binding, binding, "f");
21
+ }
22
+ get dependencies() {
23
+ return __classPrivateFieldGet(this, _DependenciesBlock_binding, "f").dependencies.map(d => new Dependency_1.Dependency(d));
24
+ }
25
+ get blocks() {
26
+ return __classPrivateFieldGet(this, _DependenciesBlock_binding, "f").blocks.map(b => new DependenciesBlock(b));
27
+ }
28
+ }
29
+ exports.DependenciesBlock = DependenciesBlock;
30
+ _DependenciesBlock_binding = new WeakMap();
@@ -0,0 +1,8 @@
1
+ import type { DependencyDTO } from "@rspack/binding";
2
+ export declare class Dependency {
3
+ #private;
4
+ constructor(binding: DependencyDTO);
5
+ get type(): string;
6
+ get category(): string;
7
+ get request(): string | undefined;
8
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Dependency_binding;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Dependency = void 0;
16
+ class Dependency {
17
+ constructor(binding) {
18
+ _Dependency_binding.set(this, void 0);
19
+ __classPrivateFieldSet(this, _Dependency_binding, binding, "f");
20
+ }
21
+ get type() {
22
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").type;
23
+ }
24
+ get category() {
25
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").category;
26
+ }
27
+ get request() {
28
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").request;
29
+ }
30
+ }
31
+ exports.Dependency = Dependency;
32
+ _Dependency_binding = new WeakMap();
package/dist/Module.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { JsCodegenerationResult, JsCreateData, JsFactoryMeta, JsModule } from "@rspack/binding";
1
+ import type { JsCodegenerationResult, JsCreateData, JsFactoryMeta, JsModule, ModuleDTO } from "@rspack/binding";
2
2
  import type { Source } from "../compiled/webpack-sources";
3
3
  import type { Compilation } from "./Compilation";
4
+ import { DependenciesBlock } from "./DependenciesBlock";
4
5
  export type ResourceData = {
5
6
  resource: string;
6
7
  path: string;
@@ -56,11 +57,13 @@ export declare class Module {
56
57
  * @see {@link Compilation#customModules}
57
58
  */
58
59
  buildMeta: Record<string, any>;
59
- static __from_binding(module: JsModule, compilation?: Compilation): Module;
60
- constructor(module: JsModule, compilation?: Compilation);
60
+ static __from_binding(module: JsModule | ModuleDTO, compilation?: Compilation): Module;
61
+ constructor(module: JsModule | ModuleDTO, compilation?: Compilation);
61
62
  originalSource(): Source | null;
62
63
  identifier(): string;
63
64
  nameForCondition(): string | null;
65
+ get blocks(): DependenciesBlock[];
66
+ size(type?: string): number;
64
67
  }
65
68
  export declare class CodeGenerationResult {
66
69
  #private;
package/dist/Module.js CHANGED
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _Module_inner, _Module_originalSource, _CodeGenerationResult_inner;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CodeGenerationResults = exports.CodeGenerationResult = exports.Module = void 0;
16
+ const DependenciesBlock_1 = require("./DependenciesBlock");
16
17
  const source_1 = require("./util/source");
17
18
  class Module {
18
19
  static __from_binding(module, compilation) {
@@ -52,6 +53,18 @@ class Module {
52
53
  }
53
54
  return null;
54
55
  }
56
+ get blocks() {
57
+ if ("blocks" in __classPrivateFieldGet(this, _Module_inner, "f")) {
58
+ return __classPrivateFieldGet(this, _Module_inner, "f").blocks.map(b => new DependenciesBlock_1.DependenciesBlock(b));
59
+ }
60
+ return [];
61
+ }
62
+ size(type) {
63
+ if ("size" in __classPrivateFieldGet(this, _Module_inner, "f")) {
64
+ return __classPrivateFieldGet(this, _Module_inner, "f").size(type);
65
+ }
66
+ return 0;
67
+ }
55
68
  }
56
69
  exports.Module = Module;
57
70
  _Module_inner = new WeakMap(), _Module_originalSource = new WeakMap();
@@ -7,7 +7,7 @@ export declare const ExternalsPlugin: {
7
7
  contextInfo?: {
8
8
  issuer: string;
9
9
  } | undefined;
10
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
10
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "module-import" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
11
11
  context?: string | undefined;
12
12
  dependencyType?: string | undefined;
13
13
  request?: string | undefined;
@@ -21,7 +21,7 @@ export declare const ExternalsPlugin: {
21
21
  contextInfo?: {
22
22
  issuer: string;
23
23
  } | undefined;
24
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
24
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "module-import" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
25
25
  context?: string | undefined;
26
26
  dependencyType?: string | undefined;
27
27
  request?: string | undefined;
@@ -37,7 +37,7 @@ export declare const ExternalsPlugin: {
37
37
  contextInfo?: {
38
38
  issuer: string;
39
39
  } | undefined;
40
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
40
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "module-import" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
41
41
  context?: string | undefined;
42
42
  dependencyType?: string | undefined;
43
43
  request?: string | undefined;
@@ -51,7 +51,7 @@ export declare const ExternalsPlugin: {
51
51
  contextInfo?: {
52
52
  issuer: string;
53
53
  } | undefined;
54
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
54
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "module-import" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
55
55
  context?: string | undefined;
56
56
  dependencyType?: string | undefined;
57
57
  request?: string | undefined;
@@ -36,12 +36,10 @@ function getCurrentScriptUrl(moduleId) {
36
36
  if (!src) {
37
37
  return null;
38
38
  }
39
- const splitResult = src.split(/([^\\/]+)\.js$/);
40
- const filename = splitResult?.[1];
41
- if (!filename) {
42
- return [src.replace(".js", ".css")];
43
- }
44
- if (!fileMap) {
39
+ const splitResult = src.match(/([^\\/]+)\.js$/);
40
+ // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
41
+ const filename = splitResult && splitResult[1];
42
+ if (!filename || !fileMap) {
45
43
  return [src.replace(".js", ".css")];
46
44
  }
47
45
  return fileMap.split(",").map(mapRule => {
@@ -80,21 +78,29 @@ function updateCss(el, url) {
80
78
  return;
81
79
  }
82
80
  newEl.isLoaded = true;
83
- el.parentNode?.removeChild(el);
81
+ if (el.parentNode) {
82
+ el.parentNode.removeChild(el);
83
+ }
84
84
  });
85
85
  newEl.addEventListener("error", () => {
86
86
  if (newEl.isLoaded) {
87
87
  return;
88
88
  }
89
89
  newEl.isLoaded = true;
90
- el.parentNode?.removeChild(el);
90
+ if (el.parentNode) {
91
+ el.parentNode.removeChild(el);
92
+ }
91
93
  });
92
94
  newEl.href = `${normalizedUrl}?${Date.now()}`;
95
+ const parent = el.parentNode;
96
+ if (!parent) {
97
+ return;
98
+ }
93
99
  if (el.nextSibling) {
94
- el.parentNode?.insertBefore(newEl, el.nextSibling);
100
+ parent.insertBefore(newEl, el.nextSibling);
95
101
  }
96
102
  else {
97
- el.parentNode?.appendChild(newEl);
103
+ parent.appendChild(newEl);
98
104
  }
99
105
  }
100
106
  function getReloadUrl(href, src) {
@@ -163,7 +169,8 @@ function cssReload(moduleId, options) {
163
169
  return;
164
170
  }
165
171
  if (reloaded) {
166
- console.log("[HMR] css reload %s", src?.join(" "));
172
+ // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
173
+ console.log("[HMR] css reload %s", src && src.join(" "));
167
174
  }
168
175
  else {
169
176
  console.log("[HMR] Reload all css");
@@ -77,10 +77,13 @@ const applyRspackOptionsDefaults = (options) => {
77
77
  return options.output.library
78
78
  ? options.output.library.type
79
79
  : options.output.module
80
- ? "module"
80
+ ? "module-import"
81
81
  : "var";
82
82
  });
83
- applyNodeDefaults(options.node, { targetProperties });
83
+ applyNodeDefaults(options.node, {
84
+ targetProperties,
85
+ outputModule: options.output.module
86
+ });
84
87
  applyLoaderDefaults(options.loader, {
85
88
  targetProperties,
86
89
  environment: options.output.environment
@@ -633,7 +636,7 @@ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
633
636
  });
634
637
  D(loader, "environment", environment);
635
638
  };
636
- const applyNodeDefaults = (node, { targetProperties }) => {
639
+ const applyNodeDefaults = (node, { outputModule, targetProperties }) => {
637
640
  if (node === false)
638
641
  return;
639
642
  // IGNORE(node.global): The default value of `global` is determined by `futureDefaults` in webpack.
@@ -645,13 +648,13 @@ const applyNodeDefaults = (node, { targetProperties }) => {
645
648
  // IGNORE(node.__dirname): The default value of `__dirname` is determined by `futureDefaults` in webpack.
646
649
  F(node, "__dirname", () => {
647
650
  if (targetProperties?.node)
648
- return "eval-only";
651
+ return outputModule ? "node-module" : "eval-only";
649
652
  return "warn-mock";
650
653
  });
651
654
  // IGNORE(node.__filename): The default value of `__filename` is determined by `futureDefaults` in webpack.
652
655
  F(node, "__filename", () => {
653
656
  if (targetProperties?.node)
654
- return "eval-only";
657
+ return outputModule ? "node-module" : "eval-only";
655
658
  return "warn-mock";
656
659
  });
657
660
  };
@@ -707,7 +710,7 @@ const applyOptimizationDefaults = (optimization, { production, development, css
707
710
  A(splitChunks, "defaultSizeTypes", () => css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]);
708
711
  D(splitChunks, "hidePathInfo", production);
709
712
  D(splitChunks, "chunks", "async");
710
- // D(splitChunks, "usedExports", optimization.usedExports === true);
713
+ D(splitChunks, "usedExports", optimization.usedExports === true);
711
714
  D(splitChunks, "minChunks", 1);
712
715
  F(splitChunks, "minSize", () => (production ? 20000 : 10000));
713
716
  // F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined));