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

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 (115) hide show
  1. package/dist/Compilation.d.ts +1 -1
  2. package/dist/Compiler.d.ts +11 -10
  3. package/dist/Compiler.js +14 -14
  4. package/dist/Module.d.ts +1 -0
  5. package/dist/Module.js +1 -0
  6. package/dist/NormalModule.d.ts +1 -0
  7. package/dist/NormalModule.js +1 -0
  8. package/dist/builtin-plugin/APIPlugin.d.ts +1 -1
  9. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
  10. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
  11. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
  12. package/dist/builtin-plugin/BannerPlugin.d.ts +31 -31
  13. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
  14. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
  15. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
  16. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
  17. package/dist/builtin-plugin/CssModulesPlugin.d.ts +1 -1
  18. package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
  19. package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
  20. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
  21. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
  22. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +1 -1
  23. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
  24. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +1 -1
  25. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +1 -1
  26. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
  27. package/dist/builtin-plugin/EntryPlugin.d.ts +3 -2
  28. package/dist/builtin-plugin/EntryPlugin.js +1 -0
  29. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
  30. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
  31. package/dist/builtin-plugin/ExternalsPlugin.d.ts +5 -5
  32. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +1 -1
  33. package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
  34. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
  35. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
  36. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +9 -9
  37. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
  38. package/dist/builtin-plugin/IgnorePlugin.d.ts +1 -1
  39. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
  40. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +1 -1
  41. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
  42. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +4 -11
  43. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
  44. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
  46. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
  47. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
  48. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
  49. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
  50. package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +1 -1
  51. package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +1 -1
  52. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
  53. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  54. package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
  55. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
  56. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
  57. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +1 -1
  58. package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
  59. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
  60. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +1 -1
  61. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
  62. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
  63. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
  64. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
  65. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
  66. package/dist/builtin-plugin/base.d.ts +1 -1
  67. package/dist/builtin-plugin/css-extract/loader.d.ts +8 -3
  68. package/dist/builtin-plugin/css-extract/loader.js +24 -13
  69. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +1 -1
  70. package/dist/config/adapter.js +15 -2
  71. package/dist/config/adapterRuleUse.js +3 -3
  72. package/dist/config/defaults.js +7 -10
  73. package/dist/config/normalization.d.ts +6 -3
  74. package/dist/config/normalization.js +2 -0
  75. package/dist/config/zod.d.ts +1224 -1055
  76. package/dist/config/zod.js +10 -1
  77. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  78. package/dist/container/ModuleFederationRuntimePlugin.d.ts +1 -1
  79. package/dist/exports.d.ts +1 -1
  80. package/dist/lib/AbstractMethodError.d.ts +12 -3
  81. package/dist/lib/AbstractMethodError.js +29 -21
  82. package/dist/lib/Cache.d.ts +40 -46
  83. package/dist/lib/Cache.js +43 -78
  84. package/dist/lib/CacheFacade.d.ts +119 -143
  85. package/dist/lib/CacheFacade.js +123 -124
  86. package/dist/lib/EntryOptionPlugin.d.ts +19 -2
  87. package/dist/lib/EntryOptionPlugin.js +22 -6
  88. package/dist/lib/EnvironmentPlugin.d.ts +17 -10
  89. package/dist/lib/EnvironmentPlugin.js +16 -15
  90. package/dist/lib/HookWebpackError.d.ts +27 -33
  91. package/dist/lib/HookWebpackError.js +33 -34
  92. package/dist/lib/IgnoreWarningsPlugin.d.ts +25 -0
  93. package/dist/lib/{ignoreWarningsPlugin.js → IgnoreWarningsPlugin.js} +17 -0
  94. package/dist/lib/LoaderOptionsPlugin.d.ts +18 -9
  95. package/dist/lib/LoaderOptionsPlugin.js +38 -14
  96. package/dist/lib/LoaderTargetPlugin.d.ts +17 -8
  97. package/dist/lib/LoaderTargetPlugin.js +17 -15
  98. package/dist/lib/ModuleFilenameHelpers.d.ts +10 -1
  99. package/dist/lib/ModuleFilenameHelpers.js +9 -0
  100. package/dist/lib/NormalModuleReplacementPlugin.d.ts +15 -5
  101. package/dist/lib/NormalModuleReplacementPlugin.js +15 -5
  102. package/dist/lib/WebpackError.d.ts +29 -22
  103. package/dist/lib/WebpackError.js +17 -29
  104. package/dist/lib/cache/getLazyHashedEtag.d.ts +24 -24
  105. package/dist/lib/cache/getLazyHashedEtag.js +20 -23
  106. package/dist/lib/cache/mergeEtags.d.ts +15 -9
  107. package/dist/lib/cache/mergeEtags.js +18 -11
  108. package/dist/lib/formatLocation.d.ts +13 -8
  109. package/dist/lib/formatLocation.js +17 -15
  110. package/dist/rspackOptionsApply.js +2 -2
  111. package/dist/stats/DefaultStatsFactoryPlugin.js +1 -1
  112. package/dist/util/comparators.d.ts +1 -1
  113. package/package.json +3 -3
  114. package/compiled/enhanced-resolve/index.js +0 -5566
  115. package/dist/lib/ignoreWarningsPlugin.d.ts +0 -7
