@rspack/core 1.0.0-beta.1 → 1.0.0-beta.2

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 (88) hide show
  1. package/dist/ChunkGroup.d.ts +1 -0
  2. package/dist/ChunkGroup.js +3 -0
  3. package/dist/Compilation.d.ts +18 -0
  4. package/dist/Compiler.js +2 -2
  5. package/dist/ExecuteModulePlugin.d.ts +0 -1
  6. package/dist/ExecuteModulePlugin.js +0 -1
  7. package/dist/Module.d.ts +1 -2
  8. package/dist/Module.js +0 -1
  9. package/dist/MultiCompiler.js +1 -1
  10. package/dist/Resolver.d.ts +1 -2
  11. package/dist/RspackError.js +1 -1
  12. package/dist/Stats.js +22 -2
  13. package/dist/Template.js +2 -2
  14. package/dist/builtin-loader/lightningcss/index.js +1 -1
  15. package/dist/builtin-plugin/DefinePlugin.js +1 -1
  16. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
  17. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +1 -1
  18. package/dist/builtin-plugin/EnableLibraryPlugin.js +1 -6
  19. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +2 -2
  20. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +1 -1
  21. package/dist/builtin-plugin/ExternalsPlugin.js +1 -1
  22. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +0 -1
  23. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  24. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -2
  25. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +3 -5
  26. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +7 -5
  27. package/dist/builtin-plugin/css-extract/loader.js +4 -10
  28. package/dist/builtin-plugin/lazy-compilation/backend.js +4 -4
  29. package/dist/config/adapter.js +1 -0
  30. package/dist/config/adapterRuleUse.d.ts +2 -6
  31. package/dist/config/adapterRuleUse.js +7 -6
  32. package/dist/config/defaults.js +21 -32
  33. package/dist/config/normalization.d.ts +1 -0
  34. package/dist/config/normalization.js +5 -2
  35. package/dist/config/zod.d.ts +440 -68
  36. package/dist/config/zod.js +21 -1
  37. package/dist/container/default.runtime.js +1 -1
  38. package/dist/lib/AbstractMethodError.js +2 -3
  39. package/dist/lib/Cache.d.ts +1 -1
  40. package/dist/lib/Dependency.d.ts +23 -0
  41. package/dist/lib/Dependency.js +11 -0
  42. package/dist/lib/EnvironmentPlugin.js +1 -3
  43. package/dist/lib/ModuleFilenameHelpers.js +1 -1
  44. package/dist/lib/WebpackError.d.ts +0 -6
  45. package/dist/lib/WebpackError.js +0 -8
  46. package/dist/lib/cache/MemoryCachePlugin.d.ts +5 -0
  47. package/dist/lib/cache/MemoryCachePlugin.js +40 -0
  48. package/dist/lib/formatLocation.d.ts +1 -1
  49. package/dist/loader-runner/index.js +6 -7
  50. package/dist/loader-runner/loadLoader.js +8 -11
  51. package/dist/logging/Logger.js +3 -3
  52. package/dist/logging/createConsoleLogger.d.ts +26 -6
  53. package/dist/logging/createConsoleLogger.js +21 -58
  54. package/dist/logging/runtime.d.ts +4 -10
  55. package/dist/logging/runtime.js +8 -23
  56. package/dist/logging/truncateArgs.d.ts +4 -4
  57. package/dist/logging/truncateArgs.js +5 -10
  58. package/dist/node/NodeEnvironmentPlugin.js +2 -2
  59. package/dist/node/NodeWatchFileSystem.js +6 -6
  60. package/dist/node/nodeConsole.d.ts +7 -21
  61. package/dist/node/nodeConsole.js +29 -36
  62. package/dist/rspackOptionsApply.d.ts +0 -1
  63. package/dist/rspackOptionsApply.js +8 -7
  64. package/dist/sharing/ProvideSharedPlugin.d.ts +20 -19
  65. package/dist/sharing/ProvideSharedPlugin.js +26 -17
  66. package/dist/sharing/SharePlugin.d.ts +3 -0
  67. package/dist/sharing/SharePlugin.js +4 -1
  68. package/dist/stats/DefaultStatsFactoryPlugin.js +187 -96
  69. package/dist/stats/DefaultStatsPresetPlugin.js +1 -2
  70. package/dist/stats/DefaultStatsPrinterPlugin.js +18 -19
  71. package/dist/stats/StatsFactory.d.ts +2 -1
  72. package/dist/stats/StatsFactory.js +2 -6
  73. package/dist/stats/statsFactoryUtils.d.ts +63 -23
  74. package/dist/util/SizeFormatHelpers.js +1 -1
  75. package/dist/util/bindingVersionCheck.js +3 -3
  76. package/dist/util/cleverMerge.js +3 -2
  77. package/dist/util/comparators.d.ts +1 -1
  78. package/dist/util/comparators.js +5 -4
  79. package/dist/util/createHash.js +1 -1
  80. package/dist/util/fs.js +2 -2
  81. package/dist/util/identifier.js +2 -2
  82. package/dist/util/index.js +1 -1
  83. package/dist/util/memoize.js +1 -4
  84. package/dist/util/smartGrouping.js +4 -6
  85. package/dist/util/webpack.d.ts +1 -1
  86. package/dist/util/webpack.js +2 -1
  87. package/module.d.ts +1 -1
  88. package/package.json +3 -3
