@rspack/core 1.0.0-alpha.4 → 1.0.0-beta.0

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 (102) hide show
  1. package/compiled/zod/index.d.ts +138 -52
  2. package/compiled/zod/index.js +300 -103
  3. package/compiled/zod/package.json +1 -1
  4. package/compiled/zod-validation-error/index.js +6 -6
  5. package/dist/Compilation.d.ts +21 -3
  6. package/dist/Compilation.js +64 -49
  7. package/dist/Compiler.js +28 -28
  8. package/dist/ErrorHelpers.js +2 -4
  9. package/dist/FileSystem.js +6 -6
  10. package/dist/Module.js +2 -6
  11. package/dist/ModuleTypeConstants.d.ts +45 -69
  12. package/dist/ModuleTypeConstants.js +24 -77
  13. package/dist/NormalModule.js +6 -6
  14. package/dist/Stats.js +4 -6
  15. package/dist/Template.d.ts +31 -147
  16. package/dist/Template.js +40 -236
  17. package/dist/Watching.js +2 -2
  18. package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
  19. package/dist/builtin-loader/lightningcss/index.js +175 -0
  20. package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
  21. package/dist/builtin-plugin/DefinePlugin.js +9 -13
  22. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  23. package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
  24. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
  25. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
  26. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
  27. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
  28. package/dist/builtin-plugin/SplitChunksPlugin.js +7 -17
  29. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
  30. package/dist/builtin-plugin/base.js +1 -3
  31. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
  32. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
  33. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
  34. package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
  35. package/dist/builtin-plugin/css-extract/loader.js +6 -6
  36. package/dist/builtin-plugin/css-extract/utils.js +3 -3
  37. package/dist/builtin-plugin/lazy-compilation/backend.d.ts +3 -3
  38. package/dist/builtin-plugin/lazy-compilation/backend.js +1 -1
  39. package/dist/config/adapter.d.ts +1 -1
  40. package/dist/config/adapter.js +31 -30
  41. package/dist/config/adapterRuleUse.d.ts +5 -5
  42. package/dist/config/adapterRuleUse.js +23 -1
  43. package/dist/config/browserslistTargetHandler.d.ts +17 -15
  44. package/dist/config/browserslistTargetHandler.js +27 -33
  45. package/dist/config/defaults.js +27 -28
  46. package/dist/config/normalization.d.ts +2 -0
  47. package/dist/config/normalization.js +5 -5
  48. package/dist/config/target.d.ts +48 -109
  49. package/dist/config/target.js +50 -86
  50. package/dist/config/zod.d.ts +2398 -2212
  51. package/dist/config/zod.js +29 -19
  52. package/dist/container/ContainerPlugin.d.ts +7 -7
  53. package/dist/container/options.js +1 -1
  54. package/dist/exports.d.ts +4 -4
  55. package/dist/exports.js +2 -2
  56. package/dist/lib/CacheFacade.js +1 -0
  57. package/dist/lib/EntryOptionPlugin.js +2 -2
  58. package/dist/lib/ModuleFilenameHelpers.js +1 -3
  59. package/dist/lib/WebpackError.js +1 -1
  60. package/dist/lib/cache/mergeEtags.js +5 -11
  61. package/dist/lib/formatLocation.js +3 -5
  62. package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
  63. package/dist/loader-runner/LoaderLoadingError.js +3 -5
  64. package/dist/loader-runner/index.js +23 -25
  65. package/dist/loader-runner/loadLoader.d.ts +11 -2
  66. package/dist/loader-runner/loadLoader.js +18 -20
  67. package/dist/logging/createConsoleLogger.js +2 -6
  68. package/dist/logging/truncateArgs.js +5 -9
  69. package/dist/node/NodeWatchFileSystem.js +5 -5
  70. package/dist/node/nodeConsole.js +2 -4
  71. package/dist/rspack.js +6 -6
  72. package/dist/rspackOptionsApply.js +3 -3
  73. package/dist/stats/DefaultStatsFactoryPlugin.js +65 -20
  74. package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
  75. package/dist/stats/DefaultStatsPrinterPlugin.js +12 -17
  76. package/dist/stats/StatsFactory.js +13 -17
  77. package/dist/stats/StatsPrinter.js +7 -9
  78. package/dist/stats/statsFactoryUtils.d.ts +9 -10
  79. package/dist/util/AssetInfo.js +11 -7
  80. package/dist/util/SplitChunkSize.js +1 -1
  81. package/dist/util/bindingVersionCheck.js +6 -6
  82. package/dist/util/cleverMerge.d.ts +33 -57
  83. package/dist/util/cleverMerge.js +89 -145
  84. package/dist/util/comparators.js +3 -5
  85. package/dist/util/createHash.d.ts +4 -3
  86. package/dist/util/createHash.js +31 -45
  87. package/dist/util/fs.js +16 -20
  88. package/dist/util/hash/BatchedHash.d.ts +24 -9
  89. package/dist/util/hash/BatchedHash.js +16 -13
  90. package/dist/util/hash/index.d.ts +9 -9
  91. package/dist/util/hash/index.js +14 -11
  92. package/dist/util/hash/md4.d.ts +29 -2
  93. package/dist/util/hash/md4.js +7 -3
  94. package/dist/util/hash/wasm-hash.d.ts +52 -5
  95. package/dist/util/hash/wasm-hash.js +19 -22
  96. package/dist/util/hash/xxhash64.d.ts +29 -2
  97. package/dist/util/hash/xxhash64.js +7 -3
  98. package/dist/util/identifier.js +13 -19
  99. package/dist/util/index.js +1 -1
  100. package/dist/util/memoize.js +7 -9
  101. package/package.json +9 -8
  102. package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
