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

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 (121) hide show
  1. package/dist/ChunkGroup.d.ts +1 -0
  2. package/dist/ChunkGroup.js +3 -0
  3. package/dist/Compilation.d.ts +38 -1
  4. package/dist/Compilation.js +109 -44
  5. package/dist/Compiler.d.ts +1 -0
  6. package/dist/Compiler.js +31 -26
  7. package/dist/ExecuteModulePlugin.d.ts +0 -1
  8. package/dist/ExecuteModulePlugin.js +0 -1
  9. package/dist/Module.d.ts +1 -2
  10. package/dist/Module.js +0 -1
  11. package/dist/MultiCompiler.js +11 -7
  12. package/dist/MultiStats.d.ts +1 -1
  13. package/dist/MultiStats.js +19 -16
  14. package/dist/NormalModule.js +3 -4
  15. package/dist/Resolver.d.ts +1 -2
  16. package/dist/RspackError.js +1 -1
  17. package/dist/Stats.d.ts +1 -1
  18. package/dist/Stats.js +22 -2
  19. package/dist/Template.d.ts +4 -4
  20. package/dist/Template.js +8 -6
  21. package/dist/Watching.js +3 -5
  22. package/dist/builtin-loader/lightningcss/index.js +1 -1
  23. package/dist/builtin-plugin/DefinePlugin.js +1 -1
  24. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  25. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  26. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
  27. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +1 -1
  28. package/dist/builtin-plugin/EnableLibraryPlugin.js +1 -6
  29. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +2 -2
  30. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +1 -1
  31. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  32. package/dist/builtin-plugin/ExternalsPlugin.js +1 -1
  33. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +0 -1
  34. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  35. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  36. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  37. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  38. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +17 -12
  39. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  40. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +13 -11
  41. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  42. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +9 -7
  43. package/dist/builtin-plugin/css-extract/loader.js +5 -12
  44. package/dist/builtin-plugin/lazy-compilation/backend.js +4 -4
  45. package/dist/config/adapter.d.ts +2 -2
  46. package/dist/config/adapter.js +1 -0
  47. package/dist/config/adapterRuleUse.d.ts +2 -6
  48. package/dist/config/adapterRuleUse.js +7 -6
  49. package/dist/config/defaults.js +21 -32
  50. package/dist/config/normalization.d.ts +1 -0
  51. package/dist/config/normalization.js +5 -2
  52. package/dist/config/zod.d.ts +762 -114
  53. package/dist/config/zod.js +29 -6
  54. package/dist/container/default.runtime.js +1 -1
  55. package/dist/exports.d.ts +4 -3
  56. package/dist/exports.js +5 -2
  57. package/dist/lib/AbstractMethodError.js +2 -3
  58. package/dist/lib/Cache.d.ts +1 -1
  59. package/dist/lib/Cache.js +6 -4
  60. package/dist/lib/CacheFacade.js +8 -9
  61. package/dist/lib/Dependency.d.ts +23 -0
  62. package/dist/lib/Dependency.js +11 -0
  63. package/dist/lib/EnvironmentPlugin.js +1 -3
  64. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  65. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  66. package/dist/lib/ModuleFilenameHelpers.js +1 -1
  67. package/dist/lib/WebpackError.d.ts +0 -6
  68. package/dist/lib/WebpackError.js +0 -8
  69. package/dist/lib/cache/MemoryCachePlugin.d.ts +5 -0
  70. package/dist/lib/cache/MemoryCachePlugin.js +40 -0
  71. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  72. package/dist/lib/cache/mergeEtags.js +5 -3
  73. package/dist/lib/formatLocation.d.ts +1 -1
  74. package/dist/loader-runner/index.js +10 -9
  75. package/dist/loader-runner/loadLoader.js +8 -11
  76. package/dist/logging/Logger.js +3 -3
  77. package/dist/logging/createConsoleLogger.d.ts +26 -6
  78. package/dist/logging/createConsoleLogger.js +21 -58
  79. package/dist/logging/runtime.d.ts +4 -10
  80. package/dist/logging/runtime.js +8 -23
  81. package/dist/logging/truncateArgs.d.ts +4 -4
  82. package/dist/logging/truncateArgs.js +5 -10
  83. package/dist/node/NodeEnvironmentPlugin.js +2 -2
  84. package/dist/node/NodeWatchFileSystem.js +6 -6
  85. package/dist/node/nodeConsole.d.ts +7 -21
  86. package/dist/node/nodeConsole.js +31 -38
  87. package/dist/rspackOptionsApply.d.ts +0 -1
  88. package/dist/rspackOptionsApply.js +8 -7
  89. package/dist/sharing/ProvideSharedPlugin.d.ts +20 -19
  90. package/dist/sharing/ProvideSharedPlugin.js +26 -17
  91. package/dist/sharing/SharePlugin.d.ts +3 -0
  92. package/dist/sharing/SharePlugin.js +4 -1
  93. package/dist/stats/DefaultStatsFactoryPlugin.js +187 -96
  94. package/dist/stats/DefaultStatsPresetPlugin.js +2 -5
  95. package/dist/stats/DefaultStatsPrinterPlugin.js +18 -19
  96. package/dist/stats/StatsFactory.d.ts +2 -1
  97. package/dist/stats/StatsFactory.js +5 -10
  98. package/dist/stats/StatsPrinter.js +3 -4
  99. package/dist/stats/statsFactoryUtils.d.ts +155 -28
  100. package/dist/util/SizeFormatHelpers.js +1 -1
  101. package/dist/util/assertNotNil.d.ts +1 -1
  102. package/dist/util/assetCondition.d.ts +2 -0
  103. package/dist/util/assetCondition.js +2 -0
  104. package/dist/util/bindingVersionCheck.js +3 -3
  105. package/dist/util/cleverMerge.js +8 -6
  106. package/dist/util/comparators.d.ts +1 -1
  107. package/dist/util/comparators.js +5 -4
  108. package/dist/util/createHash.js +11 -6
  109. package/dist/util/fs.js +2 -2
  110. package/dist/util/hash/wasm-hash.js +5 -4
  111. package/dist/util/identifier.d.ts +4 -4
  112. package/dist/util/identifier.js +10 -10
  113. package/dist/util/index.js +1 -1
  114. package/dist/util/memoize.js +4 -6
  115. package/dist/util/smartGrouping.js +4 -6
  116. package/dist/util/webpack.d.ts +1 -1
  117. package/dist/util/webpack.js +2 -1
  118. package/module.d.ts +1 -1
  119. package/package.json +3 -3
  120. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  121. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