@@ -1,27 +1,58 @@
1
+ /// <reference types="node" />
1
2
  import type * as binding from "@rspack/binding";
2
3
  import type { Compilation, NormalizedStatsOptions } from "../Compilation";
3
4
  import { type Comparator } from "../util/comparators";
4
5
  import type { StatsFactory, StatsFactoryContext } from "./StatsFactory";
5
- type Writable<T> = {
6
- -readonly [K in keyof T]: T[K];
7
- };
8
6
  export type KnownStatsChunkGroup = binding.JsStatsChunkGroup;
9
- export type KnownStatsChunk = Omit<Writable<binding.JsStatsChunk>, "sizes"> & {
7
+ export type KnownStatsChunk = Omit<binding.JsStatsChunk, "sizes" | "origins"> & {
10
8
  sizes: Record<string, number>;
9
+ origins: StatsChunkOrigin[];
11
10
  };
12
11
  export type KnownStatsAssetInfo = Omit<binding.JsStatsAssetInfo, "related">;
13
12
  export type StatsChunkGroup = binding.JsStatsChunkGroup & Record<string, any>;
14
13
  export type KnownStatsAsset = Omit<binding.JsStatsAsset, "info">;
15
14
  export type StatsAsset = KnownStatsAsset & Record<string, any>;
16
15
  export type StatsChunk = KnownStatsChunk & Record<string, any>;
17
- export type KnownStatsModule = Omit<Writable<binding.JsStatsModule>, "usedExports" | "providedExports" | "optimizationBailout" | "sizes"> & {
18
- profile?: StatsProfile;
19
- usedExports?: null | string[] | boolean;
20
- providedExports?: null | string[];
21
- optimizationBailout?: null | string[];
22
- sizes: Record<string, number>;
16
+ export type KnownStatsModule = {
17
+ type: string;
18
+ moduleType: string;
19
+ layer?: string;
20
+ identifier?: string;
21
+ name?: string;
22
+ nameForCondition?: string;
23
23
  index?: number;
24
24
  index2?: number;
25
+ preOrderIndex?: number;
26
+ postOrderIndex?: number;
27
+ size: number;
28
+ sizes: Record<string, number>;
29
+ cacheable?: boolean;
30
+ built: boolean;
31
+ codeGenerated: boolean;
32
+ buildTimeExecuted: boolean;
33
+ cached: boolean;
34
+ optional?: boolean;
35
+ orphan?: boolean;
36
+ id?: string;
37
+ issuerId?: string;
38
+ chunks?: string[];
39
+ assets?: string[];
40
+ dependent?: boolean;
41
+ issuer?: string;
42
+ issuerName?: string;
43
+ issuerPath?: StatsModuleIssuer[];
44
+ failed?: boolean;
45
+ errors?: number;
46
+ warnings?: number;
47
+ profile?: StatsProfile;
48
+ reasons?: StatsModuleReason[];
49
+ usedExports?: boolean | string[] | null;
50
+ providedExports?: string[] | null;
51
+ optimizationBailout?: string[] | null;
52
+ depth?: number;
53
+ modules?: StatsModule[];
54
+ filteredModules?: number;
55
+ source?: string | Buffer;
25
56
  };
26
57
  export type StatsProfile = KnownStatsProfile & Record<string, any>;
27
58
  export type KnownStatsProfile = {
@@ -30,9 +61,15 @@ export type KnownStatsProfile = {
30
61
  building: number;
31
62
  };
32
63
  export type StatsModule = KnownStatsModule & Record<string, any>;
33
- export type StatsModuleIssuer = binding.JsStatsModuleIssuer & Record<string, any>;
34
- export type StatsError = binding.JsStatsError & Record<string, any>;
35
- export type StatsWarnings = binding.JsStatsWarning & Record<string, any>;
64
+ export type StatsModuleIssuer = Omit<binding.JsStatsModuleIssuer, "identifier"> & {
65
+ identifier?: string;
66
+ } & Record<string, any>;
67
+ export type StatsError = Omit<binding.JsStatsError, "moduleIdentifier"> & {
68
+ moduleIdentifier?: string;
69
+ } & Record<string, any>;
70
+ export type StatsWarnings = Omit<binding.JsStatsWarning, "moduleIdentifier"> & {
71
+ moduleIdentifier?: string;
72
+ } & Record<string, any>;
36
73
  export type StatsModuleTraceItem = {
37
74
  originIdentifier?: string;
38
75
  originName?: string;
@@ -41,7 +78,18 @@ export type StatsModuleTraceItem = {
41
78
  originId?: string;
42
79
  moduleId?: string;
43
80
  };
44
- export type StatsModuleReason = Writable<binding.JsStatsModuleReason> & Record<string, any>;
81
+ export type StatsModuleReason = Omit<binding.JsStatsModuleReason, "moduleIdentifier"> & {
82
+ moduleIdentifier?: string;
83
+ } & Record<string, any>;
84
+ export type KnownStatsChunkOrigin = {
85
+ module: string;
86
+ moduleIdentifier: string;
87
+ moduleName: string;
88
+ loc: string;
89
+ request: string;
90
+ moduleId?: string;
91
+ };
92
+ export type StatsChunkOrigin = KnownStatsChunkOrigin & Record<string, any>;
45
93
  export type KnownStatsCompilation = {
46
94
  /**
47
95
  * webpack version.
@@ -86,14 +134,6 @@ export type KnownStatsLoggingEntry = {
86
134
  args?: any[] | undefined;
87
135
  time?: number | undefined;
88
136
  };
89
- export type KnownStatsChunkOrigin = {
90
- module?: string | undefined;
91
- moduleIdentifier?: string | undefined;
92
- moduleName?: string | undefined;
93
- loc?: string | undefined;
94
- request?: string | undefined;
95
- moduleId?: (string | number) | undefined;
96
- };
97
137
  type ExtractorsByOption<T, O> = {
98
138
  [x: string]: (object: O, data: T, context: StatsFactoryContext, options: any, factory: StatsFactory) => void;
99
139
  };
@@ -117,7 +157,7 @@ export type SimpleExtractors = {
117
157
  moduleReason: ExtractorsByOption<binding.JsStatsModuleReason, StatsModuleReason>;
118
158
  chunk: ExtractorsByOption<binding.JsStatsChunk, KnownStatsChunk>;
119
159
  error: ExtractorsByOption<binding.JsStatsError, StatsError>;
120
- warning: ExtractorsByOption<binding.JsStatsWarning, StatsError>;
160
+ warning: ExtractorsByOption<binding.JsStatsWarning, StatsWarnings>;
121
161
  moduleTraceItem: ExtractorsByOption<binding.JsStatsModuleTrace, StatsModuleTraceItem>;
122
162
  };
123
163
  export declare const uniqueArray: <T, I>(items: Iterable<T>, selector: (arg: T) => Iterable<I>) => I[];
@@ -19,6 +19,6 @@ const formatSize = (size) => {
19
19
  }
20
20
  const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
21
21
  const index = Math.floor(Math.log(size) / Math.log(1024));
22
- return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${abbreviations[index]}`;
22
+ return `${+(size / 1024 ** index).toPrecision(3)} ${abbreviations[index]}`;
23
23
  };
24
24
  exports.formatSize = formatSize;
@@ -64,12 +64,12 @@ const getAddonPlatformArchAbi = () => {
64
64
  const abi = NodePlatformArchToAbi[platform][arch];
65
65
  if (abi === undefined)
66
66
  return new Error(`unsupported cpu arch: ${arch}`);
67
- binding += "-" + arch;
67
+ binding += `-${arch}`;
68
68
  if (typeof abi === "string") {
69
- binding += abi.length ? "-" + abi : "";
69
+ binding += abi.length ? `-${abi}` : "";
70
70
  }
71
71
  else if (typeof abi === "object") {
72
- binding += "-" + abi[isMusl() ? "musl" : "gnu"];
72
+ binding += `-${abi[isMusl() ? "musl" : "gnu"]}`;
73
73
  }
74
74
  else {
75
75
  return new Error(`unsupported abi: ${abi}`);
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveByProperty = exports.removeOperations = exports.cleverMerge = exports.cachedSetProperty = exports.cachedCleverMerge = exports.DELETE = void 0;
4
+ const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
4
5
  const mergeCache = new WeakMap();
5
6
  const setPropertyCache = new WeakMap();
6
7
  exports.DELETE = Symbol("DELETE");
7
- const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
8
8
  /**
9
9
  * Merges two given objects and caches the result to avoid computation if same objects passed as arguments again.
10
10
  * @example
@@ -299,7 +299,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
299
299
  // second value override everything
300
300
  // = second.base + second.byProperty
301
301
  return secondEntry;
302
- case VALUE_TYPE_UNDEFINED:
302
+ case VALUE_TYPE_UNDEFINED: {
303
303
  if (!firstEntry.byProperty) {
304
304
  // = first.base + second.byProperty
305
305
  return {
@@ -323,6 +323,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
323
323
  byProperty: firstEntry.byProperty,
324
324
  byValues: newByValues
325
325
  };
326
+ }
326
327
  default: {
327
328
  if (!firstEntry.byProperty) {
328
329
  // The simple case
@@ -11,7 +11,7 @@ import type { JsStatsChunk as Chunk } from "@rspack/binding";
11
11
  import type { ChunkGroup } from "../ChunkGroup";
12
12
  export type Comparator = <T>(arg0: T, arg1: T) => -1 | 0 | 1;
13
13
  type Selector<A, B> = (input: A) => B;
14
- export declare const concatComparators: (c1: Comparator, c2: Comparator, ...cRest: Comparator[]) => Comparator;
14
+ export declare const concatComparators: (...comps: Array<Comparator>) => Comparator;
15
15
  export declare const compareIds: (a: string | number, b: string | number) => -1 | 0 | 1;
16
16
  export declare const compareChunksById: (a: Chunk, b: Chunk) => -1 | 0 | 1;
17
17
  export declare const compareChunkGroupsByIndex: (a: ChunkGroup, b: ChunkGroup) => -1 | 0 | 1;
@@ -31,14 +31,15 @@ class TwoKeyWeakMap {
31
31
  }
32
32
  }
33
33
  const concatComparatorsCache = new TwoKeyWeakMap();
34
- const concatComparators = (c1, c2, ...cRest) => {
34
+ const concatComparators = (...comps) => {
35
+ const [c1, c2, ...cRest] = comps;
36
+ if (c2 === undefined) {
37
+ return c1;
38
+ }
35
39
  if (cRest.length > 0) {
36
40
  const [c3, ...cRest2] = cRest;
37
41
  return (0, exports.concatComparators)(c1, (0, exports.concatComparators)(c2, c3, ...cRest2));
38
42
  }
39
- if (c2 === undefined) {
40
- return c1;
41
- }
42
43
  const cacheEntry = concatComparatorsCache.get(c1, c2);
43
44
  if (cacheEntry !== undefined)
44
45
  return cacheEntry;
@@ -127,7 +127,7 @@ class DebugHash extends hash_1.default {
127
127
  * @returns digest
128
128
  */
129
129
  digest(encoding) {
130
- return ("debug-digest-" + Buffer.from(this.string).toString(encoding || "hex"));
130
+ return `debug-digest-${Buffer.from(this.string).toString(encoding || "hex")}`;
131
131
  }
132
132
  }
133
133
  /**
package/dist/util/fs.js CHANGED
@@ -56,7 +56,7 @@ function rmrf(fs, p, callback) {
56
56
  }
57
57
  exports.rmrf = rmrf;
58
58
  const join = (fs, rootPath, filename) => {
59
- if (fs && fs.join) {
59
+ if (fs?.join) {
60
60
  return fs.join(rootPath, filename);
61
61
  }
62
62
  if (node_path_1.default.posix.isAbsolute(rootPath)) {
@@ -68,7 +68,7 @@ const join = (fs, rootPath, filename) => {
68
68
  throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
69
69
  };
70
70
  const dirname = (fs, absPath) => {
71
- if (fs && fs.dirname) {
71
+ if (fs?.dirname) {
72
72
  return fs.dirname(absPath);
73
73
  }
74
74
  if (node_path_1.default.posix.isAbsolute(absPath)) {
@@ -312,8 +312,8 @@ const getUndoPath = (filename, outputPath, enforceRelative) => {
312
312
  const j = outputPath.lastIndexOf("\\");
313
313
  const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
314
314
  if (pos < 0)
315
- return outputPath + "/";
316
- append = outputPath.slice(pos + 1) + "/" + append;
315
+ return `${outputPath}/`;
316
+ append = `${outputPath.slice(pos + 1)}/${append}`;
317
317
  outputPath = outputPath.slice(0, pos);
318
318
  }
319
319
  }
@@ -73,7 +73,7 @@ function concatErrorMsgAndStack(err) {
73
73
  }
74
74
  exports.concatErrorMsgAndStack = concatErrorMsgAndStack;
75
75
  function indent(str, prefix) {
76
- const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
76
+ const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
77
77
  return prefix + rem;
78
78
  }
79
79
  exports.indent = indent;
@@ -3,18 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.memoizeValue = exports.memoizeFn = exports.memoize = void 0;
4
4
  const memoize = (fn) => {
5
5
  let cache = false;
6
- // @ts-expect-error
7
- let result = undefined;
6
+ let result;
8
7
  return () => {
9
8
  if (cache) {
10
- // @ts-expect-error
11
9
  return result;
12
10
  }
13
11
  result = fn();
14
12
  cache = true;
15
13
  // Allow to clean up memory for fn
16
14
  // and all dependent resources
17
- // @ts-expect-error
18
15
  fn = undefined;
19
16
  return result;
20
17
  };
@@ -78,13 +78,11 @@ const smartGrouping = (items, groupConfigs) => {
78
78
  if (options === undefined) {
79
79
  const groupConfig = group.config;
80
80
  state.options = options =
81
- (groupConfig.getOptions &&
82
- groupConfig.getOptions(group.name, Array.from(items, ({ item }) => item))) ||
83
- false;
81
+ groupConfig.getOptions?.(group.name, Array.from(items, ({ item }) => item)) || false;
84
82
  }
85
- const force = options && options.force;
83
+ const force = options !== false && options.force;
86
84
  if (!force) {
87
- if (bestGroupOptions && bestGroupOptions.force)
85
+ if (bestGroupOptions !== false && bestGroupOptions?.force)
88
86
  continue;
89
87
  if (used)
90
88
  continue;
@@ -92,7 +90,7 @@ const smartGrouping = (items, groupConfigs) => {
92
90
  continue;
93
91
  }
94
92
  }
95
- const targetGroupCount = (options && options.targetGroupCount) || 4;
93
+ const targetGroupCount = (options !== false && options.targetGroupCount) || 4;
96
94
  const sizeValue = force
97
95
  ? items.size
98
96
  : Math.min(items.size, (totalSize * 2) / targetGroupCount +
@@ -1,4 +1,4 @@
1
1
  declare const _default: {
2
- readonly createHash: any;
2
+ readonly createHash: (algorithm: (string & {}) | "debug" | "xxhash64" | "md4" | "native-md4" | (new () => import("./hash").default)) => import("./hash").default;
3
3
  };
4
4
  export default _default;
@@ -4,9 +4,10 @@
4
4
  // const { NormalModuleReplacementPlugin, WebpackError, util } = compiler.webpack;
5
5
  // ```
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const createHash_1 = require("./createHash");
7
8
  exports.default = {
8
9
  get createHash() {
9
- return require("./createHash");
10
+ return createHash_1.createHash;
10
11
  }
11
12
  // get comparators() {
12
13
  // return require("./comparators");
package/module.d.ts CHANGED
@@ -109,7 +109,7 @@ declare namespace Rspack {
109
109
  onErrored?: (event: ErroredEvent) => void;
110
110
  }
111
111
 
112
- const enum HotUpdateStatus {
112
+ enum HotUpdateStatus {
113
113
  idle = "idle",
114
114
  check = "check",
115
115
  prepare = "prepare",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "The fast Rust-based web bundler with webpack-compatible API",
@@ -59,8 +59,8 @@
59
59
  "dependencies": {
60
60
  "@module-federation/runtime-tools": "0.2.3",
61
61
  "caniuse-lite": "^1.0.30001616",
62
- "@rspack/lite-tapable": "1.0.0-beta.1",
63
- "@rspack/binding": "1.0.0-beta.1"
62
+ "@rspack/lite-tapable": "1.0.0-beta.2",
63
+ "@rspack/binding": "1.0.0-beta.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@swc/helpers": ">=0.5.1"