@@ -4,6 +4,11 @@ exports.rspackOptions = exports.externalsType = void 0;
4
4
  const zod_1 = require("../../compiled/zod");
5
5
  const Chunk_1 = require("../Chunk");
6
6
  const Module_1 = require("../Module");
7
+ const filenameTemplate = zod_1.z.string();
8
+ const filename = filenameTemplate.or(zod_1.z
9
+ .function()
10
+ .args(zod_1.z.custom(), zod_1.z.custom().optional())
11
+ .returns(zod_1.z.string()));
7
12
  //#region Name
8
13
  const name = zod_1.z.string();
9
14
  //#endregion
@@ -26,8 +31,7 @@ const falsy = zod_1.z.union([
26
31
  ]);
27
32
  //#endregion
28
33
  //#region Entry
29
- const rawPublicPath = zod_1.z.string();
30
- const publicPath = zod_1.z.literal("auto").or(rawPublicPath);
34
+ const publicPath = zod_1.z.literal("auto").or(filename);
31
35
  const baseUri = zod_1.z.string();
32
36
  const chunkLoadingType = zod_1.z
33
37
  .enum(["jsonp", "import-scripts", "require", "async-node", "import"])
@@ -89,12 +93,7 @@ const libraryOptions = zod_1.z.strictObject({
89
93
  umdNamedDefine: umdNamedDefine.optional()
90
94
  });
91
95
  const library = libraryName.or(libraryOptions).optional();
92
- const filenameTemplate = zod_1.z.string();
93
- const filename = filenameTemplate.or(zod_1.z
94
- .function()
95
- .args(zod_1.z.custom(), zod_1.z.custom().optional())
96
- .returns(zod_1.z.string()));
97
- const entryFilename = filenameTemplate;
96
+ const entryFilename = filename;
98
97
  const entryRuntime = zod_1.z.literal(false).or(zod_1.z.string());
99
98
  const entryItem = zod_1.z.string().or(zod_1.z.array(zod_1.z.string()));
100
99
  const entryDependOn = zod_1.z.string().or(zod_1.z.array(zod_1.z.string()));
