@rspack/core 1.0.0-beta.0 → 1.0.0-beta.2

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 (177) hide show
  1. package/dist/ChunkGroup.d.ts +1 -0
  2. package/dist/ChunkGroup.js +3 -0
  3. package/dist/Compilation.d.ts +19 -1
  4. package/dist/Compiler.d.ts +11 -10
  5. package/dist/Compiler.js +16 -16
  6. package/dist/ExecuteModulePlugin.d.ts +0 -1
  7. package/dist/ExecuteModulePlugin.js +0 -1
  8. package/dist/Module.d.ts +2 -2
  9. package/dist/Module.js +1 -1
  10. package/dist/MultiCompiler.js +1 -1
  11. package/dist/NormalModule.d.ts +1 -0
  12. package/dist/NormalModule.js +1 -0
  13. package/dist/Resolver.d.ts +1 -2
  14. package/dist/RspackError.js +1 -1
  15. package/dist/Stats.js +22 -2
  16. package/dist/Template.js +2 -2
  17. package/dist/builtin-loader/lightningcss/index.js +1 -1
  18. package/dist/builtin-plugin/APIPlugin.d.ts +1 -1
  19. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
  20. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
  21. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
  22. package/dist/builtin-plugin/BannerPlugin.d.ts +31 -31
  23. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
  24. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
  25. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
  26. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
  27. package/dist/builtin-plugin/CssModulesPlugin.d.ts +1 -1
  28. package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
  29. package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
  30. package/dist/builtin-plugin/DefinePlugin.js +1 -1
  31. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
  32. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
  33. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +1 -1
  34. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
  35. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +3 -3
  36. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +1 -1
  37. package/dist/builtin-plugin/EnableLibraryPlugin.js +1 -6
  38. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +3 -3
  39. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +1 -1
  40. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
  41. package/dist/builtin-plugin/EntryPlugin.d.ts +3 -2
  42. package/dist/builtin-plugin/EntryPlugin.js +1 -0
  43. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
  44. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/ExternalsPlugin.d.ts +5 -5
  46. package/dist/builtin-plugin/ExternalsPlugin.js +1 -1
  47. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +1 -1
  48. package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
  49. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
  50. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
  51. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +9 -9
  52. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
  53. package/dist/builtin-plugin/IgnorePlugin.d.ts +1 -1
  54. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
  55. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +0 -1
  56. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  57. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +1 -1
  58. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
  59. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +4 -11
  60. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
  61. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
  62. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
  63. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
  64. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
  65. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
  66. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
  67. package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +1 -1
  68. package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +1 -1
  69. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
  70. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  71. package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
  72. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
  73. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
  74. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +1 -1
  75. package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
  76. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
  77. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +1 -1
  78. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
  79. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
  80. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +2 -3
  81. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
  82. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
  83. package/dist/builtin-plugin/base.d.ts +1 -1
  84. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +3 -5
  85. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +7 -5
  86. package/dist/builtin-plugin/css-extract/loader.d.ts +8 -3
  87. package/dist/builtin-plugin/css-extract/loader.js +27 -22
  88. package/dist/builtin-plugin/lazy-compilation/backend.js +4 -4
  89. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +1 -1
  90. package/dist/config/adapter.js +16 -2
  91. package/dist/config/adapterRuleUse.d.ts +2 -6
  92. package/dist/config/adapterRuleUse.js +10 -9
  93. package/dist/config/defaults.js +28 -42
  94. package/dist/config/normalization.d.ts +7 -3
  95. package/dist/config/normalization.js +7 -2
  96. package/dist/config/zod.d.ts +1634 -1093
  97. package/dist/config/zod.js +31 -2
  98. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  99. package/dist/container/ModuleFederationRuntimePlugin.d.ts +1 -1
  100. package/dist/container/default.runtime.js +1 -1
  101. package/dist/exports.d.ts +1 -1
  102. package/dist/lib/AbstractMethodError.d.ts +12 -3
  103. package/dist/lib/AbstractMethodError.js +29 -22
  104. package/dist/lib/Cache.d.ts +40 -46
  105. package/dist/lib/Cache.js +43 -78
  106. package/dist/lib/CacheFacade.d.ts +119 -143
  107. package/dist/lib/CacheFacade.js +123 -124
  108. package/dist/lib/Dependency.d.ts +23 -0
  109. package/dist/lib/Dependency.js +11 -0
  110. package/dist/lib/EntryOptionPlugin.d.ts +19 -2
  111. package/dist/lib/EntryOptionPlugin.js +22 -6
  112. package/dist/lib/EnvironmentPlugin.d.ts +17 -10
  113. package/dist/lib/EnvironmentPlugin.js +16 -17
  114. package/dist/lib/HookWebpackError.d.ts +27 -33
  115. package/dist/lib/HookWebpackError.js +33 -34
  116. package/dist/lib/IgnoreWarningsPlugin.d.ts +25 -0
  117. package/dist/lib/{ignoreWarningsPlugin.js → IgnoreWarningsPlugin.js} +17 -0
  118. package/dist/lib/LoaderOptionsPlugin.d.ts +18 -9
  119. package/dist/lib/LoaderOptionsPlugin.js +38 -14
  120. package/dist/lib/LoaderTargetPlugin.d.ts +17 -8
  121. package/dist/lib/LoaderTargetPlugin.js +17 -15
  122. package/dist/lib/ModuleFilenameHelpers.d.ts +10 -1
  123. package/dist/lib/ModuleFilenameHelpers.js +10 -1
  124. package/dist/lib/NormalModuleReplacementPlugin.d.ts +15 -5
  125. package/dist/lib/NormalModuleReplacementPlugin.js +15 -5
  126. package/dist/lib/WebpackError.d.ts +23 -22
  127. package/dist/lib/WebpackError.js +15 -35
  128. package/dist/lib/cache/MemoryCachePlugin.d.ts +5 -0
  129. package/dist/lib/cache/MemoryCachePlugin.js +40 -0
  130. package/dist/lib/cache/getLazyHashedEtag.d.ts +24 -24
  131. package/dist/lib/cache/getLazyHashedEtag.js +20 -23
  132. package/dist/lib/cache/mergeEtags.d.ts +15 -9
  133. package/dist/lib/cache/mergeEtags.js +18 -11
  134. package/dist/lib/formatLocation.d.ts +14 -9
  135. package/dist/lib/formatLocation.js +17 -15
  136. package/dist/loader-runner/index.js +6 -7
  137. package/dist/loader-runner/loadLoader.js +8 -11
  138. package/dist/logging/Logger.js +3 -3
  139. package/dist/logging/createConsoleLogger.d.ts +26 -6
  140. package/dist/logging/createConsoleLogger.js +21 -58
  141. package/dist/logging/runtime.d.ts +4 -10
  142. package/dist/logging/runtime.js +8 -23
  143. package/dist/logging/truncateArgs.d.ts +4 -4
  144. package/dist/logging/truncateArgs.js +5 -10
  145. package/dist/node/NodeEnvironmentPlugin.js +2 -2
  146. package/dist/node/NodeWatchFileSystem.js +6 -6
  147. package/dist/node/nodeConsole.d.ts +7 -21
  148. package/dist/node/nodeConsole.js +29 -36
  149. package/dist/rspackOptionsApply.d.ts +0 -1
  150. package/dist/rspackOptionsApply.js +10 -9
  151. package/dist/sharing/ProvideSharedPlugin.d.ts +20 -19
  152. package/dist/sharing/ProvideSharedPlugin.js +26 -17
  153. package/dist/sharing/SharePlugin.d.ts +3 -0
  154. package/dist/sharing/SharePlugin.js +4 -1
  155. package/dist/stats/DefaultStatsFactoryPlugin.js +187 -96
  156. package/dist/stats/DefaultStatsPresetPlugin.js +1 -2
  157. package/dist/stats/DefaultStatsPrinterPlugin.js +18 -19
  158. package/dist/stats/StatsFactory.d.ts +2 -1
  159. package/dist/stats/StatsFactory.js +2 -6
  160. package/dist/stats/statsFactoryUtils.d.ts +63 -23
  161. package/dist/util/SizeFormatHelpers.js +1 -1
  162. package/dist/util/bindingVersionCheck.js +3 -3
  163. package/dist/util/cleverMerge.js +3 -2
  164. package/dist/util/comparators.d.ts +2 -2
  165. package/dist/util/comparators.js +5 -4
  166. package/dist/util/createHash.js +1 -1
  167. package/dist/util/fs.js +2 -2
  168. package/dist/util/identifier.js +2 -2
  169. package/dist/util/index.js +1 -1
  170. package/dist/util/memoize.js +1 -4
  171. package/dist/util/smartGrouping.js +4 -6
  172. package/dist/util/webpack.d.ts +1 -1
  173. package/dist/util/webpack.js +2 -1
  174. package/module.d.ts +1 -1
  175. package/package.json +3 -3
  176. package/compiled/enhanced-resolve/index.js +0 -5566
  177. package/dist/lib/ignoreWarningsPlugin.d.ts +0 -7
