@rspack/core 1.0.0-beta.2 → 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.
Files changed (65) hide show
  1. package/dist/Compilation.d.ts +21 -8
  2. package/dist/Compilation.js +114 -57
  3. package/dist/Compiler.d.ts +1 -0
  4. package/dist/Compiler.js +29 -24
  5. package/dist/DependenciesBlock.d.ts +8 -0
  6. package/dist/DependenciesBlock.js +30 -0
  7. package/dist/Dependency.d.ts +8 -0
  8. package/dist/Dependency.js +32 -0
  9. package/dist/Module.d.ts +6 -3
  10. package/dist/Module.js +13 -0
  11. package/dist/MultiCompiler.js +10 -6
  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/Stats.d.ts +1 -1
  16. package/dist/Template.d.ts +4 -4
  17. package/dist/Template.js +6 -4
  18. package/dist/Watching.js +3 -5
  19. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  20. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  21. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  22. package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -4
  23. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  24. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  25. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +16 -10
  27. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  28. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +28 -17
  29. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  30. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +2 -2
  31. package/dist/builtin-plugin/css-extract/loader.js +1 -2
  32. package/dist/config/adapter.d.ts +2 -2
  33. package/dist/config/defaults.js +9 -6
  34. package/dist/config/zod.d.ts +537 -141
  35. package/dist/config/zod.js +18 -10
  36. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  37. package/dist/exports.d.ts +4 -3
  38. package/dist/exports.js +5 -2
  39. package/dist/lib/Cache.js +6 -4
  40. package/dist/lib/CacheFacade.js +8 -9
  41. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  42. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  43. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  44. package/dist/lib/cache/mergeEtags.js +5 -3
  45. package/dist/loader-runner/index.js +4 -2
  46. package/dist/node/nodeConsole.js +5 -5
  47. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +0 -10
  48. package/dist/stats/DefaultStatsFactoryPlugin.js +130 -90
  49. package/dist/stats/DefaultStatsPresetPlugin.js +17 -18
  50. package/dist/stats/StatsFactory.js +8 -10
  51. package/dist/stats/StatsPrinter.js +3 -4
  52. package/dist/stats/statsFactoryUtils.d.ts +119 -19
  53. package/dist/stats/statsFactoryUtils.js +62 -1
  54. package/dist/util/assertNotNil.d.ts +1 -1
  55. package/dist/util/assetCondition.d.ts +2 -0
  56. package/dist/util/assetCondition.js +2 -0
  57. package/dist/util/cleverMerge.js +5 -4
  58. package/dist/util/createHash.js +10 -5
  59. package/dist/util/hash/wasm-hash.js +5 -4
  60. package/dist/util/identifier.d.ts +4 -4
  61. package/dist/util/identifier.js +10 -10
  62. package/dist/util/memoize.js +3 -2
  63. package/package.json +3 -3
  64. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  65. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