@@ -118,7 +117,7 @@ const entry = entryStatic.or(zod_1.z.function().returns(entryStatic.or(zod_1.z.p
118
117
  //#region Output
119
118
  const path = zod_1.z.string();
120
119
  const pathinfo = zod_1.z.boolean().or(zod_1.z.literal("verbose"));
121
- const assetModuleFilename = zod_1.z.string();
120
+ const assetModuleFilename = filename;
122
121
  const webassemblyModuleFilename = zod_1.z.string();
123
122
  const chunkFilename = filename;
124
123
  const crossOriginLoading = zod_1.z
@@ -221,6 +220,8 @@ const output = zod_1.z.strictObject({
221
220
  devtoolNamespace: devtoolNamespace.optional(),
222
221
  devtoolModuleFilenameTemplate: devtoolModuleFilenameTemplate.optional(),
223
222
  devtoolFallbackModuleFilenameTemplate: devtoolFallbackModuleFilenameTemplate.optional(),
223
+ chunkLoadTimeout: zod_1.z.number().optional(),
224
+ charset: zod_1.z.boolean().optional(),
224
225
  environment: environment.optional()
225
226
  });
226
227
  //#endregion
@@ -390,7 +391,7 @@ const assetInlineGeneratorOptions = zod_1.z.strictObject({
390
391
  });
391
392
  const assetResourceGeneratorOptions = zod_1.z.strictObject({
392
393
  emit: zod_1.z.boolean().optional(),
393
- filename: filenameTemplate.optional(),
394
+ filename: filename.optional(),
394
395
  publicPath: publicPath.optional()
395
396
  });
396
397
  const assetGeneratorOptions = assetInlineGeneratorOptions.merge(assetResourceGeneratorOptions);
@@ -519,7 +520,12 @@ const externalItemObjectUnknown = zod_1.z.record(externalItemValue);
519
520
  const externalItemFunctionData = zod_1.z.strictObject({
520
521
  context: zod_1.z.string().optional(),
521
522
  dependencyType: zod_1.z.string().optional(),
522
- request: zod_1.z.string().optional()
523
+ request: zod_1.z.string().optional(),
524
+ contextInfo: zod_1.z
525
+ .strictObject({
526
+ issuer: zod_1.z.string()
527
+ })
528
+ .optional()
523
529
  });
524
530
  const externalItem = zod_1.z
525
531
  .string()
@@ -617,12 +623,19 @@ const snapshotOptions = zod_1.z.strictObject({});
617
623
  const cacheOptions = zod_1.z.boolean();
618
624
  //#endregion
619
625
  //#region Stats
626
+ const statsPresets = zod_1.z.enum([
627
+ "normal",
628
+ "none",
629
+ "verbose",
630
+ "errors-only",
631
+ "errors-warnings",
632
+ "minimal",
633
+ "detailed",
634
+ "summary"
635
+ ]);
620
636
  const statsOptions = zod_1.z.strictObject({
621
637
  all: zod_1.z.boolean().optional(),
622
- preset: zod_1.z
623
- .boolean()
624
- .or(zod_1.z.enum(["normal", "none", "verbose", "errors-only", "errors-warnings"]))
625
- .optional(),
638
+ preset: zod_1.z.boolean().or(statsPresets).optional(),
626
639
  assets: zod_1.z.boolean().optional(),
627
640
  chunks: zod_1.z.boolean().optional(),
628
641
  modules: zod_1.z.boolean().optional(),
@@ -713,10 +726,7 @@ const statsOptions = zod_1.z.strictObject({
713
726
  errorStack: zod_1.z.boolean().optional(),
714
727
  moduleTrace: zod_1.z.boolean().optional()
715
728
  });
716
- const statsValue = zod_1.z
717
- .enum(["none", "errors-only", "errors-warnings", "normal", "verbose"])
718
- .or(zod_1.z.boolean())
719
- .or(statsOptions);
729
+ const statsValue = zod_1.z.boolean().or(statsPresets).or(statsOptions);
720
730
  const plugin = zod_1.z.union([
721
731
  zod_1.z.custom(),
722
732
  zod_1.z.custom(),
@@ -28,19 +28,19 @@ export declare class ContainerPlugin extends RspackBuiltinPlugin {
28
28
  shareScope: string;
29
29
  library: {
30
30
  type: string;
31
+ name?: string | string[] | {
32
+ commonjs?: string | undefined;
33
+ amd?: string | undefined;
34
+ root?: string | string[] | undefined;
35
+ } | undefined;
31
36
  amdContainer?: string | undefined;
32
37
  auxiliaryComment?: string | {
33
- amd?: string | undefined;
34
38
  commonjs?: string | undefined;
35
- commonjs2?: string | undefined;
39
+ amd?: string | undefined;
36
40
  root?: string | undefined;
41
+ commonjs2?: string | undefined;
37
42
  } | undefined;
38
43
  export?: string | string[] | undefined;
39
- name?: string | string[] | {
40
- amd?: string | undefined;
41
- commonjs?: string | undefined;
42
- root?: string | string[] | undefined;
43
- } | undefined;
44
44
  umdNamedDefine?: boolean | undefined;
45
45
  };
46
46
  runtime: string | false | undefined;
@@ -28,7 +28,7 @@ const process = (options, normalizeSimple, normalizeOptions, fn) => {
28
28
  if (!options) {
29
29
  return;
30
30
  }
31
- else if (Array.isArray(options)) {
31
+ if (Array.isArray(options)) {
32
32
  array(options);
33
33
  }
34
34
  else if (typeof options === "object") {
package/dist/exports.d.ts CHANGED
@@ -18,8 +18,7 @@ export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule,
18
18
  export { Stats } from "./Stats";
19
19
  import * as ModuleFilenameHelpers from "./lib/ModuleFilenameHelpers";
20
20
  export { ModuleFilenameHelpers };
21
- import Template = require("./Template");
22
- export { Template };
21
+ export { Template } from "./Template";
23
22
  export declare const WebpackError: ErrorConstructor;
24
23
  export type { Watching } from "./Watching";
25
24
  import sources = require("../compiled/webpack-sources");
@@ -34,8 +33,8 @@ type Config = {
34
33
  export declare const config: Config;
35
34
  export type * from "./config";
36
35
  export declare const util: {
37
- createHash: (algorithm: any) => any;
38
- cleverMerge: <T, O>(first: T, second: O) => T | O | (T & O);
36
+ createHash: (algorithm: "debug" | "md4" | "xxhash64" | (string & {}) | "native-md4" | (new () => import("./util/hash").default)) => import("./util/hash").default;
37
+ cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
39
38
  };
40
39
  export { default as EntryOptionPlugin } from "./lib/EntryOptionPlugin";
41
40
  export { type OutputFileSystem } from "./util/fs";
@@ -148,6 +147,7 @@ export { EvalSourceMapDevToolPlugin } from "./builtin-plugin";
148
147
  export { EvalDevToolModulePlugin } from "./builtin-plugin";
149
148
  export { CssExtractRspackPlugin } from "./builtin-plugin";
150
149
  export type { SwcLoaderEnvConfig, SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, SwcLoaderOptions, SwcLoaderParserConfig, SwcLoaderTransformConfig, SwcLoaderTsParserConfig } from "./builtin-loader/swc/index";
150
+ export { type LoaderOptions as LightningcssLoaderOptions, type FeatureOptions as LightningcssFeatureOptions } from "./builtin-loader/lightningcss/index";
151
151
  import { cleanupGlobalTrace, registerGlobalTrace } from "@rspack/binding";
152
152
  interface Experiments {
153
153
  globalTrace: {
package/dist/exports.js CHANGED
@@ -52,8 +52,8 @@ Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { r
52
52
  const ModuleFilenameHelpers = __importStar(require("./lib/ModuleFilenameHelpers"));
53
53
  exports.ModuleFilenameHelpers = ModuleFilenameHelpers;
54
54
  // API extractor not working with some re-exports, see: https://github.com/microsoft/fluentui/issues/20694
55
- const Template = require("./Template");
56
- exports.Template = Template;
55
+ var Template_1 = require("./Template");
56
+ Object.defineProperty(exports, "Template", { enumerable: true, get: function () { return Template_1.Template; } });
57
57
  exports.WebpackError = Error;
58
58
  const sources = require("../compiled/webpack-sources");
59
59
  exports.sources = sources;
@@ -52,6 +52,7 @@ class MultiItemCache {
52
52
  getPromise() {
53
53
  // @ts-expect-error
54
54
  const next = i => {
55
+ // @ts-ignore if your typescript version >= 5.5, this line will throw an error
55
56
  return this._items[i].getPromise().then(result => {
56
57
  if (result !== undefined)
57
58
  return result;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const assert_1 = __importDefault(require("assert"));
15
+ const node_assert_1 = __importDefault(require("node:assert"));
16
16
  const builtin_plugin_1 = require("../builtin-plugin");
17
17
  class EntryOptionPlugin {
18
18
  apply(compiler) {
@@ -29,7 +29,7 @@ class EntryOptionPlugin {
29
29
  for (const name of Object.keys(entry)) {
30
30
  const desc = entry[name];
31
31
  const options = EntryOptionPlugin.entryDescriptionToOptions(compiler, name, desc);
32
- (0, assert_1.default)(desc.import !== undefined, "desc.import should not be `undefined` once `EntryOptionPlugin.applyEntryOption` is called");
32
+ (0, node_assert_1.default)(desc.import !== undefined, "desc.import should not be `undefined` once `EntryOptionPlugin.applyEntryOption` is called");
33
33
  for (const entry of desc.import) {
34
34
  new builtin_plugin_1.EntryPlugin(context, entry, options).apply(compiler);
35
35
  }
@@ -27,9 +27,7 @@ const matchPart = (str, test) => {
27
27
  if (Array.isArray(test)) {
28
28
  return test.map(exports.asRegExp).some(regExp => regExp.test(str));
29
29
  }
30
- else {
31
- return (0, exports.asRegExp)(test).test(str);
32
- }
30
+ return (0, exports.asRegExp)(test).test(str);
33
31
  };
34
32
  exports.matchPart = matchPart;
35
33
  /**
@@ -3,7 +3,7 @@
3
3
  Author Jarid Margolin @jaridmargolin
4
4
  */
5
5
  "use strict";
6
- const inspect = require("util").inspect.custom;
6
+ const inspect = require("node:util").inspect.custom;
7
7
  // /** @typedef {import("./Chunk")} Chunk */
8
8
  // /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
9
9
  // /** @typedef {import("./Module")} Module */
@@ -29,11 +29,9 @@ const mergeEtags = (a, b) => {
29
29
  if (typeof b === "string") {
30
30
  return `${a}|${b}`;
31
31
  }
32
- else {
33
- const temp = b;
34
- b = a;
35
- a = temp;
36
- }
32
+ const temp = b;
33
+ b = a;
34
+ a = temp;
37
35
  }
38
36
  else {
39
37
  if (typeof b !== "string") {
@@ -48,9 +46,7 @@ const mergeEtags = (a, b) => {
48
46
  map.set(b, newMergedEtag);
49
47
  return newMergedEtag;
50
48
  }
51
- else {
52
- return mergedEtag;
53
- }
49
+ return mergedEtag;
54
50
  }
55
51
  }
56
52
  // a is object, b is string
@@ -64,8 +60,6 @@ const mergeEtags = (a, b) => {
64
60
  map.set(b, newMergedEtag);
65
61
  return newMergedEtag;
66
62
  }
67
- else {
68
- return mergedEtag;
69
- }
63
+ return mergedEtag;
70
64
  };
71
65
  module.exports = mergeEtags;
@@ -16,7 +16,7 @@ const formatPosition = pos => {
16
16
  if ("line" in pos && "column" in pos) {
17
17
  return `${pos.line}:${pos.column}`;
18
18
  }
19
- else if ("line" in pos) {
19
+ if ("line" in pos) {
20
20
  return `${pos.line}:?`;
21
21
  }
22
22
  }
@@ -37,7 +37,7 @@ const formatLocation = loc => {
37
37
  loc.start.line === loc.end.line) {
38
38
  return `${formatPosition(loc.start)}-${loc.end.column}`;
39
39
  }
40
- else if (typeof loc.start === "object" &&
40
+ if (typeof loc.start === "object" &&
41
41
  typeof loc.start.line === "number" &&
42
42
  typeof loc.start.column !== "number" &&
43
43
  typeof loc.end === "object" &&
@@ -45,9 +45,7 @@ const formatLocation = loc => {
45
45
  typeof loc.end.column !== "number") {
46
46
  return `${loc.start.line}-${loc.end.line}`;
47
47
  }
48
- else {
49
- return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
50
- }
48
+ return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
51
49
  }
52
50
  if ("start" in loc && loc.start) {
53
51
  return formatPosition(loc.start);
@@ -1,3 +1,13 @@
1
- export = LoadingLoaderError;
1
+ /**
2
+ * The following code is from
3
+ * https://github.com/webpack/loader-runner
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/loader-runner/blob/main/LICENSE
9
+ */
2
10
  declare class LoadingLoaderError extends Error {
11
+ constructor(message: string);
3
12
  }
13
+ export default LoadingLoaderError;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * The following code is from
3
4
  * https://github.com/webpack/loader-runner
@@ -7,15 +8,12 @@
7
8
  * Copyright (c) JS Foundation and other contributors
8
9
  * https://github.com/webpack/loader-runner/blob/main/LICENSE
9
10
  */
10
- "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
11
12
  class LoadingLoaderError extends Error {
12
- /**
13
- * @param {string=} message
14
- */
15
13
  constructor(message) {
16
14
  super(message);
17
15
  this.name = "LoaderRunnerError";
18
16
  Error.captureStackTrace(this, this.constructor);
19
17
  }
20
18
  }
21
- module.exports = LoadingLoaderError;
19
+ exports.default = LoadingLoaderError;
@@ -26,15 +26,15 @@ var _LoaderObject_loaderItem;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.parsePathQueryFragment = exports.runLoaders = exports.LoaderObject = void 0;
28
28
  const node_querystring_1 = __importDefault(require("node:querystring"));
29
- const assert_1 = __importDefault(require("assert"));
30
- const util_1 = require("util");
29
+ const node_assert_1 = __importDefault(require("node:assert"));
30
+ const node_util_1 = require("node:util");
31
31
  const binding_1 = require("@rspack/binding");
32
32
  const webpack_sources_1 = require("../../compiled/webpack-sources");
33
33
  const Module_1 = require("../Module");
34
34
  const NormalModule_1 = require("../NormalModule");
35
35
  const RspackError_1 = require("../RspackError");
36
36
  const adapterRuleUse_1 = require("../config/adapterRuleUse");
37
- const util_2 = require("../util");
37
+ const util_1 = require("../util");
38
38
  const createHash_1 = require("../util/createHash");
39
39
  const identifier_1 = require("../util/identifier");
40
40
  const memoize_1 = require("../util/memoize");
@@ -123,14 +123,14 @@ class LoaderObject {
123
123
  return __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").pitchExecuted;
124
124
  }
125
125
  set pitchExecuted(value) {
126
- (0, assert_1.default)(value);
126
+ (0, node_assert_1.default)(value);
127
127
  __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").pitchExecuted = true;
128
128
  }
129
129
  get normalExecuted() {
130
130
  return __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").normalExecuted;
131
131
  }
132
132
  set normalExecuted(value) {
133
- (0, assert_1.default)(value);
133
+ (0, node_assert_1.default)(value);
134
134
  __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").normalExecuted = true;
135
135
  }
136
136
  // A data object shared between the pitch and the normal phase
@@ -167,14 +167,14 @@ exports.LoaderObject = LoaderObject;
167
167
  _LoaderObject_loaderItem = new WeakMap();
168
168
  class JsSourceMap {
169
169
  static __from_binding(map) {
170
- return (0, util_2.isNil)(map) ? undefined : (0, util_2.toObject)(map);
170
+ return (0, util_1.isNil)(map) ? undefined : (0, util_1.toObject)(map);
171
171
  }
172
172
  static __to_binding(map) {
173
- return (0, util_2.serializeObject)(map);
173
+ return (0, util_1.serializeObject)(map);
174
174
  }
175
175
  }
176
- const loadLoaderAsync = (0, util_1.promisify)(loadLoader_1.default);
177
- const runSyncOrAsync = (0, util_1.promisify)(function runSyncOrAsync(fn, context, args, callback) {
176
+ const loadLoaderAsync = (0, node_util_1.promisify)(loadLoader_1.default);
177
+ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, context, args, callback) {
178
178
  let isSync = true;
179
179
  let isDone = false;
180
180
  let isError = false; // internal error
@@ -293,7 +293,6 @@ async function runLoaders(compiler, context) {
293
293
  const contextDependencies = context.contextDependencies;
294
294
  const missingDependencies = context.missingDependencies;
295
295
  const buildDependencies = context.buildDependencies;
296
- const assetFilenames = context.assetFilenames;
297
296
  /// Construct `loaderContext`
298
297
  const loaderContext = {};
299
298
  loaderContext.loaders = context.loaderItems.map(item => {
@@ -356,7 +355,6 @@ async function runLoaders(compiler, context) {
356
355
  if (res.cacheable === false) {
357
356
  this.cacheable(false);
358
357
  }
359
- assetFilenames.push(...res.assets);
360
358
  resolve(compiler.__internal__getModuleExecutionResult(res.id));
361
359
  }
362
360
  });
@@ -384,7 +382,6 @@ async function runLoaders(compiler, context) {
384
382
  if (res.cacheable === false) {
385
383
  this.cacheable(false);
386
384
  }
387
- assetFilenames.push(...res.assets);
388
385
  callback(undefined, compiler.__internal__getModuleExecutionResult(res.id));
389
386
  }
390
387
  });
@@ -516,9 +513,9 @@ async function runLoaders(compiler, context) {
516
513
  }
517
514
  const hasStack = !!error.stack;
518
515
  error.name = "ModuleError";
519
- error.message = `${error.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
516
+ error.message = `${error.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
520
517
  !hasStack && Error.captureStackTrace(error);
521
- error = (0, util_2.concatErrorMsgAndStack)(error);
518
+ error = (0, util_1.concatErrorMsgAndStack)(error);
522
519
  error.moduleIdentifier = this._module.identifier();
523
520
  compiler._lastCompilation.__internal__pushDiagnostic({
524
521
  error,
@@ -531,9 +528,9 @@ async function runLoaders(compiler, context) {
531
528
  }
532
529
  const hasStack = !!warning.stack;
533
530
  warning.name = "ModuleWarning";
534
- warning.message = `${warning.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
531
+ warning.message = `${warning.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
535
532
  hasStack && Error.captureStackTrace(warning);
536
- warning = (0, util_2.concatErrorMsgAndStack)(warning);
533
+ warning = (0, util_1.concatErrorMsgAndStack)(warning);
537
534
  warning.moduleIdentifier = this._module.identifier();
538
535
  compiler._lastCompilation.__internal__pushDiagnostic({
539
536
  error: warning,
@@ -560,9 +557,12 @@ async function runLoaders(compiler, context) {
560
557
  // @ts-expect-error webpack-sources type declaration is wrong
561
558
  content);
562
559
  }
563
- assetFilenames.push(name),
564
- // @ts-expect-error
565
- compiler._lastCompilation.emitAsset(name, source, assetInfo);
560
+ // @ts-expect-error
561
+ compiler._lastCompilation.__internal__emit_asset_from_loader(name,
562
+ // @ts-expect-error
563
+ source,
564
+ // @ts-expect-error
565
+ assetInfo, context._moduleIdentifier);
566
566
  };
567
567
  loaderContext.fs = compiler.inputFileSystem;
568
568
  const getAbsolutify = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindCache(compiler.root));
@@ -661,8 +661,8 @@ async function runLoaders(compiler, context) {
661
661
  const hasArg = args.some(value => value !== undefined);
662
662
  if (hasArg) {
663
663
  const [content, sourceMap, additionalData] = args;
664
- context.content = (0, util_2.isNil)(content) ? null : (0, util_2.toBuffer)(content);
665
- context.sourceMap = (0, util_2.serializeObject)(sourceMap);
664
+ context.content = (0, util_1.isNil)(content) ? null : (0, util_1.toBuffer)(content);
665
+ context.sourceMap = (0, util_1.serializeObject)(sourceMap);
666
666
  context.additionalData = additionalData;
667
667
  break;
668
668
  }
@@ -691,7 +691,7 @@ async function runLoaders(compiler, context) {
691
691
  [content, sourceMap, additionalData] =
692
692
  (await runSyncOrAsync(fn, loaderContext, args)) || [];
693
693
  }
694
- context.content = (0, util_2.isNil)(content) ? null : (0, util_2.toBuffer)(content);
694
+ context.content = (0, util_1.isNil)(content) ? null : (0, util_1.toBuffer)(content);
695
695
  context.sourceMap = JsSourceMap.__to_binding(sourceMap);
696
696
  context.additionalData = additionalData;
697
697
  break;
@@ -709,9 +709,7 @@ function utf8BufferToString(buf) {
709
709
  if (str.charCodeAt(0) === 0xfeff) {
710
710
  return str.slice(1);
711
711
  }
712
- else {
713
- return str;
714
- }
712
+ return str;
715
713
  }
716
714
  function convertArgs(args, raw) {
717
715
  if (!raw && Buffer.isBuffer(args[0]))
@@ -1,2 +1,11 @@
1
- declare function _exports(loader: any, callback: any): any;
2
- export = _exports;
1
+ /**
2
+ * The following code is from
3
+ * https://github.com/webpack/loader-runner
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/loader-runner/blob/main/LICENSE
9
+ */
10
+ import type { LoaderObject } from ".";
11
+ export default function loadLoader(loader: LoaderObject, callback: (err: unknown) => void): void;
@@ -8,19 +8,20 @@
8
8
  * Copyright (c) JS Foundation and other contributors
9
9
  * https://github.com/webpack/loader-runner/blob/main/LICENSE
10
10
  */
11
- var LoaderLoadingError = require("./LoaderLoadingError");
12
- /** @type {undefined | import('node:url')} */
13
- var url;
14
- // @ts-expect-error
15
- module.exports = function loadLoader(loader, callback) {
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const LoaderLoadingError_1 = __importDefault(require("./LoaderLoadingError"));
16
+ var url = undefined;
17
+ function loadLoader(loader, callback) {
16
18
  if (loader.type === "module") {
17
19
  try {
18
20
  if (url === undefined)
19
- url = require("url");
21
+ url = require("node:url");
20
22
  var loaderUrl = url.pathToFileURL(loader.path);
21
- /** @type {Promise<any>} */
22
23
  var modulePromise = eval("import(" + JSON.stringify(loaderUrl.toString()) + ")");
23
- modulePromise.then(module => {
24
+ modulePromise.then((module) => {
24
25
  handleResult(loader, module, callback);
25
26
  }, callback);
26
27
  return;
@@ -36,28 +37,25 @@ module.exports = function loadLoader(loader, callback) {
36
37
  catch (e) {
37
38
  // it is possible for node to choke on a require if the FD descriptor
38
39
  // limit has been reached. give it a chance to recover.
39
- // @ts-expect-error
40
- if (e instanceof Error && e.code === "EMFILE") {
41
- // @ts-expect-error
40
+ if (e instanceof Error &&
41
+ e.code === "EMFILE") {
42
42
  var retry = loadLoader.bind(null, loader, callback);
43
43
  if (typeof setImmediate === "function") {
44
44
  // node >= 0.9.0
45
- return setImmediate(retry);
46
- }
47
- else {
48
- // node < 0.9.0
49
- return process.nextTick(retry);
45
+ return void setImmediate(retry);
50
46
  }
47
+ // node < 0.9.0
48
+ return process.nextTick(retry);
51
49
  }
52
50
  return callback(e);
53
51
  }
54
52
  return handleResult(loader, module, callback);
55
53
  }
56
- };
57
- // @ts-expect-error
54
+ }
55
+ exports.default = loadLoader;
58
56
  function handleResult(loader, module, callback) {
59
57
  if (typeof module !== "function" && typeof module !== "object") {
60
- return callback(new LoaderLoadingError("Module '" +
58
+ return callback(new LoaderLoadingError_1.default("Module '" +
61
59
  loader.path +
62
60
  "' is not a loader (export function or es6 module)"));
63
61
  }
@@ -66,7 +64,7 @@ function handleResult(loader, module, callback) {
66
64
  loader.raw = module.raw;
67
65
  if (typeof loader.normal !== "function" &&
68
66
  typeof loader.pitch !== "function") {
69
- return callback(new LoaderLoadingError("Module '" +
67
+ return callback(new LoaderLoadingError_1.default("Module '" +
70
68
  loader.path +
71
69
  "' is not a loader (must have normal or pitch function)"));
72
70
  }
@@ -87,13 +87,9 @@ module.exports = ({ level = "info", debug = false, console }) => {
87
87
  if (args.length > 0 && typeof args[0] === "string") {
88
88
  return [`[${name}] ${args[0]}`, ...args.slice(1)];
89
89
  }
90
- else {
91
- return [`[${name}]`, ...args];
92
- }
93
- }
94
- else {
95
- return [];
90
+ return [`[${name}]`, ...args];
96
91
  }
92
+ return [];
97
93
  };
98
94
  const debug = debugFilters.some(f => f(name));
99
95
  switch (type) {
@@ -30,12 +30,10 @@ const truncateArgs = (args, maxLength) => {
30
30
  if (availableLength >= args[0].length) {
31
31
  return args;
32
32
  }
33
- else if (availableLength > 3) {
33
+ if (availableLength > 3) {
34
34
  return ["..." + args[0].slice(-availableLength + 3)];
35
35
  }
36
- else {
37
- return [args[0].slice(-availableLength)];
38
- }
36
+ return [args[0].slice(-availableLength)];
39
37
  }
40
38
  // Check if there is space for at least 4 chars per arg
41
39
  // @ts-expect-error
@@ -76,15 +74,13 @@ const truncateArgs = (args, maxLength) => {
76
74
  if (str.length === length) {
77
75
  return str;
78
76
  }
79
- else if (length > 5) {
77
+ if (length > 5) {
80
78
  return "..." + str.slice(-length + 3);
81
79
  }
82
- else if (length > 0) {
80
+ if (length > 0) {
83
81
  return str.slice(-length);
84
82
  }
85
- else {
86
- return "";
87
- }
83
+ return "";
88
84
  });
89
85
  };
90
86
  exports.truncateArgs = truncateArgs;