@rspack/core 0.5.9 → 0.6.0-canary-77faf73-20240410004447

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 (54) hide show
  1. package/dist/Compilation.d.ts +4 -13
  2. package/dist/Compilation.js +11 -17
  3. package/dist/Compiler.d.ts +3 -8
  4. package/dist/Compiler.js +165 -144
  5. package/dist/ContextModuleFactory.d.ts +4 -8
  6. package/dist/ContextModuleFactory.js +26 -3
  7. package/dist/ExecuteModulePlugin.js +2 -2
  8. package/dist/Module.d.ts +20 -1
  9. package/dist/Module.js +1 -0
  10. package/dist/NormalModuleFactory.d.ts +8 -23
  11. package/dist/NormalModuleFactory.js +6 -4
  12. package/dist/Stats.js +2 -2
  13. package/dist/builtin-plugin/APIPlugin.d.ts +10 -0
  14. package/dist/builtin-plugin/APIPlugin.js +6 -0
  15. package/dist/builtin-plugin/CssModulesPlugin.d.ts +10 -0
  16. package/dist/builtin-plugin/CssModulesPlugin.js +6 -0
  17. package/dist/builtin-plugin/EntryPlugin.d.ts +1 -0
  18. package/dist/builtin-plugin/EntryPlugin.js +3 -2
  19. package/dist/builtin-plugin/ExternalsPlugin.d.ts +2 -2
  20. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +3 -1
  21. package/dist/builtin-plugin/SplitChunksPlugin.js +2 -1
  22. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -0
  23. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +222 -0
  24. package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +2 -0
  25. package/dist/builtin-plugin/css-extract/hmr/normalize-url.js +38 -0
  26. package/dist/builtin-plugin/css-extract/index.d.ts +22 -0
  27. package/dist/builtin-plugin/css-extract/index.js +109 -0
  28. package/dist/builtin-plugin/css-extract/loader-options.json +32 -0
  29. package/dist/builtin-plugin/css-extract/loader.d.ts +15 -0
  30. package/dist/builtin-plugin/css-extract/loader.js +191 -0
  31. package/dist/builtin-plugin/css-extract/plugin-options.json +79 -0
  32. package/dist/builtin-plugin/css-extract/utils.d.ts +5 -0
  33. package/dist/builtin-plugin/css-extract/utils.js +51 -0
  34. package/dist/builtin-plugin/index.d.ts +4 -6
  35. package/dist/builtin-plugin/index.js +3 -15
  36. package/dist/config/adapter.js +58 -8
  37. package/dist/config/adapterRuleUse.d.ts +2 -2
  38. package/dist/config/defaults.js +65 -35
  39. package/dist/config/normalization.d.ts +1 -0
  40. package/dist/config/normalization.js +9 -1
  41. package/dist/config/zod.d.ts +706 -23
  42. package/dist/config/zod.js +47 -4
  43. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  44. package/dist/exports.d.ts +67 -11
  45. package/dist/exports.js +7 -1
  46. package/dist/lib/EntryOptionPlugin.js +1 -1
  47. package/dist/lib/NormalModuleReplacementPlugin.d.ts +19 -0
  48. package/dist/lib/NormalModuleReplacementPlugin.js +75 -0
  49. package/dist/lite-tapable/index.d.ts +25 -0
  50. package/dist/lite-tapable/index.js +70 -1
  51. package/dist/rspackOptionsApply.d.ts +0 -1
  52. package/dist/rspackOptionsApply.js +8 -21
  53. package/dist/util/comparators.d.ts +1 -1
  54. package/package.json +10 -7
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.ContextModuleFactory = void 0;
4
- const tapable_1 = require("tapable");
27
+ const liteTapable = __importStar(require("./lite-tapable"));
5
28
  class ContextModuleFactory {
6
29
  constructor() {
7
30
  this.hooks = {
@@ -18,8 +41,8 @@ class ContextModuleFactory {
18
41
  // /** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
19
42
  // factorize: new AsyncSeriesBailHook(["resolveData"]),
20
43
  // /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
21
- beforeResolve: new tapable_1.AsyncSeriesBailHook(["resolveData"]),
22
- afterResolve: new tapable_1.AsyncSeriesBailHook(["resolveData"])
44
+ beforeResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
45
+ afterResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"])
23
46
  // /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
24
47
  // createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
25
48
  // /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
@@ -13,10 +13,10 @@ class ExecuteModulePlugin {
13
13
  const moduleObject = options.moduleObject;
14
14
  const source = options.codeGenerationResult.get("javascript");
15
15
  try {
16
- const fn = node_vm_1.default.runInThisContext(`(function(module, __webpack_exports__, ${_1.RuntimeGlobals.require}) {\n${source}\n})`, {
16
+ const fn = node_vm_1.default.runInThisContext(`(function(module, __webpack_module__, __webpack_exports__, exports, ${_1.RuntimeGlobals.require}) {\n${source}\n})`, {
17
17
  filename: moduleObject.id
18
18
  });
19
- fn.call(moduleObject.exports, moduleObject, moduleObject.exports, context.__webpack_require__);
19
+ fn.call(moduleObject.exports, moduleObject, moduleObject, moduleObject.exports, moduleObject.exports, context.__webpack_require__);
20
20
  }
21
21
  catch (e) {
22
22
  let err = e instanceof Error ? e : new Error(e);
package/dist/Module.d.ts CHANGED
@@ -1,8 +1,27 @@
1
- import { JsCodegenerationResult, JsCodegenerationResults, JsModule } from "@rspack/binding";
1
+ import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsModule } from "@rspack/binding";
2
2
  import { Source } from "webpack-sources";
3
+ export type ResourceData = {
4
+ resource: string;
5
+ path: string;
6
+ query?: string;
7
+ fragment?: string;
8
+ };
9
+ export type ResourceDataWithData = ResourceData & {
10
+ data?: Record<string, any>;
11
+ };
12
+ export type CreateData = Partial<JsCreateData>;
13
+ export type ResolveData = {
14
+ context: string;
15
+ request: string;
16
+ fileDependencies: string[];
17
+ missingDependencies: string[];
18
+ contextDependencies: string[];
19
+ createData?: CreateData;
20
+ };
3
21
  export declare class Module {
4
22
  #private;
5
23
  _originalSource?: Source;
24
+ rawRequest?: string;
6
25
  static __from_binding(module: JsModule): Module;
7
26
  constructor(module: JsModule);
8
27
  get context(): string | undefined;
package/dist/Module.js CHANGED
@@ -21,6 +21,7 @@ class Module {
21
21
  constructor(module) {
22
22
  _Module_inner.set(this, void 0);
23
23
  __classPrivateFieldSet(this, _Module_inner, module, "f");
24
+ this.rawRequest = module.rawRequest;
24
25
  }
25
26
  get context() {
26
27
  return __classPrivateFieldGet(this, _Module_inner, "f").context;
@@ -1,33 +1,18 @@
1
- import { AsyncSeriesBailHook, HookMap } from "tapable";
2
1
  import * as liteTapable from "./lite-tapable";
3
2
  import type * as binding from "@rspack/binding";
4
- type ResourceData = {
5
- resource: string;
6
- path: string;
7
- query?: string;
8
- fragment?: string;
9
- };
10
- type ResourceDataWithData = ResourceData & {
11
- data?: Record<string, any>;
12
- };
13
- type ResolveData = {
14
- context?: string;
15
- request: string;
16
- fileDependencies: string[];
17
- missingDependencies: string[];
18
- contextDependencies: string[];
19
- };
20
- type CreateModuleData = binding.CreateModuleData & {
3
+ import { ResolveData, ResourceDataWithData } from "./Module";
4
+ export type NormalModuleCreateData = binding.JsNormalModuleFactoryCreateModuleArgs & {
21
5
  settings: {};
22
- matchResource: string;
23
6
  };
24
7
  export declare class NormalModuleFactory {
25
8
  hooks: {
26
- resolveForScheme: HookMap<AsyncSeriesBailHook<[ResourceDataWithData], true | void>>;
9
+ resolveForScheme: liteTapable.HookMap<liteTapable.AsyncSeriesBailHook<[ResourceDataWithData], true | void>>;
27
10
  beforeResolve: liteTapable.AsyncSeriesBailHook<[ResolveData], false | void>;
28
- afterResolve: AsyncSeriesBailHook<[ResolveData], boolean | void>;
29
- createModule: AsyncSeriesBailHook<[CreateModuleData, {}], void>;
11
+ afterResolve: liteTapable.AsyncSeriesBailHook<[ResolveData], false | void>;
12
+ createModule: liteTapable.AsyncSeriesBailHook<[
13
+ NormalModuleCreateData,
14
+ {}
15
+ ], void>;
30
16
  };
31
17
  constructor();
32
18
  }
33
- export {};
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.NormalModuleFactory = void 0;
27
- const tapable_1 = require("tapable");
28
27
  const liteTapable = __importStar(require("./lite-tapable"));
29
28
  class NormalModuleFactory {
30
29
  constructor() {
@@ -32,7 +31,7 @@ class NormalModuleFactory {
32
31
  // /** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
33
32
  // resolve: new AsyncSeriesBailHook(["resolveData"]),
34
33
  // /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
35
- resolveForScheme: new tapable_1.HookMap(() => new tapable_1.AsyncSeriesBailHook(["resourceData"])),
34
+ resolveForScheme: new liteTapable.HookMap(() => new liteTapable.AsyncSeriesBailHook(["resourceData"])),
36
35
  // /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
37
36
  // resolveInScheme: new HookMap(
38
37
  // () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
@@ -42,9 +41,12 @@ class NormalModuleFactory {
42
41
  // /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
43
42
  beforeResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
44
43
  // /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
45
- afterResolve: new tapable_1.AsyncSeriesBailHook(["resolveData"]),
44
+ afterResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
46
45
  // /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
47
- createModule: new tapable_1.AsyncSeriesBailHook(["createData", "resolveData"])
46
+ createModule: new liteTapable.AsyncSeriesBailHook([
47
+ "createData",
48
+ "resolveData"
49
+ ])
48
50
  // /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
49
51
  // module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
50
52
  // createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
package/dist/Stats.js CHANGED
@@ -103,8 +103,8 @@ function normalizeStatsPreset(options) {
103
103
  }
104
104
  exports.normalizeStatsPreset = normalizeStatsPreset;
105
105
  function presetToOptions(name) {
106
- const pn = (typeof name === "string" && name.toLowerCase()) || name;
107
- switch (pn) {
106
+ const preset = (typeof name === "string" && name.toLowerCase()) || name;
107
+ switch (preset) {
108
108
  case "none":
109
109
  return {
110
110
  all: false
@@ -0,0 +1,10 @@
1
+ import { BuiltinPluginName } from "@rspack/binding";
2
+ export declare const APIPlugin: {
3
+ new (): {
4
+ name: BuiltinPluginName;
5
+ _options: void;
6
+ affectedHooks: "make" | "compile" | "emit" | "afterEmit" | "invalid" | "done" | "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
+ raw(): import("@rspack/binding").BuiltinPlugin;
8
+ apply(compiler: import("../Compiler").Compiler): void;
9
+ };
10
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIPlugin = void 0;
4
+ const binding_1 = require("@rspack/binding");
5
+ const base_1 = require("./base");
6
+ exports.APIPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.APIPlugin, () => { });
@@ -0,0 +1,10 @@
1
+ import { BuiltinPluginName } from "@rspack/binding";
2
+ export declare const CssModulesPlugin: {
3
+ new (): {
4
+ name: BuiltinPluginName;
5
+ _options: void;
6
+ affectedHooks: "make" | "compile" | "emit" | "afterEmit" | "invalid" | "done" | "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
+ raw(): import("@rspack/binding").BuiltinPlugin;
8
+ apply(compiler: import("../Compiler").Compiler): void;
9
+ };
10
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CssModulesPlugin = void 0;
4
+ const binding_1 = require("@rspack/binding");
5
+ const base_1 = require("./base");
6
+ exports.CssModulesPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.CssModulesPlugin, () => { }, "compilation");
@@ -9,6 +9,7 @@ export type EntryOptions = {
9
9
  baseUri?: string;
10
10
  filename?: FilenameTemplate;
11
11
  library?: LibraryOptions;
12
+ dependOn?: string[];
12
13
  };
13
14
  export declare const EntryPlugin: {
14
15
  new (context: string, entry: string, options?: string | EntryOptions | undefined): {
@@ -12,7 +12,7 @@ exports.EntryPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EntryPlugin
12
12
  entry,
13
13
  options: getRawEntryOptions(entryOptions)
14
14
  };
15
- });
15
+ }, "make");
16
16
  function getRawEntryOptions(entry) {
17
17
  const runtime = entry.runtime;
18
18
  const chunkLoading = entry.chunkLoading;
@@ -26,6 +26,7 @@ function getRawEntryOptions(entry) {
26
26
  : undefined,
27
27
  asyncChunks: entry.asyncChunks,
28
28
  filename: entry.filename,
29
- library: entry.library && (0, config_1.getRawLibrary)(entry.library)
29
+ library: entry.library && (0, config_1.getRawLibrary)(entry.library),
30
+ dependOn: entry.dependOn
30
31
  };
31
32
  }
@@ -4,7 +4,7 @@ export declare const ExternalsPlugin: {
4
4
  context?: string | undefined;
5
5
  dependencyType?: string | undefined;
6
6
  request?: string | undefined;
7
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "jsonp" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
7
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "global" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "jsonp" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
8
8
  context?: string | undefined;
9
9
  dependencyType?: string | undefined;
10
10
  request?: string | undefined;
@@ -12,7 +12,7 @@ export declare const ExternalsPlugin: {
12
12
  context?: string | undefined;
13
13
  dependencyType?: string | undefined;
14
14
  request?: string | undefined;
15
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "jsonp" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
15
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "global" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "jsonp" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
16
16
  context?: string | undefined;
17
17
  dependencyType?: string | undefined;
18
18
  request?: string | undefined;
@@ -4,4 +4,6 @@ exports.JsLoaderRspackPlugin = void 0;
4
4
  const binding_1 = require("@rspack/binding");
5
5
  const base_1 = require("./base");
6
6
  const loader_runner_1 = require("../loader-runner");
7
- exports.JsLoaderRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.JsLoaderRspackPlugin, (compiler) => loader_runner_1.runLoaders.bind(null, compiler), "compilation");
7
+ exports.JsLoaderRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.JsLoaderRspackPlugin, (compiler) => loader_runner_1.runLoaders.bind(null, compiler),
8
+ /* Not Inheretable */
9
+ "thisCompilation");
@@ -65,10 +65,11 @@ function toRawSplitChunksOptions(sc, compiler) {
65
65
  return chunks;
66
66
  }
67
67
  }
68
- const { name, chunks, cacheGroups = {}, fallbackCacheGroup, ...passThrough } = sc;
68
+ const { name, chunks, defaultSizeTypes, cacheGroups = {}, fallbackCacheGroup, ...passThrough } = sc;
69
69
  return {
70
70
  name: getName(name),
71
71
  chunks: getChunks(chunks),
72
+ defaultSizeTypes: defaultSizeTypes || ["javascript", "unknown"],
72
73
  cacheGroups: Object.entries(cacheGroups)
73
74
  .filter(([_key, group]) => group !== false)
74
75
  .map(([key, group]) => {
@@ -0,0 +1,3 @@
1
+ declare function _exports(moduleId: TODO, options: TODO): TODO;
2
+ export = _exports;
3
+ export type TODO = any;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ /* eslint-env browser */
3
+ /*
4
+ eslint-disable
5
+ no-console,
6
+ func-names
7
+ */
8
+ /** @typedef {any} TODO */
9
+ const normalizeUrl = require("./normalize-url");
10
+ const srcByModuleId = Object.create(null);
11
+ const noDocument = typeof document === "undefined";
12
+ const { forEach } = Array.prototype;
13
+ /**
14
+ * @param {function} fn
15
+ * @param {number} time
16
+ * @returns {(function(): void)|*}
17
+ */
18
+ function debounce(fn, time) {
19
+ let timeout = 0;
20
+ return function () {
21
+ // @ts-ignore
22
+ const self = this;
23
+ // eslint-disable-next-line prefer-rest-params
24
+ const args = arguments;
25
+ const functionCall = function functionCall() {
26
+ return fn.apply(self, args);
27
+ };
28
+ clearTimeout(timeout);
29
+ // @ts-ignore
30
+ timeout = setTimeout(functionCall, time);
31
+ };
32
+ }
33
+ function noop() { }
34
+ /**
35
+ * @param {TODO} moduleId
36
+ * @returns {TODO}
37
+ */
38
+ function getCurrentScriptUrl(moduleId) {
39
+ let src = srcByModuleId[moduleId];
40
+ if (!src) {
41
+ if (document.currentScript) {
42
+ ({ src } = /** @type {HTMLScriptElement} */ (document.currentScript));
43
+ }
44
+ else {
45
+ const scripts = document.getElementsByTagName("script");
46
+ const lastScriptTag = scripts[scripts.length - 1];
47
+ if (lastScriptTag) {
48
+ ({ src } = lastScriptTag);
49
+ }
50
+ }
51
+ srcByModuleId[moduleId] = src;
52
+ }
53
+ /**
54
+ * @param {string} fileMap
55
+ * @returns {null | string[]}
56
+ */
57
+ return function (fileMap) {
58
+ if (!src) {
59
+ return null;
60
+ }
61
+ const splitResult = src.split(/([^\\/]+)\.js$/);
62
+ const filename = splitResult && splitResult[1];
63
+ if (!filename) {
64
+ return [src.replace(".js", ".css")];
65
+ }
66
+ if (!fileMap) {
67
+ return [src.replace(".js", ".css")];
68
+ }
69
+ return fileMap.split(",").map(mapRule => {
70
+ const reg = new RegExp(`${filename}\\.js$`, "g");
71
+ return normalizeUrl(src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`));
72
+ });
73
+ };
74
+ }
75
+ /**
76
+ * @param {TODO} el
77
+ * @param {string} [url]
78
+ */
79
+ function updateCss(el, url) {
80
+ if (!url) {
81
+ if (!el.href) {
82
+ return;
83
+ }
84
+ // eslint-disable-next-line
85
+ url = el.href.split("?")[0];
86
+ }
87
+ if (!isUrlRequest(/** @type {string} */ (url))) {
88
+ return;
89
+ }
90
+ if (el.isLoaded === false) {
91
+ // We seem to be about to replace a css link that hasn't loaded yet.
92
+ // We're probably changing the same file more than once.
93
+ return;
94
+ }
95
+ if (!url || !(url.indexOf(".css") > -1)) {
96
+ return;
97
+ }
98
+ // eslint-disable-next-line no-param-reassign
99
+ el.visited = true;
100
+ const newEl = el.cloneNode();
101
+ newEl.isLoaded = false;
102
+ newEl.addEventListener("load", () => {
103
+ if (newEl.isLoaded) {
104
+ return;
105
+ }
106
+ newEl.isLoaded = true;
107
+ el.parentNode.removeChild(el);
108
+ });
109
+ newEl.addEventListener("error", () => {
110
+ if (newEl.isLoaded) {
111
+ return;
112
+ }
113
+ newEl.isLoaded = true;
114
+ el.parentNode.removeChild(el);
115
+ });
116
+ newEl.href = `${url}?${Date.now()}`;
117
+ if (el.nextSibling) {
118
+ el.parentNode.insertBefore(newEl, el.nextSibling);
119
+ }
120
+ else {
121
+ el.parentNode.appendChild(newEl);
122
+ }
123
+ }
124
+ /**
125
+ * @param {string} href
126
+ * @param {TODO} src
127
+ * @returns {TODO}
128
+ */
129
+ function getReloadUrl(href, src) {
130
+ let ret;
131
+ // eslint-disable-next-line no-param-reassign
132
+ href = normalizeUrl(href);
133
+ src.some(
134
+ /**
135
+ * @param {string} url
136
+ */
137
+ // eslint-disable-next-line array-callback-return
138
+ url => {
139
+ if (href.indexOf(src) > -1) {
140
+ ret = url;
141
+ }
142
+ });
143
+ return ret;
144
+ }
145
+ /**
146
+ * @param {string} [src]
147
+ * @returns {boolean}
148
+ */
149
+ function reloadStyle(src) {
150
+ if (!src) {
151
+ return false;
152
+ }
153
+ const elements = document.querySelectorAll("link");
154
+ let loaded = false;
155
+ forEach.call(elements, el => {
156
+ if (!el.href) {
157
+ return;
158
+ }
159
+ const url = getReloadUrl(el.href, src);
160
+ if (!isUrlRequest(url)) {
161
+ return;
162
+ }
163
+ if (el.visited === true) {
164
+ return;
165
+ }
166
+ if (url) {
167
+ updateCss(el, url);
168
+ loaded = true;
169
+ }
170
+ });
171
+ return loaded;
172
+ }
173
+ function reloadAll() {
174
+ const elements = document.querySelectorAll("link");
175
+ forEach.call(elements, el => {
176
+ if (el.visited === true) {
177
+ return;
178
+ }
179
+ updateCss(el);
180
+ });
181
+ }
182
+ /**
183
+ * @param {string} url
184
+ * @returns {boolean}
185
+ */
186
+ function isUrlRequest(url) {
187
+ // An URL is not an request if
188
+ // It is not http or https
189
+ if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url)) {
190
+ return false;
191
+ }
192
+ return true;
193
+ }
194
+ /**
195
+ * @param {TODO} moduleId
196
+ * @param {TODO} options
197
+ * @returns {TODO}
198
+ */
199
+ module.exports = function (moduleId, options) {
200
+ if (noDocument) {
201
+ console.log("no window.document found, will not HMR CSS");
202
+ return noop;
203
+ }
204
+ const getScriptSrc = getCurrentScriptUrl(moduleId);
205
+ function update() {
206
+ const src = getScriptSrc(options.filename);
207
+ const reloaded = reloadStyle(src);
208
+ if (options.locals) {
209
+ console.log("[HMR] Detected local css modules. Reload all css");
210
+ reloadAll();
211
+ return;
212
+ }
213
+ if (reloaded) {
214
+ console.log("[HMR] css reload %s", src.join(" "));
215
+ }
216
+ else {
217
+ console.log("[HMR] Reload all css");
218
+ reloadAll();
219
+ }
220
+ }
221
+ return debounce(update, 50);
222
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(urlString: string): string;
2
+ export = _exports;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {string[]} pathComponents
5
+ * @returns {string}
6
+ */
7
+ function normalizeUrl(pathComponents) {
8
+ return pathComponents
9
+ .reduce(function (accumulator, item) {
10
+ switch (item) {
11
+ case "..":
12
+ accumulator.pop();
13
+ break;
14
+ case ".":
15
+ break;
16
+ default:
17
+ accumulator.push(item);
18
+ }
19
+ return accumulator;
20
+ }, /** @type {string[]} */ ([]))
21
+ .join("/");
22
+ }
23
+ /**
24
+ * @param {string} urlString
25
+ * @returns {string}
26
+ */
27
+ module.exports = function (urlString) {
28
+ urlString = urlString.trim();
29
+ if (/^data:/i.test(urlString)) {
30
+ return urlString;
31
+ }
32
+ var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : "";
33
+ var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
34
+ var host = components[0].toLowerCase().replace(/\.$/, "");
35
+ components[0] = "";
36
+ var path = normalizeUrl(components);
37
+ return protocol + host + path;
38
+ };
@@ -0,0 +1,22 @@
1
+ import type { RawCssExtractPluginOption } from "@rspack/binding";
2
+ import { Compiler } from "../..";
3
+ export * from "./loader";
4
+ export interface PluginOptions {
5
+ filename?: string;
6
+ chunkFilename?: string;
7
+ ignoreOrder?: boolean;
8
+ insert?: string | ((linkTag: HTMLLinkElement) => void);
9
+ attributes?: Record<string, string>;
10
+ linkType?: string | "text/css" | false;
11
+ runtime?: boolean;
12
+ pathinfo?: boolean;
13
+ }
14
+ export declare class CssExtractRspackPlugin {
15
+ static pluginName: string;
16
+ static loader: string;
17
+ options: PluginOptions;
18
+ constructor(options?: PluginOptions);
19
+ apply(compiler: Compiler): void;
20
+ normalizeOptions(options: PluginOptions): RawCssExtractPluginOption;
21
+ }
22
+ export default CssExtractRspackPlugin;