@@ -0,0 +1,5 @@
1
+ import type { Compiler } from "../../Compiler";
2
+ export default class MemoryCachePlugin {
3
+ static PLUGIN_NAME: string;
4
+ apply(compiler: Compiler): void;
5
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Cache_1 = require("../Cache");
4
+ class MemoryCachePlugin {
5
+ apply(compiler) {
6
+ const cache = new Map();
7
+ compiler.cache.hooks.store.tap({ name: MemoryCachePlugin.PLUGIN_NAME, stage: Cache_1.Cache.STAGE_MEMORY }, (identifier, etag, data) => {
8
+ const dataEtag = typeof etag?.toString === "function"
9
+ ? etag.toString()
10
+ : etag;
11
+ cache.set(identifier, { etag: dataEtag, data });
12
+ });
13
+ compiler.cache.hooks.get.tap({ name: MemoryCachePlugin.PLUGIN_NAME, stage: Cache_1.Cache.STAGE_MEMORY }, (identifier, etag, gotHandlers) => {
14
+ const cacheEntry = cache.get(identifier);
15
+ const dataEtag = typeof etag?.toString === "function"
16
+ ? etag.toString()
17
+ : etag;
18
+ if (cacheEntry === null) {
19
+ return null;
20
+ }
21
+ if (cacheEntry !== undefined) {
22
+ return cacheEntry.etag === dataEtag ? cacheEntry.data : null;
23
+ }
24
+ gotHandlers.push((result, callback) => {
25
+ if (result === undefined) {
26
+ cache.set(identifier, null);
27
+ }
28
+ else {
29
+ cache.set(identifier, { etag: dataEtag, data: result });
30
+ }
31
+ return callback(null);
32
+ });
33
+ });
34
+ compiler.cache.hooks.shutdown.tap({ name: MemoryCachePlugin.PLUGIN_NAME, stage: Cache_1.Cache.STAGE_MEMORY }, () => {
35
+ cache.clear();
36
+ });
37
+ }
38
+ }
39
+ MemoryCachePlugin.PLUGIN_NAME = "MemoryCachePlugin";
40
+ exports.default = MemoryCachePlugin;
@@ -1,35 +1,35 @@
1
- export = getter;
2
1
  /**
3
- * @param {HashableObject} obj object with updateHash method
4
- * @param {string | HashConstructor} hashFunction the hash function to use
5
- * @returns {LazyHashedEtag} etag
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/cache/getLazyHashedEtag.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
6
9
  */
7
- declare function getter(obj: HashableObject, hashFunction?: string | HashConstructor): LazyHashedEtag;
8
- declare namespace getter {
9
- export { Hash, HashConstructor, HashableObject };
10
+ import type Hash from "../../util/hash";
11
+ export type HashConstructor = typeof Hash;
12
+ export interface HashableObject {
13
+ updateHash(hash: Hash): void;
10
14
  }
11
- type HashableObject = {
12
- updateHash: (arg0: Hash) => void;
13
- };
14
- type HashConstructor = any;
15
- /** @typedef {any} Hash */
16
- /** @typedef {any} HashConstructor */
17
- /**
18
- * @typedef {Object} HashableObject
19
- * @property {function(Hash): void} updateHash
20
- */
21
15
  declare class LazyHashedEtag {
16
+ _obj: HashableObject;
17
+ _hash?: string;
18
+ _hashFunction: string | HashConstructor;
22
19
  /**
23
- * @param {HashableObject} obj object with updateHash method
24
- * @param {string | HashConstructor} hashFunction the hash function to use
20
+ * @param obj object with updateHash method
21
+ * @param hashFunction the hash function to use
25
22
  */
26
23
  constructor(obj: HashableObject, hashFunction?: string | HashConstructor);
27
- _obj: HashableObject;
28
- _hash: string | undefined;
29
- _hashFunction: any;
30
24
  /**
31
- * @returns {string} hash of object
25
+ * @returns hash of object
32
26
  */
33
27
  toString(): string;
34
28
  }
35
- type Hash = any;
29
+ /**
30
+ * @param obj object with updateHash method
31
+ * @param ashFunction the hash function to use
32
+ * @returns etag
33
+ */
34
+ export declare const getter: (obj: HashableObject, hashFunction?: string | HashConstructor) => LazyHashedEtag;
35
+ export default getter;
@@ -1,21 +1,20 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
1
  "use strict";
6
- const createHash = require("../../util/createHash");
7
- // /** @typedef {import("../util/Hash")} Hash */
8
- // /** @typedef {typeof import("../util/Hash")} HashConstructor */
9
- /** @typedef {any} Hash */
10
- /** @typedef {any} HashConstructor */
11
2
  /**
12
- * @typedef {Object} HashableObject
13
- * @property {function(Hash): void} updateHash
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/cache/getLazyHashedEtag.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
14
10
  */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getter = void 0;
13
+ const createHash_1 = require("../../util/createHash");
15
14
  class LazyHashedEtag {
16
15
  /**
17
- * @param {HashableObject} obj object with updateHash method
18
- * @param {string | HashConstructor} hashFunction the hash function to use
16
+ * @param obj object with updateHash method
17
+ * @param hashFunction the hash function to use
19
18
  */
20
19
  constructor(obj, hashFunction = "md4") {
21
20
  this._obj = obj;
@@ -23,26 +22,23 @@ class LazyHashedEtag {
23
22
  this._hashFunction = hashFunction;
24
23
  }
25
24
  /**
26
- * @returns {string} hash of object
25
+ * @returns hash of object
27
26
  */
28
27
  toString() {
29
28
  if (this._hash === undefined) {
30
- // @ts-expect-error
31
- const hash = createHash(this._hashFunction);
29
+ const hash = (0, createHash_1.createHash)(this._hashFunction);
32
30
  this._obj.updateHash(hash);
33
- this._hash = /** @type {string} */ (hash.digest("base64"));
31
+ this._hash = hash.digest("base64");
34
32
  }
35
33
  return this._hash;
36
34
  }
37
35
  }
38
- /** @type {Map<string | HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
39
36
  const mapStrings = new Map();
40
- /** @type {WeakMap<HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
41
37
  const mapObjects = new WeakMap();
42
38
  /**
43
- * @param {HashableObject} obj object with updateHash method
44
- * @param {string | HashConstructor} hashFunction the hash function to use
45
- * @returns {LazyHashedEtag} etag
39
+ * @param obj object with updateHash method
40
+ * @param ashFunction the hash function to use
41
+ * @returns etag
46
42
  */
47
43
  const getter = (obj, hashFunction = "md4") => {
48
44
  let innerMap;
@@ -73,4 +69,5 @@ const getter = (obj, hashFunction = "md4") => {
73
69
  innerMap.set(obj, newHash);
74
70
  return newHash;
75
71
  };
76
- module.exports = getter;
72
+ exports.getter = getter;
73
+ exports.default = exports.getter;
@@ -1,11 +1,17 @@
1
- export = mergeEtags;
2
1
  /**
3
- * @param {Etag} a first
4
- * @param {Etag} b second
5
- * @returns {Etag} result
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/cache/mergeEtags.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
6
9
  */
7
- declare function mergeEtags(a: Etag, b: Etag): Etag;
8
- declare namespace mergeEtags {
9
- export { Etag };
10
- }
11
- type Etag = import("../Cache").Etag;
10
+ import type { Etag } from "../Cache";
11
+ /**
12
+ * @param a first
13
+ * @param b second
14
+ * @returns result
15
+ */
16
+ export declare const mergeEtags: (a: Etag, b: Etag) => Etag;
17
+ export default mergeEtags;
@@ -1,13 +1,19 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
1
  "use strict";
6
- /** @typedef {import("../Cache").Etag} Etag */
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/cache/mergeEtags.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.mergeEtags = void 0;
7
13
  class MergedEtag {
8
14
  /**
9
- * @param {Etag} a first
10
- * @param {Etag} b second
15
+ * @param a first
16
+ * @param b second
11
17
  */
12
18
  constructor(a, b) {
13
19
  this.a = a;
@@ -20,9 +26,9 @@ class MergedEtag {
20
26
  const dualObjectMap = new WeakMap();
21
27
  const objectStringMap = new WeakMap();
22
28
  /**
23
- * @param {Etag} a first
24
- * @param {Etag} b second
25
- * @returns {Etag} result
29
+ * @param a first
30
+ * @param b second
31
+ * @returns result
26
32
  */
27
33
  const mergeEtags = (a, b) => {
28
34
  if (typeof a === "string") {
@@ -62,4 +68,5 @@ const mergeEtags = (a, b) => {
62
68
  }
63
69
  return mergedEtag;
64
70
  };
65
- module.exports = mergeEtags;
71
+ exports.mergeEtags = mergeEtags;
72
+ exports.default = exports.mergeEtags;
@@ -1,11 +1,16 @@
1
- export = formatLocation;
2
1
  /**
3
- * @param {DependencyLocation} loc location
4
- * @returns {string} formatted location
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/formatLocation.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
5
9
  */
6
- declare function formatLocation(loc: DependencyLocation): string;
7
- declare namespace formatLocation {
8
- export { DependencyLocation, SourcePosition };
9
- }
10
- type DependencyLocation = any;
11
- type SourcePosition = any;
10
+ import type { DependencyLocation } from "./Dependency";
11
+ /**
12
+ * @param loc location
13
+ * @returns formatted location
14
+ */
15
+ declare const formatLocation: (loc: DependencyLocation) => string;
16
+ export default formatLocation;
@@ -1,17 +1,19 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
1
  "use strict";
6
- // /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
7
- // /** @typedef {import("./Dependency").SourcePosition} SourcePosition */
8
- /** @typedef {any} DependencyLocation */
9
- /** @typedef {any} SourcePosition */
10
2
  /**
11
- * @param {SourcePosition} pos position
12
- * @returns {string} formatted position
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/formatLocation.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
13
10
  */
14
- const formatPosition = pos => {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /**
13
+ * @param pos position
14
+ * @returns formatted position
15
+ */
16
+ const formatPosition = (pos) => {
15
17
  if (pos && typeof pos === "object") {
16
18
  if ("line" in pos && "column" in pos) {
17
19
  return `${pos.line}:${pos.column}`;
@@ -23,10 +25,10 @@ const formatPosition = pos => {
23
25
  return "";
24
26
  };
25
27
  /**
26
- * @param {DependencyLocation} loc location
27
- * @returns {string} formatted location
28
+ * @param loc location
29
+ * @returns formatted location
28
30
  */
29
- const formatLocation = loc => {
31
+ const formatLocation = (loc) => {
30
32
  if (loc && typeof loc === "object") {
31
33
  if ("start" in loc && loc.start && "end" in loc && loc.end) {
32
34
  if (typeof loc.start === "object" &&
@@ -59,4 +61,4 @@ const formatLocation = loc => {
59
61
  }
60
62
  return "";
61
63
  };
62
- module.exports = formatLocation;
64
+ exports.default = formatLocation;
@@ -40,7 +40,7 @@ const identifier_1 = require("../util/identifier");
40
40
  const memoize_1 = require("../util/memoize");
41
41
  const loadLoader_1 = __importDefault(require("./loadLoader"));
42
42
  function createLoaderObject(loader, compiler) {
43
- var obj = {
43
+ const obj = {
44
44
  path: null,
45
45
  query: null,
46
46
  fragment: null,
@@ -88,13 +88,13 @@ function createLoaderObject(loader, compiler) {
88
88
  else if (obj.options === undefined)
89
89
  obj.query = "";
90
90
  else if (typeof obj.options === "string")
91
- obj.query = "?" + obj.options;
91
+ obj.query = `?${obj.options}`;
92
92
  else if (obj.ident)
93
- obj.query = "??" + obj.ident;
93
+ obj.query = `??${obj.ident}`;
94
94
  else if (typeof obj.options === "object" && obj.options.ident)
95
- obj.query = "??" + obj.options.ident;
95
+ obj.query = `??${obj.options.ident}`;
96
96
  else
97
- obj.query = "?" + JSON.stringify(obj.options);
97
+ obj.query = `?${JSON.stringify(obj.options)}`;
98
98
  }
99
99
  });
100
100
  obj.request = loader;
@@ -268,8 +268,7 @@ function dirname(path) {
268
268
  return path.slice(0, idx);
269
269
  }
270
270
  function getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
271
- if (loaderContext.loaders &&
272
- loaderContext.loaders.length &&
271
+ if (loaderContext.loaders?.length &&
273
272
  index < loaderContext.loaders.length &&
274
273
  index >= 0 &&
275
274
  loaderContext.loaders[index]) {
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const LoaderLoadingError_1 = __importDefault(require("./LoaderLoadingError"));
16
- var url = undefined;
16
+ let url = undefined;
17
17
  function loadLoader(loader, callback) {
18
18
  if (loader.type === "module") {
19
19
  try {
20
20
  if (url === undefined)
21
21
  url = require("node:url");
22
- var loaderUrl = url.pathToFileURL(loader.path);
23
- var modulePromise = eval("import(" + JSON.stringify(loaderUrl.toString()) + ")");
22
+ const loaderUrl = url.pathToFileURL(loader.path);
23
+ const modulePromise = eval(`import(${JSON.stringify(loaderUrl.toString())})`);
24
24
  modulePromise.then((module) => {
25
25
  handleResult(loader, module, callback);
26
26
  }, callback);
@@ -31,15 +31,16 @@ function loadLoader(loader, callback) {
31
31
  }
32
32
  }
33
33
  else {
34
+ let module;
34
35
  try {
35
- var module = require(loader.path);
36
+ module = require(loader.path);
36
37
  }
37
38
  catch (e) {
38
39
  // it is possible for node to choke on a require if the FD descriptor
39
40
  // limit has been reached. give it a chance to recover.
40
41
  if (e instanceof Error &&
41
42
  e.code === "EMFILE") {
42
- var retry = loadLoader.bind(null, loader, callback);
43
+ const retry = loadLoader.bind(null, loader, callback);
43
44
  if (typeof setImmediate === "function") {
44
45
  // node >= 0.9.0
45
46
  return void setImmediate(retry);
@@ -55,18 +56,14 @@ function loadLoader(loader, callback) {
55
56
  exports.default = loadLoader;
56
57
  function handleResult(loader, module, callback) {
57
58
  if (typeof module !== "function" && typeof module !== "object") {
58
- return callback(new LoaderLoadingError_1.default("Module '" +
59
- loader.path +
60
- "' is not a loader (export function or es6 module)"));
59
+ return callback(new LoaderLoadingError_1.default(`Module '${loader.path}' is not a loader (export function or es6 module)`));
61
60
  }
62
61
  loader.normal = typeof module === "function" ? module : module.default;
63
62
  loader.pitch = module.pitch;
64
63
  loader.raw = module.raw;
65
64
  if (typeof loader.normal !== "function" &&
66
65
  typeof loader.pitch !== "function") {
67
- return callback(new LoaderLoadingError_1.default("Module '" +
68
- loader.path +
69
- "' is not a loader (must have normal or pitch function)"));
66
+ return callback(new LoaderLoadingError_1.default(`Module '${loader.path}' is not a loader (must have normal or pitch function)`));
70
67
  }
71
68
  callback();
72
69
  }
@@ -92,7 +92,7 @@ class Logger {
92
92
  this[TIMERS_SYMBOL].set(label, process.hrtime());
93
93
  }
94
94
  timeLog(label) {
95
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
95
+ const prev = this[TIMERS_SYMBOL]?.get(label);
96
96
  if (!prev) {
97
97
  throw new Error(`No such label '${label}' for WebpackLogger.timeLog()`);
98
98
  }
@@ -100,7 +100,7 @@ class Logger {
100
100
  this[LOG_SYMBOL](exports.LogType.time, [label, ...time]);
101
101
  }
102
102
  timeEnd(label) {
103
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
103
+ const prev = this[TIMERS_SYMBOL]?.get(label);
104
104
  if (!prev) {
105
105
  throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
106
106
  }
@@ -109,7 +109,7 @@ class Logger {
109
109
  this[LOG_SYMBOL](exports.LogType.time, [label, ...time]);
110
110
  }
111
111
  timeAggregate(label) {
112
- const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
112
+ const prev = this[TIMERS_SYMBOL]?.get(label);
113
113
  if (!prev) {
114
114
  throw new Error(`No such label '${label}' for WebpackLogger.timeAggregate()`);
115
115
  }
@@ -7,9 +7,29 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
- /**
11
- * @param {LoggerOptions} options options object
12
- * @returns {function(string, LogTypeEnum, any[]): void} logging function
13
- */
14
- declare const _default: ({ level, debug, console }: any) => (name: any, type: any, args: any) => void;
15
- export = _default;
10
+ import type { FilterTypes } from "../config";
11
+ import { type LogTypeEnum } from "./Logger";
12
+ export type FilterFunction = (ident: string) => boolean;
13
+ export type LoggerConsole = {
14
+ clear: () => void;
15
+ trace: () => void;
16
+ info: (...args: any[]) => void;
17
+ log: (...args: any[]) => void;
18
+ warn: (...args: any[]) => void;
19
+ error: (...args: any[]) => void;
20
+ debug?: (...args: any[]) => void;
21
+ group?: (...args: any[]) => void;
22
+ groupCollapsed?: (...args: any[]) => void;
23
+ groupEnd?: (...args: any[]) => void;
24
+ status?: (...args: any[]) => void;
25
+ profile?: (...args: any[]) => void;
26
+ profileEnd?: (...args: any[]) => void;
27
+ logTime?: (...args: any[]) => void;
28
+ };
29
+ export type LoggerOptions = {
30
+ level: "none" | "error" | "warn" | "info" | "log" | "verbose" | boolean;
31
+ debug: FilterTypes | boolean;
32
+ console: LoggerConsole;
33
+ };
34
+ declare const createConsoleLogger: ({ level, debug, console }: LoggerOptions) => (name: string, type: LogTypeEnum, args: any[]) => void;
35
+ export { createConsoleLogger };