@@ -93,6 +93,7 @@ const libraryOptions = zod_1.z.strictObject({
93
93
  umdNamedDefine: umdNamedDefine.optional()
94
94
  });
95
95
  const library = libraryName.or(libraryOptions).optional();
96
+ const layer = zod_1.z.string().or(zod_1.z.null());
96
97
  const entryFilename = filename;
97
98
  const entryRuntime = zod_1.z.literal(false).or(zod_1.z.string());
98
99
  const entryItem = zod_1.z.string().or(zod_1.z.array(zod_1.z.string()));
@@ -107,7 +108,8 @@ const entryDescription = zod_1.z.strictObject({
107
108
  wasmLoading: wasmLoading.optional(),
108
109
  filename: entryFilename.optional(),
109
110
  library: libraryOptions.optional(),
110
- dependOn: entryDependOn.optional()
111
+ dependOn: entryDependOn.optional(),
112
+ layer: layer.optional()
111
113
  });
112
114
  const entryUnnamed = entryItem;
113
115
  const entryObject = zod_1.z.record(entryItem.or(entryDescription));
@@ -138,6 +140,7 @@ const strictModuleErrorHandling = zod_1.z.boolean();
138
140
  const globalObject = zod_1.z.string();
139
141
  const enabledWasmLoadingTypes = zod_1.z.array(wasmLoadingType);
140
142
  const importFunctionName = zod_1.z.string();
143
+ const importMetaName = zod_1.z.string();
141
144
  const iife = zod_1.z.boolean();
142
145
  const enabledChunkLoadingTypes = zod_1.z.array(chunkLoadingType);
143
146
  const chunkFormat = zod_1.z.literal(false).or(zod_1.z.string());