@@ -56,21 +56,23 @@ class MultiStats {
56
56
  return this.stats.some(stat => stat.hasWarnings());
57
57
  }
58
58
  toJson(options) {
59
- options = __classPrivateFieldGet(this, _MultiStats_instances, "m", _MultiStats_createChildOptions).call(this, options, { forToString: false });
59
+ const childOptions = __classPrivateFieldGet(this, _MultiStats_instances, "m", _MultiStats_createChildOptions).call(this, options || {}, {
60
+ forToString: false
61
+ });
60
62
  const obj = {};
61
63
  obj.children = this.stats.map((stat, idx) => {
62
- const obj = stat.toJson(options.children[idx]);
64
+ const obj = stat.toJson(childOptions.children[idx]);
63
65
  const compilationName = stat.compilation.name;
64
66
  const name = compilationName &&
65
- identifierUtils.makePathsRelative(options.context, compilationName, stat.compilation.compiler.root);
67
+ identifierUtils.makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root);
66
68
  obj.name = name;
67
69
  return obj;
68
70
  });
69
- if (options.version) {
71
+ if (childOptions.version) {
70
72
  obj.rspackVersion = require("../package.json").version;
71
73
  obj.version = require("../package.json").webpackVersion;
72
74
  }
73
- if (options.hash) {
75
+ if (childOptions.hash) {
74
76
  obj.hash = obj.children.map(j => j.hash).join("");
75
77
  }
76
78
  const mapError = (j, obj) => {
@@ -81,7 +83,7 @@ class MultiStats {
81
83
  : j.name
82
84
  };
83
85
  };
84
- if (options.errors) {
86
+ if (childOptions.errors) {
85
87
  obj.errors = [];
86
88
  for (const j of obj.children) {
87
89
  for (const i of j.errors || []) {
@@ -89,7 +91,7 @@ class MultiStats {
89
91
  }
90
92
  }
91
93
  }
92
- if (options.warnings) {
94
+ if (childOptions.warnings) {
93
95
  obj.warnings = [];
94
96
  for (const j of obj.children) {
95
97
  for (const i of j.warnings || []) {
@@ -97,13 +99,13 @@ class MultiStats {
97
99
  }
98
100
  }
99
101
  }
100
- if (options.errorsCount) {
102
+ if (childOptions.errorsCount) {
101
103
  obj.errorsCount = 0;
102
104
  for (const j of obj.children) {
103
105
  obj.errorsCount += j.errorsCount || 0;
104
106
  }
105
107
  }
106
- if (options.warningsCount) {
108
+ if (childOptions.warningsCount) {
107
109
  obj.warningsCount = 0;
108
110
  for (const j of obj.children) {
109
111
  obj.warningsCount += j.warningsCount || 0;
@@ -112,13 +114,15 @@ class MultiStats {
112
114
  return obj;
113
115
  }
114
116
  toString(options) {
115
- options = __classPrivateFieldGet(this, _MultiStats_instances, "m", _MultiStats_createChildOptions).call(this, options, { forToString: true });
117
+ const childOptions = __classPrivateFieldGet(this, _MultiStats_instances, "m", _MultiStats_createChildOptions).call(this, options || {}, {
118
+ forToString: true
119
+ });
116
120
  const results = this.stats.map((stat, idx) => {
117
- const str = stat.toString(options.children[idx]);
121
+ const str = stat.toString(childOptions.children[idx]);
118
122
  const compilationName = stat.compilation.name;
119
123
  const name = compilationName &&
120
124
  identifierUtils
121
- .makePathsRelative(options.context, compilationName, stat.compilation.compiler.root)
125
+ .makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root)
122
126
  .replace(/\|/g, " ");
123
127
  if (!str)
124
128
  return str;
@@ -130,9 +134,6 @@ class MultiStats {
130
134
  exports.default = MultiStats;
131
135
  exports.MultiStats = MultiStats;
132
136
  _MultiStats_instances = new WeakSet(), _MultiStats_createChildOptions = function _MultiStats_createChildOptions(options, context) {
133
- if (!options) {
134
- options = {};
135
- }
136
137
  const { children: childrenOptions = undefined, ...baseOptions } = typeof options === "string" ? { preset: options } : options;
137
138
  const children = this.stats.map((stat, idx) => {
138
139
  const childOptions = Array.isArray(childrenOptions)
@@ -153,6 +154,8 @@ _MultiStats_instances = new WeakSet(), _MultiStats_createChildOptions = function
153
154
  warningsCount: children.every(o => o.warningsCount),
154
155
  errors: children.every(o => o.errors),
155
156
  warnings: children.every(o => o.warnings),
156
- children
157
+ children,
158
+ context: "",
159
+ version: ""
157
160
  };
158
161
  };
@@ -32,10 +32,9 @@ const liteTapable = __importStar(require("@rspack/lite-tapable"));
32
32
  const Compilation_1 = require("./Compilation");
33
33
  const compilationHooksMap = new WeakMap();
34
34
  const createFakeHook = (fakeHook, message, code) => {
35
- if (message && code) {
36
- fakeHook = deprecateAllProperties(fakeHook, message, code);
37
- }
38
- return Object.freeze(Object.assign(fakeHook, { _fakeHook: true }));
35
+ return Object.freeze(Object.assign(message && code
36
+ ? deprecateAllProperties(fakeHook, message, code)
37
+ : fakeHook, { _fakeHook: true }));
39
38
  };
40
39
  const deprecateAllProperties = (obj, message, code) => {
41
40
  const newObj = {};
@@ -1,7 +1,6 @@
1
1
  import type * as binding from "@rspack/binding";
2
2
  import { type Resolve } from "./config";
3
- interface ResolveContext {
4
- }
3
+ type ResolveContext = {};
5
4
  type ErrorWithDetail = Error & {
6
5
  details?: string;
7
6
  };
@@ -15,7 +15,7 @@ class NonErrorEmittedError extends Error {
15
15
  constructor(error) {
16
16
  super();
17
17
  this.name = "NonErrorEmittedError";
18
- this.message = "(Emitted value instead of an instance of Error) " + error;
18
+ this.message = `(Emitted value instead of an instance of Error) ${error}`;
19
19
  }
20
20
  }
21
21
  exports.NonErrorEmittedError = NonErrorEmittedError;
package/dist/Stats.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Compilation } from "./Compilation";
2
2
  import type { StatsOptions, StatsValue } from "./config";
3
3
  import type { StatsCompilation } from "./stats/statsFactoryUtils";
4
- export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule, StatsWarnings } from "./stats/statsFactoryUtils";
4
+ export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule } from "./stats/statsFactoryUtils";
5
5
  export declare class Stats {
6
6
  #private;
7
7
  compilation: Compilation;
package/dist/Stats.js CHANGED
@@ -32,16 +32,17 @@ class Stats {
32
32
  return this.compilation.endTime;
33
33
  }
34
34
  hasErrors() {
35
- return __classPrivateFieldGet(this, _Stats_inner, "f").getErrors().length > 0;
35
+ return __classPrivateFieldGet(this, _Stats_inner, "f").hasErrors();
36
36
  }
37
37
  hasWarnings() {
38
- return __classPrivateFieldGet(this, _Stats_inner, "f").getWarnings().length > 0;
38
+ return __classPrivateFieldGet(this, _Stats_inner, "f").hasWarnings();
39
39
  }
40
40
  toJson(opts, forToString) {
41
41
  const options = this.compilation.createStatsOptions(opts, {
42
42
  forToString
43
43
  });
44
44
  const statsFactory = this.compilation.createStatsFactory(options);
45
+ const statsCompilationMap = new Map();
45
46
  // FIXME: This is a really ugly workaround for avoid panic for accessing previous compilation.
46
47
  // Modern.js dev server will detect whether the returned stats is available.
47
48
  // So this does not do harm to these frameworks.
@@ -50,6 +51,15 @@ class Stats {
50
51
  try {
51
52
  stats = statsFactory.create("compilation", this.compilation, {
52
53
  compilation: this.compilation,
54
+ getStatsCompilation: (compilation) => {
55
+ if (statsCompilationMap.has(compilation)) {
56
+ return statsCompilationMap.get(compilation);
57
+ }
58
+ const innerStats = __classPrivateFieldGet(this, _Stats_instances, "m", _Stats_getInnerByCompilation).call(this, compilation);
59
+ const innerStatsCompilation = innerStats.toJson(options);
60
+ statsCompilationMap.set(compilation, innerStatsCompilation);
61
+ return innerStatsCompilation;
62
+ },
53
63
  getInner: __classPrivateFieldGet(this, _Stats_instances, "m", _Stats_getInnerByCompilation).bind(this)
54
64
  });
55
65
  }
@@ -65,6 +75,7 @@ class Stats {
65
75
  });
66
76
  const statsFactory = this.compilation.createStatsFactory(options);
67
77
  const statsPrinter = this.compilation.createStatsPrinter(options);
78
+ const statsCompilationMap = new Map();
68
79
  // FIXME: This is a really ugly workaround for avoid panic for accessing previous compilation.
69
80
  // Modern.js dev server will detect whether the returned stats is available.
70
81
  // So this does not do harm to these frameworks.
@@ -73,6 +84,15 @@ class Stats {
73
84
  try {
74
85
  stats = statsFactory.create("compilation", this.compilation, {
75
86
  compilation: this.compilation,
87
+ getStatsCompilation: (compilation) => {
88
+ if (statsCompilationMap.has(compilation)) {
89
+ return statsCompilationMap.get(compilation);
90
+ }
91
+ const innerStats = __classPrivateFieldGet(this, _Stats_instances, "m", _Stats_getInnerByCompilation).call(this, compilation);
92
+ const innerStatsCompilation = innerStats.toJson(options);
93
+ statsCompilationMap.set(compilation, innerStatsCompilation);
94
+ return innerStatsCompilation;
95
+ },
76
96
  getInner: __classPrivateFieldGet(this, _Stats_instances, "m", _Stats_getInnerByCompilation).bind(this)
77
97
  });
78
98
  }
@@ -37,15 +37,15 @@ declare class Template {
37
37
  */
38
38
  static toPath(str: string): string;
39
39
  /**
40
- * @param n number to convert to ident
40
+ * @param num number to convert to ident
41
41
  * @returns returns single character ident
42
42
  */
43
- static numberToIdentifier(n: number): string;
43
+ static numberToIdentifier(num: number): string;
44
44
  /**
45
- * @param n number to convert to ident
45
+ * @param num number to convert to ident
46
46
  * @returns returns single character ident
47
47
  */
48
- static numberToIdentifierContinuation(n: number): string;
48
+ static numberToIdentifierContinuation(num: number): string;
49
49
  /**
50
50
  *
51
51
  * @param s string to convert to identity
package/dist/Template.js CHANGED
@@ -80,10 +80,11 @@ class Template {
80
80
  }
81
81
  // map number to a single character a-z, A-Z or multiple characters if number is too big
82
82
  /**
83
- * @param n number to convert to ident
83
+ * @param num number to convert to ident
84
84
  * @returns returns single character ident
85
85
  */
86
- static numberToIdentifier(n) {
86
+ static numberToIdentifier(num) {
87
+ let n = num;
87
88
  if (n >= NUMBER_OF_IDENTIFIER_START_CHARS) {
88
89
  // use multiple letters
89
90
  return (Template.numberToIdentifier(n % NUMBER_OF_IDENTIFIER_START_CHARS) +
@@ -103,10 +104,11 @@ class Template {
103
104
  return "$";
104
105
  }
105
106
  /**
106
- * @param n number to convert to ident
107
+ * @param num number to convert to ident
107
108
  * @returns returns single character ident
108
109
  */
109
- static numberToIdentifierContinuation(n) {
110
+ static numberToIdentifierContinuation(num) {
111
+ let n = num;
110
112
  if (n >= NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS) {
111
113
  // use multiple letters
112
114
  return (Template.numberToIdentifierContinuation(n % NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS) +
@@ -156,7 +158,7 @@ class Template {
156
158
  if (!str)
157
159
  return "";
158
160
  const ind = str[0] === "\n" ? "" : prefix;
159
- return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
161
+ return ind + str.replace(/\n([^\n])/g, `\n${prefix}$1`);
160
162
  }
161
163
  /**
162
164
  *
@@ -186,7 +188,7 @@ class Template {
186
188
  if (minId > moduleId)
187
189
  minId = moduleId;
188
190
  }
189
- if (minId < 16 + ("" + minId).length) {
191
+ if (minId < 16 + `${minId}`.length) {
190
192
  // add minId x ',' instead of 'Array(minId).concat(…)'
191
193
  minId = 0;
192
194
  }
package/dist/Watching.js CHANGED
@@ -171,12 +171,10 @@ class Watching {
171
171
  // this.compiler.cache.beginIdle();
172
172
  // this.compiler.idle = true;
173
173
  this.handler(err, stats);
174
- if (!cbs) {
175
- cbs = this.callbacks;
176
- this.callbacks = [];
177
- }
178
- for (const cb of cbs)
174
+ const callbacksToExecute = cbs || this.callbacks.splice(0);
175
+ for (const cb of callbacksToExecute) {
179
176
  cb(err);
177
+ }
180
178
  };
181
179
  const cbs = this.callbacks;
182
180
  this.callbacks = [];
@@ -141,7 +141,7 @@ function parseVersion(version) {
141
141
  .split("-")[0]
142
142
  .split(".")
143
143
  .map(v => Number.parseInt(v, 10));
144
- if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
144
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {
145
145
  return null;
146
146
  }
147
147
  return (major << 16) | (minor << 8) | patch;
@@ -19,7 +19,7 @@ const normalizeValue = (define, supportsBigIntLiteral) => {
19
19
  return p.toString();
20
20
  }
21
21
  if (typeof p === "function") {
22
- return "(" + p.toString() + ")";
22
+ return `(${p.toString()})`;
23
23
  }
24
24
  if (typeof p === "bigint") {
25
25
  return supportsBigIntLiteral ? `${p}n` : `BigInt("${p}")`;
@@ -1,11 +1,12 @@
1
- import { BuiltinPluginName } from "@rspack/binding";
1
+ import { type BuiltinPlugin, BuiltinPluginName } from "@rspack/binding";
2
+ import type { Compiler } from "../Compiler";
2
3
  import type { EntryDynamicNormalized } from "../config";
3
- export declare const DynamicEntryPlugin: {
4
- new (context: string, entry: EntryDynamicNormalized): {
5
- name: BuiltinPluginName;
6
- _args: [context: string, entry: EntryDynamicNormalized];
7
- affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
8
- raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
9
- apply(compiler: import("../Compiler").Compiler): void;
10
- };
11
- };
4
+ import { RspackBuiltinPlugin } from "./base";
5
+ export declare class DynamicEntryPlugin extends RspackBuiltinPlugin {
6
+ private context;
7
+ private entry;
8
+ name: BuiltinPluginName;
9
+ affectedHooks: "make";
10
+ constructor(context: string, entry: EntryDynamicNormalized);
11
+ raw(compiler: Compiler): BuiltinPlugin | undefined;
12
+ }
@@ -8,18 +8,29 @@ const binding_1 = require("@rspack/binding");
8
8
  const EntryOptionPlugin_1 = __importDefault(require("../lib/EntryOptionPlugin"));
9
9
  const EntryPlugin_1 = require("./EntryPlugin");
10
10
  const base_1 = require("./base");
11
- exports.DynamicEntryPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.DynamicEntryPlugin, (context, entry) => {
12
- return {
13
- context,
14
- entry: async () => {
15
- const result = await entry();
16
- return Object.entries(result).map(([name, desc]) => {
17
- const options = EntryOptionPlugin_1.default.entryDescriptionToOptions({}, name, desc);
18
- return {
19
- import: desc.import,
20
- options: (0, EntryPlugin_1.getRawEntryOptions)(options)
21
- };
22
- });
23
- }
24
- };
25
- }, "make");
11
+ class DynamicEntryPlugin extends base_1.RspackBuiltinPlugin {
12
+ constructor(context, entry) {
13
+ super();
14
+ this.context = context;
15
+ this.entry = entry;
16
+ this.name = binding_1.BuiltinPluginName.DynamicEntryPlugin;
17
+ this.affectedHooks = "make";
18
+ }
19
+ raw(compiler) {
20
+ const raw = {
21
+ context: this.context,
22
+ entry: async () => {
23
+ const result = await this.entry();
24
+ return Object.entries(result).map(([name, desc]) => {
25
+ const options = EntryOptionPlugin_1.default.entryDescriptionToOptions(compiler, name, desc);
26
+ return {
27
+ import: desc.import,
28
+ options: (0, EntryPlugin_1.getRawEntryOptions)(options)
29
+ };
30
+ });
31
+ }
32
+ };
33
+ return (0, base_1.createBuiltinPlugin)(this.name, raw);
34
+ }
35
+ }
36
+ exports.DynamicEntryPlugin = DynamicEntryPlugin;
@@ -1,8 +1,8 @@
1
1
  import { BuiltinPluginName } from "@rspack/binding";
2
2
  export declare const EnableChunkLoadingPlugin: {
3
- new (type: any): {
3
+ new (type: string): {
4
4
  name: BuiltinPluginName;
5
- _args: [type: any];
5
+ _args: [type: string];
6
6
  affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
7
7
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
8
8
  apply(compiler: import("../Compiler").Compiler): void;
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnableChunkLoadingPlugin = void 0;
4
4
  const binding_1 = require("@rspack/binding");
5
5
  const base_1 = require("./base");
6
- exports.EnableChunkLoadingPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EnableChunkLoadingPlugin, type => type);
6
+ exports.EnableChunkLoadingPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EnableChunkLoadingPlugin, (type) => type);
@@ -23,12 +23,7 @@ class EnableLibraryPlugin extends base_1.RspackBuiltinPlugin {
23
23
  }
24
24
  static checkEnabled(compiler, type) {
25
25
  if (!getEnabledTypes(compiler).has(type)) {
26
- throw new Error(`Library type "${type}" is not enabled. ` +
27
- "EnableLibraryPlugin need to be used to enable this type of library. " +
28
- 'This usually happens through the "output.enabledLibraryTypes" option. ' +
29
- 'If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". ' +
30
- "These types are enabled: " +
31
- Array.from(getEnabledTypes(compiler)).join(", "));
26
+ throw new Error(`Library type "${type}" is not enabled. EnableLibraryPlugin need to be used to enable this type of library. This usually happens through the "output.enabledLibraryTypes" option. If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". These types are enabled: ${Array.from(getEnabledTypes(compiler)).join(", ")}`);
32
27
  }
33
28
  }
34
29
  raw(compiler) {
@@ -1,8 +1,8 @@
1
1
  import { BuiltinPluginName } from "@rspack/binding";
2
2
  export declare const EnableWasmLoadingPlugin: {
3
- new (type: any): {
3
+ new (type: string): {
4
4
  name: BuiltinPluginName;
5
- _args: [type: any];
5
+ _args: [type: string];
6
6
  affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
7
7
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
8
8
  apply(compiler: import("../Compiler").Compiler): void;
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnableWasmLoadingPlugin = void 0;
4
4
  const binding_1 = require("@rspack/binding");
5
5
  const base_1 = require("./base");
6
- exports.EnableWasmLoadingPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EnableWasmLoadingPlugin, type => type);
6
+ exports.EnableWasmLoadingPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EnableWasmLoadingPlugin, (type) => type);
@@ -1,4 +1,4 @@
1
- import { BuiltinPluginName, type RawEntryOptions } from "@rspack/binding";
1
+ import { BuiltinPluginName, type JsEntryOptions } from "@rspack/binding";
2
2
  import { type ChunkLoading, type EntryRuntime, type Filename, type Layer, type LibraryOptions, type PublicPath } from "../config";
3
3
  export type EntryOptions = {
4
4
  name?: string;
@@ -21,4 +21,4 @@ export declare const EntryPlugin: {
21
21
  apply(compiler: import("../Compiler").Compiler): void;
22
22
  };
23
23
  };
24
- export declare function getRawEntryOptions(entry: EntryOptions): RawEntryOptions;
24
+ export declare function getRawEntryOptions(entry: EntryOptions): JsEntryOptions;
@@ -26,7 +26,7 @@ function getRawExternalItem(item) {
26
26
  externalType: type
27
27
  });
28
28
  });
29
- if (promise && promise.then) {
29
+ if (promise?.then) {
30
30
  promise.then(result => resolve({
31
31
  result: getRawExternalItemValueFormFnResult(result),
32
32
  externalType: undefined
@@ -10,7 +10,6 @@ export type CompilationHooks = {
10
10
  export declare class JavascriptModulesPlugin extends RspackBuiltinPlugin {
11
11
  name: BuiltinPluginName;
12
12
  affectedHooks: "compilation";
13
- constructor();
14
13
  raw(): BuiltinPlugin;
15
14
  static getCompilationHooks(compilation: Compilation): CompilationHooks;
16
15
  }
@@ -31,7 +31,7 @@ const base_1 = require("./base");
31
31
  const compilationHooksMap = new WeakMap();
32
32
  class JavascriptModulesPlugin extends base_1.RspackBuiltinPlugin {
33
33
  constructor() {
34
- super();
34
+ super(...arguments);
35
35
  this.name = binding_1.BuiltinPluginName.JavascriptModulesPlugin;
36
36
  this.affectedHooks = "compilation";
37
37
  }
@@ -1,9 +1,26 @@
1
- import { BuiltinPluginName, type RawLightningCssMinimizerRspackPluginOptions } from "@rspack/binding";
2
- export type LightningCssMinimizerRspackPluginOptions = Partial<RawLightningCssMinimizerRspackPluginOptions>;
1
+ import { BuiltinPluginName } from "@rspack/binding";
2
+ import { type Drafts, type FeatureOptions, type NonStandard, type PseudoClasses, type Targets } from "../builtin-loader/lightningcss";
3
+ import type { AssetConditions } from "../util/assetCondition";
4
+ export type LightningCssMinimizerRspackPluginOptions = {
5
+ test?: AssetConditions;
6
+ include?: AssetConditions;
7
+ exclude?: AssetConditions;
8
+ removeUnusedLocalIdents?: boolean;
9
+ minimizerOptions?: {
10
+ errorRecovery?: boolean;
11
+ targets?: Targets | string[] | string;
12
+ include?: FeatureOptions;
13
+ exclude?: FeatureOptions;
14
+ draft?: Drafts;
15
+ nonStandard?: NonStandard;
16
+ pseudoClasses?: PseudoClasses;
17
+ unusedSymbols?: string[];
18
+ };
19
+ };
3
20
  export declare const LightningCssMinimizerRspackPlugin: {
4
- new (options?: Partial<RawLightningCssMinimizerRspackPluginOptions> | undefined): {
21
+ new (options?: LightningCssMinimizerRspackPluginOptions | undefined): {
5
22
  name: BuiltinPluginName;
6
- _args: [options?: Partial<RawLightningCssMinimizerRspackPluginOptions> | undefined];
23
+ _args: [options?: LightningCssMinimizerRspackPluginOptions | undefined];
7
24
  affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
8
25
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
9
26
  apply(compiler: import("../Compiler").Compiler): void;
@@ -1,16 +1,40 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.LightningCssMinimizerRspackPlugin = void 0;
4
7
  const binding_1 = require("@rspack/binding");
8
+ const browserslist_1 = __importDefault(require("../../compiled/browserslist"));
9
+ const lightningcss_1 = require("../builtin-loader/lightningcss");
5
10
  const base_1 = require("./base");
6
11
  exports.LightningCssMinimizerRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.LightningCssMinimizerRspackPlugin, (options) => {
12
+ const { include, exclude, draft, nonStandard, pseudoClasses } = options?.minimizerOptions ?? {};
13
+ const targets = options?.minimizerOptions?.targets ?? "fully supports es6"; // last not support es module chrome version
7
14
  return {
8
- errorRecovery: options?.errorRecovery ?? true,
9
- unusedSymbols: options?.unusedSymbols ?? [],
10
- removeUnusedLocalIdents: options?.removeUnusedLocalIdents ?? true,
11
- browserslist: options?.browserslist ?? ["defaults"],
12
15
  test: options?.test,
13
16
  include: options?.include,
14
- exclude: options?.exclude
17
+ exclude: options?.exclude,
18
+ removeUnusedLocalIdents: options?.removeUnusedLocalIdents ?? true,
19
+ minimizerOptions: {
20
+ errorRecovery: options?.minimizerOptions?.errorRecovery ?? true,
21
+ unusedSymbols: options?.minimizerOptions?.unusedSymbols ?? [],
22
+ include: include ? (0, lightningcss_1.toFeatures)(include) : undefined,
23
+ exclude: exclude
24
+ ? (0, lightningcss_1.toFeatures)(exclude)
25
+ : // exclude all features, avoid downgrade css syntax when minimize
26
+ // 1048575 = Features.Empty | Features.Nesting | ... | Features.LogicalProperties
27
+ 1048575,
28
+ targets: typeof targets === "string" || Array.isArray(targets)
29
+ ? (0, lightningcss_1.browserslistToTargets)((0, browserslist_1.default)(targets))
30
+ : targets,
31
+ draft: draft ? { customMedia: draft.customMedia ?? false } : undefined,
32
+ nonStandard: nonStandard
33
+ ? {
34
+ deepSelectorCombinator: nonStandard.deepSelectorCombinator ?? false
35
+ }
36
+ : undefined,
37
+ pseudoClasses
38
+ }
15
39
  };
16
40
  });
@@ -1,10 +1,9 @@
1
1
  import { BuiltinPluginName } from "@rspack/binding";
2
- type MinifyCondition = string | RegExp;
3
- type MinifyConditions = MinifyCondition | MinifyCondition[];
2
+ import type { AssetConditions } from "../util/assetCondition";
4
3
  export type SwcCssMinimizerRspackPluginOptions = {
5
- test?: MinifyConditions;
6
- exclude?: MinifyConditions;
7
- include?: MinifyConditions;
4
+ test?: AssetConditions;
5
+ exclude?: AssetConditions;
6
+ include?: AssetConditions;
8
7
  };
9
8
  export declare const SwcCssMinimizerRspackPlugin: {
10
9
  new (options?: SwcCssMinimizerRspackPluginOptions | undefined): {
@@ -15,4 +14,3 @@ export declare const SwcCssMinimizerRspackPlugin: {
15
14
  apply(compiler: import("../Compiler").Compiler): void;
16
15
  };
17
16
  };
18
- export {};
@@ -1,6 +1,5 @@
1
1
  import { BuiltinPluginName } from "@rspack/binding";
2
- type MinifyCondition = string | RegExp;
3
- type MinifyConditions = MinifyCondition | MinifyCondition[];
2
+ import type { AssetConditions } from "../util/assetCondition";
4
3
  type ExtractCommentsCondition = boolean | RegExp;
5
4
  type ExtractCommentsBanner = string | boolean;
6
5
  type ExtractCommentsObject = {
@@ -9,14 +8,16 @@ type ExtractCommentsObject = {
9
8
  };
10
9
  type ExtractCommentsOptions = ExtractCommentsCondition | ExtractCommentsObject;
11
10
  export type SwcJsMinimizerRspackPluginOptions = {
11
+ test?: AssetConditions;
12
+ exclude?: AssetConditions;
13
+ include?: AssetConditions;
12
14
  extractComments?: ExtractCommentsOptions | undefined;
13
- compress?: TerserCompressOptions | boolean;
14
- mangle?: TerserMangleOptions | boolean;
15
- format?: JsFormatOptions & ToSnakeCaseProperties<JsFormatOptions>;
16
- module?: boolean;
17
- test?: MinifyConditions;
18
- exclude?: MinifyConditions;
19
- include?: MinifyConditions;
15
+ minimizerOptions?: {
16
+ compress?: TerserCompressOptions | boolean;
17
+ mangle?: TerserMangleOptions | boolean;
18
+ format?: JsFormatOptions & ToSnakeCaseProperties<JsFormatOptions>;
19
+ module?: boolean;
20
+ };
20
21
  };
21
22
  /**
22
23
  * @example ToSnakeCase<'indentLevel'> == 'indent_level'
@@ -198,12 +199,16 @@ export interface TerserMangleOptions {
198
199
  safari10?: boolean;
199
200
  reserved?: string[];
200
201
  }
201
- export interface TerserManglePropertiesOptions {
202
- }
202
+ export type TerserManglePropertiesOptions = {};
203
203
  export declare const SwcJsMinimizerRspackPlugin: {
204
204
  new (options?: SwcJsMinimizerRspackPluginOptions | undefined): {
205
205
  name: BuiltinPluginName;
206
- _args: [options?: SwcJsMinimizerRspackPluginOptions | undefined];
206
+ _args: [options?: SwcJsMinimizerRspackPluginOptions | undefined]; /**
207
+ * - `false`: removes all comments
208
+ * - `'some'`: preserves some comments
209
+ * - `'all'`: preserves all comments
210
+ * @default false
211
+ */
207
212
  affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
208
213
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
209
214
  apply(compiler: import("../Compiler").Compiler): void;