@@ -51,21 +51,25 @@ const ArrayQueue_1 = __importDefault(require("./util/ArrayQueue"));
51
51
  class MultiCompiler {
52
52
  constructor(compilers, options) {
53
53
  _MultiCompiler_instances.add(this);
54
+ let normalizedCompilers;
54
55
  if (!Array.isArray(compilers)) {
55
- compilers = Object.entries(compilers).map(([name, compiler]) => {
56
+ normalizedCompilers = Object.entries(compilers).map(([name, compiler]) => {
56
57
  compiler.name = name;
57
58
  return compiler;
58
59
  });
59
60
  }
61
+ else {
62
+ normalizedCompilers = compilers;
63
+ }
60
64
  this.hooks = {
61
65
  done: new liteTapable.SyncHook(["stats"]),
62
- invalid: new liteTapable.MultiHook(compilers.map(c => c.hooks.invalid)),
63
- run: new liteTapable.MultiHook(compilers.map(c => c.hooks.run)),
66
+ invalid: new liteTapable.MultiHook(normalizedCompilers.map(c => c.hooks.invalid)),
67
+ run: new liteTapable.MultiHook(normalizedCompilers.map(c => c.hooks.run)),
64
68
  watchClose: new liteTapable.SyncHook([]),
65
- watchRun: new liteTapable.MultiHook(compilers.map(c => c.hooks.watchRun)),
66
- infrastructureLog: new liteTapable.MultiHook(compilers.map(c => c.hooks.infrastructureLog))
69
+ watchRun: new liteTapable.MultiHook(normalizedCompilers.map(c => c.hooks.watchRun)),
70
+ infrastructureLog: new liteTapable.MultiHook(normalizedCompilers.map(c => c.hooks.infrastructureLog))
67
71
  };
68
- this.compilers = compilers;
72
+ this.compilers = normalizedCompilers;
69
73
  this._options = {
70
74
  parallelism: options?.parallelism || Number.POSITIVE_INFINITY
71
75
  };
@@ -16,7 +16,7 @@ export default class MultiStats {
16
16
  get hash(): string;
17
17
  hasErrors(): boolean;
18
18
  hasWarnings(): boolean;
19
- toJson(options?: any): StatsCompilation;
19
+ toJson(options: any): StatsCompilation;
20
20
  toString(options: any): string;
21
21
  }
22
22
  export { MultiStats };
@@ -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 = {};
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;
@@ -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) +
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 = [];
@@ -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,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;
@@ -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;
@@ -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'
@@ -202,7 +203,12 @@ export type TerserManglePropertiesOptions = {};
202
203
  export declare const SwcJsMinimizerRspackPlugin: {
203
204
  new (options?: SwcJsMinimizerRspackPluginOptions | undefined): {
204
205
  name: BuiltinPluginName;
205
- _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
+ */
206
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;
207
213
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
208
214
  apply(compiler: import("../Compiler").Compiler): void;
@@ -47,11 +47,11 @@ function getRawExtractCommentsOptions(extractComments) {
47
47
  return undefined;
48
48
  }
49
49
  exports.SwcJsMinimizerRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.SwcJsMinimizerRspackPlugin, (options) => {
50
- let compress = options?.compress ?? true;
51
- const mangle = options?.mangle ?? true;
50
+ let compress = options?.minimizerOptions?.compress ?? true;
51
+ const mangle = options?.minimizerOptions?.mangle ?? true;
52
52
  const format = {
53
53
  comments: false,
54
- ...options?.format
54
+ ...options?.minimizerOptions?.format
55
55
  };
56
56
  if (compress && typeof compress === "object") {
57
57
  compress = {
@@ -65,13 +65,15 @@ exports.SwcJsMinimizerRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginN
65
65
  };
66
66
  }
67
67
  return {
68
- extractComments: getRawExtractCommentsOptions(options?.extractComments),
69
- compress,
70
- mangle,
71
- format,
72
- module: options?.module,
73
68
  test: options?.test,
74
69
  include: options?.include,
75
- exclude: options?.exclude
70
+ exclude: options?.exclude,
71
+ extractComments: getRawExtractCommentsOptions(options?.extractComments),
72
+ minimizerOptions: {
73
+ compress,
74
+ mangle,
75
+ format,
76
+ module: options?.minimizerOptions?.module
77
+ }
76
78
  };
77
79
  }, "compilation");
@@ -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 => {
@@ -51,13 +49,17 @@ function getCurrentScriptUrl(moduleId) {
51
49
  };
52
50
  }
53
51
  function updateCss(el, url) {
52
+ let normalizedUrl;
54
53
  if (!url) {
55
54
  if (!el.href) {
56
55
  return;
57
56
  }
58
- url = el.href.split("?")[0];
57
+ normalizedUrl = el.href.split("?")[0];
58
+ }
59
+ else {
60
+ normalizedUrl = url;
59
61
  }
60
- if (!isUrlRequest(url)) {
62
+ if (!isUrlRequest(normalizedUrl)) {
61
63
  return;
62
64
  }
63
65
  if (el.isLoaded === false) {
@@ -65,7 +67,7 @@ function updateCss(el, url) {
65
67
  // We're probably changing the same file more than once.
66
68
  return;
67
69
  }
68
- if (!url || !(url.indexOf(".css") > -1)) {
70
+ if (!normalizedUrl || !(normalizedUrl.indexOf(".css") > -1)) {
69
71
  return;
70
72
  }
71
73
  el.visited = true;
@@ -76,28 +78,36 @@ function updateCss(el, url) {
76
78
  return;
77
79
  }
78
80
  newEl.isLoaded = true;
79
- el.parentNode?.removeChild(el);
81
+ if (el.parentNode) {
82
+ el.parentNode.removeChild(el);
83
+ }
80
84
  });
81
85
  newEl.addEventListener("error", () => {
82
86
  if (newEl.isLoaded) {
83
87
  return;
84
88
  }
85
89
  newEl.isLoaded = true;
86
- el.parentNode?.removeChild(el);
90
+ if (el.parentNode) {
91
+ el.parentNode.removeChild(el);
92
+ }
87
93
  });
88
- newEl.href = `${url}?${Date.now()}`;
94
+ newEl.href = `${normalizedUrl}?${Date.now()}`;
95
+ const parent = el.parentNode;
96
+ if (!parent) {
97
+ return;
98
+ }
89
99
  if (el.nextSibling) {
90
- el.parentNode?.insertBefore(newEl, el.nextSibling);
100
+ parent.insertBefore(newEl, el.nextSibling);
91
101
  }
92
102
  else {
93
- el.parentNode?.appendChild(newEl);
103
+ parent.appendChild(newEl);
94
104
  }
95
105
  }
96
106
  function getReloadUrl(href, src) {
97
107
  let ret = "";
98
- href = (0, normalizeUrl_1.normalizeUrl)(href);
108
+ const normalizedHref = (0, normalizeUrl_1.normalizeUrl)(href);
99
109
  src.some(url => {
100
- if (href.indexOf(src) > -1) {
110
+ if (normalizedHref.indexOf(src) > -1) {
101
111
  ret = url;
102
112
  }
103
113
  });
@@ -159,7 +169,8 @@ function cssReload(moduleId, options) {
159
169
  return;
160
170
  }
161
171
  if (reloaded) {
162
- 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(" "));
163
174
  }
164
175
  else {
165
176
  console.log("[HMR] Reload all css");