@@ -199,6 +202,7 @@ const output = zod_1.z.strictObject({
199
202
  strictModuleErrorHandling: strictModuleErrorHandling.optional(),
200
203
  globalObject: globalObject.optional(),
201
204
  importFunctionName: importFunctionName.optional(),
205
+ importMetaName: importMetaName.optional(),
202
206
  iife: iife.optional(),
203
207
  wasmLoading: wasmLoading.optional(),
204
208
  enabledWasmLoadingTypes: enabledWasmLoadingTypes.optional(),
@@ -291,6 +295,7 @@ const baseRuleSetRule = zod_1.z.strictObject({
291
295
  exclude: ruleSetCondition.optional(),
292
296
  include: ruleSetCondition.optional(),
293
297
  issuer: ruleSetCondition.optional(),
298
+ issuerLayer: ruleSetCondition.optional(),
294
299
  dependency: ruleSetCondition.optional(),
295
300
  resource: ruleSetCondition.optional(),
296
301
  resourceFragment: ruleSetCondition.optional(),
@@ -298,7 +303,9 @@ const baseRuleSetRule = zod_1.z.strictObject({
298
303
  scheme: ruleSetCondition.optional(),
299
304
  mimetype: ruleSetCondition.optional(),
300
305
  descriptionData: zod_1.z.record(ruleSetCondition).optional(),
306
+ with: zod_1.z.record(ruleSetCondition).optional(),
301
307
  type: zod_1.z.string().optional(),
308
+ layer: zod_1.z.string().optional(),
302
309
  loader: ruleSetLoader.optional(),
303
310
  options: ruleSetLoaderOptions.optional(),
304
311
  use: ruleSetUse.optional(),
@@ -352,6 +359,7 @@ const javascriptParserOptions = zod_1.z.strictObject({
352
359
  dynamicImportPreload: dynamicImportPreload.optional(),
353
360
  dynamicImportPrefetch: dynamicImportPrefetch.optional(),
354
361
  dynamicImportFetchPriority: dynamicImportFetchPriority.optional(),
362
+ importMeta: zod_1.z.boolean().optional(),
355
363
  url: javascriptParserUrl.optional(),
356
364
  exprContextCritical: exprContextCritical.optional(),
357
365
  wrappedContextCritical: wrappedContextCritical.optional(),
@@ -857,6 +865,7 @@ const experiments = zod_1.z.strictObject({
857
865
  outputModule: zod_1.z.boolean().optional(),
858
866
  topLevelAwait: zod_1.z.boolean().optional(),
859
867
  css: zod_1.z.boolean().optional(),
868
+ layers: zod_1.z.boolean().optional(),
860
869
  futureDefaults: zod_1.z.boolean().optional(),
861
870
  rspackFuture: rspackFutureOptions.optional()
862
871
  });
@@ -21,7 +21,7 @@ export type RemotesConfig = {
21
21
  export declare class ContainerReferencePlugin extends RspackBuiltinPlugin {
22
22
  name: BuiltinPluginName;
23
23
  _options: {
24
- remoteType: "promise" | "module" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs";
24
+ remoteType: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs";
25
25
  remotes: [string, {
26
26
  external: string[];
27
27
  shareScope: string;
@@ -3,7 +3,7 @@ export declare const ModuleFederationRuntimePlugin: {
3
3
  new (): {
4
4
  name: BuiltinPluginName;
5
5
  _args: [];
6
- affectedHooks: "done" | "compilation" | "failed" | "environment" | "emit" | "make" | "compile" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "shutdown" | "watchRun" | "watchClose" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
6
+ 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;
7
7
  raw(compiler: import("../Compiler").Compiler): import("@rspack/binding").BuiltinPlugin;
8
8
  apply(compiler: import("../Compiler").Compiler): void;
9
9
  };
package/dist/exports.d.ts CHANGED
@@ -33,7 +33,7 @@ type Config = {
33
33
  export declare const config: Config;
34
34
  export type * from "./config";
35
35
  export declare const util: {
36
- createHash: (algorithm: "debug" | "md4" | "xxhash64" | (string & {}) | "native-md4" | (new () => import("./util/hash").default)) => import("./util/hash").default;
36
+ createHash: (algorithm: (string & {}) | "debug" | "xxhash64" | "md4" | "native-md4" | (new () => import("./util/hash").default)) => import("./util/hash").default;
37
37
  cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
38
38
  };
39
39
  export { default as EntryOptionPlugin } from "./lib/EntryOptionPlugin";
@@ -1,4 +1,13 @@
1
- export = AbstractMethodError;
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/AbstractMethodError.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
9
+ */
10
+ import WebpackError from "./WebpackError";
2
11
  /**
3
12
  * Error for abstract method
4
13
  * @example
@@ -9,7 +18,7 @@ export = AbstractMethodError;
9
18
  * }
10
19
  *
11
20
  */
12
- declare class AbstractMethodError extends WebpackError {
21
+ export declare class AbstractMethodError extends WebpackError {
13
22
  constructor();
14
23
  }
15
- import WebpackError = require("./WebpackError");
24
+ export default AbstractMethodError;
@@ -1,29 +1,36 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Ivan Kopeykin @vankop
4
- */
5
1
  "use strict";
6
- const WebpackError = require("./WebpackError");
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/AbstractMethodError.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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AbstractMethodError = void 0;
16
+ const WebpackError_1 = __importDefault(require("./WebpackError"));
7
17
  const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
8
18
  /**
9
- * @param {string=} method method name
10
- * @returns {string} message
19
+ * @param method method name
20
+ * @returns message
11
21
  */
12
22
  function createMessage(method) {
13
23
  return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
14
24
  }
15
- /**
16
- * @constructor
17
- */
18
- function Message() {
19
- /** @type {string} */
20
- // @ts-expect-error
21
- this.stack = undefined;
22
- Error.captureStackTrace(this);
23
- /** @type {RegExpMatchArray} */
24
- // @ts-expect-error
25
- const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);
26
- this.message = match && match[1] ? createMessage(match[1]) : createMessage();
25
+ class Message extends Error {
26
+ constructor() {
27
+ super();
28
+ this.stack = undefined;
29
+ Error.captureStackTrace(this);
30
+ const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);
31
+ this.message =
32
+ match && match[1] ? createMessage(match[1]) : createMessage();
33
+ }
27
34
  }
28
35
  /**
29
36
  * Error for abstract method
@@ -35,10 +42,11 @@ function Message() {
35
42
  * }
36
43
  *
37
44
  */
38
- class AbstractMethodError extends WebpackError {
45
+ class AbstractMethodError extends WebpackError_1.default {
39
46
  constructor() {
40
47
  super(new Message().message);
41
48
  this.name = "AbstractMethodError";
42
49
  }
43
50
  }
44
- module.exports = AbstractMethodError;
51
+ exports.AbstractMethodError = AbstractMethodError;
52
+ exports.default = AbstractMethodError;
@@ -1,71 +1,65 @@
1
- export = Cache;
2
- declare class Cache {
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/Cache.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
9
+ */
10
+ import { AsyncParallelHook, AsyncSeriesBailHook, SyncHook } from "@rspack/lite-tapable";
11
+ import type { WebpackError } from "./WebpackError";
12
+ export interface Etag {
13
+ toString(): string;
14
+ }
15
+ export type CallbackCache<T> = (err?: WebpackError | null, result?: T) => void;
16
+ type GotHandler<T = any> = (result: any | null, callback: (error: Error) => void) => void;
17
+ export declare class Cache {
18
+ static STAGE_DISK: number;
19
+ static STAGE_MEMORY: number;
20
+ static STAGE_DEFAULT: number;
21
+ static STAGE_NETWORK: number;
3
22
  hooks: {
4
- /** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], any>} */
5
23
  get: AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], any>;
6
- /** @type {AsyncParallelHook<[string, Etag | null, any]>} */
7
24
  store: AsyncParallelHook<[string, Etag | null, any]>;
8
- /** @type {AsyncParallelHook<[Iterable<string>]>} */
9
25
  storeBuildDependencies: AsyncParallelHook<[Iterable<string>]>;
10
- /** @type {SyncHook<[]>} */
11
26
  beginIdle: SyncHook<[]>;
12
- /** @type {AsyncParallelHook<[]>} */
13
27
  endIdle: AsyncParallelHook<[]>;
14
- /** @type {AsyncParallelHook<[]>} */
15
28
  shutdown: AsyncParallelHook<[]>;
16
29
  };
30
+ constructor();
17
31
  /**
18
- * @template T
19
- * @param {string} identifier the cache identifier
20
- * @param {Etag | null} etag the etag
21
- * @param {CallbackCache<T>} callback signals when the value is retrieved
22
- * @returns {void}
32
+ * @param identifier the cache identifier
33
+ * @param etag the etag
34
+ * @param callback signals when the value is retrieved
35
+ * @returns
23
36
  */
24
37
  get<T>(identifier: string, etag: Etag | null, callback: CallbackCache<T>): void;
25
38
  /**
26
- * @template T
27
- * @param {string} identifier the cache identifier
28
- * @param {Etag | null} etag the etag
29
- * @param {T} data the value to store
30
- * @param {CallbackCache<void>} callback signals when the value is stored
31
- * @returns {void}
39
+ * @param identifier the cache identifier
40
+ * @param etag the etag
41
+ * @param data the value to store
42
+ * @param callback signals when the value is stored
43
+ * @returns
32
44
  */
33
- store<T_1>(identifier: string, etag: Etag | null, data: T_1, callback: CallbackCache<void>): void;
45
+ store<T>(identifier: string, etag: Etag | null, data: T, callback: CallbackCache<void>): void;
34
46
  /**
35
47
  * After this method has succeeded the cache can only be restored when build dependencies are
36
- * @param {Iterable<string>} dependencies list of all build dependencies
37
- * @param {CallbackCache<void>} callback signals when the dependencies are stored
38
- * @returns {void}
48
+ * @param dependencies list of all build dependencies
49
+ * @param callback signals when the dependencies are stored
50
+ * @returns
39
51
  */
40
52
  storeBuildDependencies(dependencies: Iterable<string>, callback: CallbackCache<void>): void;
41
- /**
42
- * @returns {void}
43
- */
44
53
  beginIdle(): void;
45
54
  /**
46
- * @param {CallbackCache<void>} callback signals when the call finishes
47
- * @returns {void}
55
+ * @param callback signals when the call finishes
56
+ * @returns
48
57
  */
49
58
  endIdle(callback: CallbackCache<void>): void;
50
59
  /**
51
- * @param {CallbackCache<void>} callback signals when the call finishes
52
- * @returns {void}
60
+ * @param callback signals when the call finishes
61
+ * @returns
53
62
  */
54
63
  shutdown(callback: CallbackCache<void>): void;
55
64
  }
56
- declare namespace Cache {
57
- export { STAGE_MEMORY, STAGE_DEFAULT, STAGE_DISK, STAGE_NETWORK, WebpackError, Etag, CallbackCache, GotHandler };
58
- }
59
- import { AsyncSeriesBailHook } from "@rspack/lite-tapable";
60
- type Etag = {
61
- toString: () => string;
62
- };
63
- type GotHandler = (result: any, callback: (arg0: Error | undefined) => void) => void;
64
- import { AsyncParallelHook } from "@rspack/lite-tapable";
65
- import { SyncHook } from "@rspack/lite-tapable";
66
- type CallbackCache<T> = (err?: (WebpackError | null) | undefined, result?: T | undefined) => void;
67
- declare var STAGE_MEMORY: number;
68
- declare var STAGE_DEFAULT: number;
69
- declare var STAGE_DISK: number;
70
- declare var STAGE_NETWORK: number;
71
- type WebpackError = import("./WebpackError");
65
+ export default Cache;
package/dist/lib/Cache.js CHANGED
@@ -1,72 +1,50 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
1
  "use strict";
6
- const { AsyncParallelHook, AsyncSeriesBailHook, SyncHook } = require("@rspack/lite-tapable");
7
- const { makeWebpackError, makeWebpackErrorCallback } = require("./HookWebpackError.js");
8
- /** @typedef {import("./WebpackError")} WebpackError */
9
2
  /**
10
- * @typedef {Object} Etag
11
- * @property {function(): string} toString
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/Cache.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
12
10
  */
13
- /**
14
- * @template T
15
- * @callback CallbackCache
16
- * @param {(WebpackError | null)=} err
17
- * @param {T=} result
18
- * @returns {void}
19
- */
20
- /**
21
- * @callback GotHandler
22
- * @param {any} result
23
- * @param {function(Error=): void} callback
24
- * @returns {void}
25
- */
26
- // @ts-expect-error
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Cache = void 0;
13
+ const lite_tapable_1 = require("@rspack/lite-tapable");
14
+ const HookWebpackError_1 = require("./HookWebpackError");
27
15
  const needCalls = (times, callback) => {
28
- // @ts-expect-error
29
16
  return err => {
30
17
  if (--times === 0) {
31
- return callback(err);
18
+ return callback();
32
19
  }
33
20
  if (err && times > 0) {
34
21
  times = 0;
35
- return callback(err);
22
+ return callback();
36
23
  }
37
24
  };
38
25
  };
39
26
  class Cache {
40
27
  constructor() {
41
28
  this.hooks = {
42
- /** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], any>} */
43
- get: new AsyncSeriesBailHook(["identifier", "etag", "gotHandlers"]),
44
- /** @type {AsyncParallelHook<[string, Etag | null, any]>} */
45
- store: new AsyncParallelHook(["identifier", "etag", "data"]),
46
- /** @type {AsyncParallelHook<[Iterable<string>]>} */
47
- storeBuildDependencies: new AsyncParallelHook(["dependencies"]),
48
- /** @type {SyncHook<[]>} */
49
- beginIdle: new SyncHook([]),
50
- /** @type {AsyncParallelHook<[]>} */
51
- endIdle: new AsyncParallelHook([]),
52
- /** @type {AsyncParallelHook<[]>} */
53
- shutdown: new AsyncParallelHook([])
29
+ get: new lite_tapable_1.AsyncSeriesBailHook(["identifier", "etag", "gotHandlers"]),
30
+ store: new lite_tapable_1.AsyncParallelHook(["identifier", "etag", "data"]),
31
+ storeBuildDependencies: new lite_tapable_1.AsyncParallelHook(["dependencies"]),
32
+ beginIdle: new lite_tapable_1.SyncHook([]),
33
+ endIdle: new lite_tapable_1.AsyncParallelHook([]),
34
+ shutdown: new lite_tapable_1.AsyncParallelHook([])
54
35
  };
55
36
  }
56
37
  /**
57
- * @template T
58
- * @param {string} identifier the cache identifier
59
- * @param {Etag | null} etag the etag
60
- * @param {CallbackCache<T>} callback signals when the value is retrieved
61
- * @returns {void}
38
+ * @param identifier the cache identifier
39
+ * @param etag the etag
40
+ * @param callback signals when the value is retrieved
41
+ * @returns
62
42
  */
63
43
  get(identifier, etag, callback) {
64
- // @ts-expect-error
65
44
  const gotHandlers = [];
66
- // @ts-expect-error
67
45
  this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
68
46
  if (err) {
69
- callback(makeWebpackError(err, "Cache.hooks.get"));
47
+ callback((0, HookWebpackError_1.makeWebpackError)(err, "Cache.hooks.get"));
70
48
  return;
71
49
  }
72
50
  if (result === null) {
@@ -74,13 +52,11 @@ class Cache {
74
52
  }
75
53
  if (gotHandlers.length > 1) {
76
54
  const innerCallback = needCalls(gotHandlers.length, () => callback(null, result));
77
- // @ts-expect-error
78
55
  for (const gotHandler of gotHandlers) {
79
56
  gotHandler(result, innerCallback);
80
57
  }
81
58
  }
82
59
  else if (gotHandlers.length === 1) {
83
- // @ts-expect-error
84
60
  gotHandlers[0](result, () => callback(null, result));
85
61
  }
86
62
  else {
@@ -89,56 +65,45 @@ class Cache {
89
65
  });
90
66
  }
91
67
  /**
92
- * @template T
93
- * @param {string} identifier the cache identifier
94
- * @param {Etag | null} etag the etag
95
- * @param {T} data the value to store
96
- * @param {CallbackCache<void>} callback signals when the value is stored
97
- * @returns {void}
68
+ * @param identifier the cache identifier
69
+ * @param etag the etag
70
+ * @param data the value to store
71
+ * @param callback signals when the value is stored
72
+ * @returns
98
73
  */
99
74
  store(identifier, etag, data, callback) {
100
- this.hooks.store.callAsync(identifier, etag, data,
101
- // @ts-expect-error
102
- makeWebpackErrorCallback(callback, "Cache.hooks.store"));
75
+ this.hooks.store.callAsync(identifier, etag, data, (0, HookWebpackError_1.makeWebpackErrorCallback)(callback, "Cache.hooks.store"));
103
76
  }
104
77
  /**
105
78
  * After this method has succeeded the cache can only be restored when build dependencies are
106
- * @param {Iterable<string>} dependencies list of all build dependencies
107
- * @param {CallbackCache<void>} callback signals when the dependencies are stored
108
- * @returns {void}
79
+ * @param dependencies list of all build dependencies
80
+ * @param callback signals when the dependencies are stored
81
+ * @returns
109
82
  */
110
83
  storeBuildDependencies(dependencies, callback) {
111
- this.hooks.storeBuildDependencies.callAsync(dependencies,
112
- // @ts-expect-error
113
- makeWebpackErrorCallback(callback, "Cache.hooks.storeBuildDependencies"));
84
+ this.hooks.storeBuildDependencies.callAsync(dependencies, (0, HookWebpackError_1.makeWebpackErrorCallback)(callback, "Cache.hooks.storeBuildDependencies"));
114
85
  }
115
- /**
116
- * @returns {void}
117
- */
118
86
  beginIdle() {
119
87
  this.hooks.beginIdle.call();
120
88
  }
121
89
  /**
122
- * @param {CallbackCache<void>} callback signals when the call finishes
123
- * @returns {void}
90
+ * @param callback signals when the call finishes
91
+ * @returns
124
92
  */
125
93
  endIdle(callback) {
126
- this.hooks.endIdle.callAsync(
127
- // @ts-expect-error
128
- makeWebpackErrorCallback(callback, "Cache.hooks.endIdle"));
94
+ this.hooks.endIdle.callAsync((0, HookWebpackError_1.makeWebpackErrorCallback)(callback, "Cache.hooks.endIdle"));
129
95
  }
130
96
  /**
131
- * @param {CallbackCache<void>} callback signals when the call finishes
132
- * @returns {void}
97
+ * @param callback signals when the call finishes
98
+ * @returns
133
99
  */
134
100
  shutdown(callback) {
135
- this.hooks.shutdown.callAsync(
136
- // @ts-expect-error
137
- makeWebpackErrorCallback(callback, "Cache.hooks.shutdown"));
101
+ this.hooks.shutdown.callAsync((0, HookWebpackError_1.makeWebpackErrorCallback)(callback, "Cache.hooks.shutdown"));
138
102
  }
139
103
  }
104
+ Cache.STAGE_DISK = 10;
140
105
  Cache.STAGE_MEMORY = -10;
141
106
  Cache.STAGE_DEFAULT = 0;
142
- Cache.STAGE_DISK = 10;
143
107
  Cache.STAGE_NETWORK = 20;
144
- module.exports = Cache;
108
+ exports.Cache = Cache;
109
+ exports.default = Cache;