@rspack/core 1.0.0-beta.2 → 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 (53) hide show
  1. package/dist/Compilation.d.ts +20 -1
  2. package/dist/Compilation.js +109 -44
  3. package/dist/Compiler.d.ts +1 -0
  4. package/dist/Compiler.js +29 -24
  5. package/dist/MultiCompiler.js +10 -6
  6. package/dist/MultiStats.d.ts +1 -1
  7. package/dist/MultiStats.js +19 -16
  8. package/dist/NormalModule.js +3 -4
  9. package/dist/Stats.d.ts +1 -1
  10. package/dist/Template.d.ts +4 -4
  11. package/dist/Template.js +6 -4
  12. package/dist/Watching.js +3 -5
  13. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  14. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  15. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  16. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  17. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  18. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  19. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +16 -10
  20. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  21. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +10 -6
  22. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  23. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +2 -2
  24. package/dist/builtin-plugin/css-extract/loader.js +1 -2
  25. package/dist/config/adapter.d.ts +2 -2
  26. package/dist/config/zod.d.ts +338 -62
  27. package/dist/config/zod.js +8 -5
  28. package/dist/exports.d.ts +4 -3
  29. package/dist/exports.js +5 -2
  30. package/dist/lib/Cache.js +6 -4
  31. package/dist/lib/CacheFacade.js +8 -9
  32. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  33. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  34. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  35. package/dist/lib/cache/mergeEtags.js +5 -3
  36. package/dist/loader-runner/index.js +4 -2
  37. package/dist/node/nodeConsole.js +5 -5
  38. package/dist/stats/DefaultStatsPresetPlugin.js +1 -3
  39. package/dist/stats/StatsFactory.js +3 -4
  40. package/dist/stats/StatsPrinter.js +3 -4
  41. package/dist/stats/statsFactoryUtils.d.ts +106 -19
  42. package/dist/util/assertNotNil.d.ts +1 -1
  43. package/dist/util/assetCondition.d.ts +2 -0
  44. package/dist/util/assetCondition.js +2 -0
  45. package/dist/util/cleverMerge.js +5 -4
  46. package/dist/util/createHash.js +10 -5
  47. package/dist/util/hash/wasm-hash.js +5 -4
  48. package/dist/util/identifier.d.ts +4 -4
  49. package/dist/util/identifier.js +10 -10
  50. package/dist/util/memoize.js +3 -2
  51. package/package.json +3 -3
  52. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  53. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
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;
@@ -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");
@@ -51,13 +51,17 @@ function getCurrentScriptUrl(moduleId) {
51
51
  };
52
52
  }
53
53
  function updateCss(el, url) {
54
+ let normalizedUrl;
54
55
  if (!url) {
55
56
  if (!el.href) {
56
57
  return;
57
58
  }
58
- url = el.href.split("?")[0];
59
+ normalizedUrl = el.href.split("?")[0];
59
60
  }
60
- if (!isUrlRequest(url)) {
61
+ else {
62
+ normalizedUrl = url;
63
+ }
64
+ if (!isUrlRequest(normalizedUrl)) {
61
65
  return;
62
66
  }
63
67
  if (el.isLoaded === false) {
@@ -65,7 +69,7 @@ function updateCss(el, url) {
65
69
  // We're probably changing the same file more than once.
66
70
  return;
67
71
  }
68
- if (!url || !(url.indexOf(".css") > -1)) {
72
+ if (!normalizedUrl || !(normalizedUrl.indexOf(".css") > -1)) {
69
73
  return;
70
74
  }
71
75
  el.visited = true;
@@ -85,7 +89,7 @@ function updateCss(el, url) {
85
89
  newEl.isLoaded = true;
86
90
  el.parentNode?.removeChild(el);
87
91
  });
88
- newEl.href = `${url}?${Date.now()}`;
92
+ newEl.href = `${normalizedUrl}?${Date.now()}`;
89
93
  if (el.nextSibling) {
90
94
  el.parentNode?.insertBefore(newEl, el.nextSibling);
91
95
  }
@@ -95,9 +99,9 @@ function updateCss(el, url) {
95
99
  }
96
100
  function getReloadUrl(href, src) {
97
101
  let ret = "";
98
- href = (0, normalizeUrl_1.normalizeUrl)(href);
102
+ const normalizedHref = (0, normalizeUrl_1.normalizeUrl)(href);
99
103
  src.some(url => {
100
- if (href.indexOf(src) > -1) {
104
+ if (normalizedHref.indexOf(src) > -1) {
101
105
  ret = url;
102
106
  }
103
107
  });
@@ -1,2 +1,2 @@
1
- declare function normalizeUrl(urlString: string): string;
1
+ declare function normalizeUrl(url: string): string;
2
2
  export { normalizeUrl };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeUrl = void 0;
4
- function normalizeUrl(urlString) {
5
- urlString = urlString.trim();
4
+ function normalizeUrl(url) {
5
+ const urlString = url.trim();
6
6
  if (/^data:/i.test(urlString)) {
7
7
  return urlString;
8
8
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.pitch = exports.hotLoader = exports.SINGLE_DOT_PATH_SEGMENT = exports.ABSOLUTE_PUBLIC_PATH = exports.AUTO_PUBLIC_PATH = exports.MODULE_TYPE = exports.BASE_URI = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const index_1 = require("./index");
9
- const loader_options_json_1 = __importDefault(require("./loader-options.json"));
10
9
  const utils_1 = require("./utils");
11
10
  exports.BASE_URI = "webpack://";
12
11
  exports.MODULE_TYPE = "css/mini-extract";
@@ -63,7 +62,7 @@ const pitch = function (request, _, data) {
63
62
  this.emitWarning(e);
64
63
  return;
65
64
  }
66
- const options = this.getOptions(loader_options_json_1.default);
65
+ const options = this.getOptions();
67
66
  const emit = typeof options.emit !== "undefined" ? options.emit : true;
68
67
  const callback = this.async();
69
68
  const filepath = this.resourcePath;
@@ -1,4 +1,4 @@
1
- import { type RawLibraryOptions, type RawOptions } from "@rspack/binding";
1
+ import { type JsLibraryOptions, type RawOptions } from "@rspack/binding";
2
2
  import type { Compiler } from "../Compiler";
3
3
  import { type LoaderContext, type LoaderDefinition, type LoaderDefinitionFunction } from "./adapterRuleUse";
4
4
  import type { RspackOptionsNormalized } from "./normalization";
@@ -6,5 +6,5 @@ import type { ChunkLoading, LibraryOptions, Resolve } from "./zod";
6
6
  export type { LoaderContext, LoaderDefinition, LoaderDefinitionFunction };
7
7
  export declare const getRawOptions: (options: RspackOptionsNormalized, compiler: Compiler) => RawOptions;
8
8
  export declare function getRawResolve(resolve: Resolve): RawOptions["resolve"];
9
- export declare function getRawLibrary(library: LibraryOptions): RawLibraryOptions;
9
+ export declare function getRawLibrary(library: LibraryOptions): JsLibraryOptions;
10
10
  export declare function getRawChunkLoading(chunkLoading: ChunkLoading): string;