@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
@@ -1,90 +1,101 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
1
  "use strict";
6
- const { forEachBail } = require("../../compiled/enhanced-resolve");
7
- const asyncLib = require("../../compiled/neo-async");
8
- const getLazyHashedEtag = require("./cache/getLazyHashedEtag.js");
9
- const mergeEtags = require("./cache/mergeEtags.js");
10
- /** @typedef {import("./Cache")} Cache */
11
- /** @typedef {import("./Cache").Etag} Etag */
12
- /** @typedef {import("./WebpackError")} WebpackError */
13
- /** @typedef {import("./cache/getLazyHashedEtag").HashableObject} HashableObject */
14
- // /** @typedef {typeof import("./util/Hash")} HashConstructor */
15
- /** @typedef {any} HashConstructor */
16
2
  /**
17
- * @template T
18
- * @callback CallbackCache
19
- * @param {(WebpackError | null)=} err
20
- * @param {T=} result
21
- * @returns {void}
22
- */
23
- /**
24
- * @template T
25
- * @callback CallbackNormalErrorCache
26
- * @param {(Error | null)=} err
27
- * @param {T=} result
28
- * @returns {void}
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/CacheFacade.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
29
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.CacheFacade = exports.ItemCacheFacade = exports.MultiItemCache = void 0;
16
+ const neo_async_1 = __importDefault(require("../../compiled/neo-async"));
17
+ const getLazyHashedEtag_js_1 = require("./cache/getLazyHashedEtag.js");
18
+ const mergeEtags_js_1 = require("./cache/mergeEtags.js");
19
+ function forEachBail(array, iterator, callback) {
20
+ if (array.length === 0) {
21
+ callback();
22
+ return;
23
+ }
24
+ let i = 0;
25
+ const next = () => {
26
+ /** @type {boolean|undefined} */
27
+ let loop = undefined;
28
+ iterator(array[i++], (err, result) => {
29
+ if (err || result !== undefined || i >= array.length) {
30
+ return callback(err, result, i);
31
+ }
32
+ if (loop === false)
33
+ while (next())
34
+ ;
35
+ loop = true;
36
+ }, i);
37
+ if (!loop)
38
+ loop = false;
39
+ return loop;
40
+ };
41
+ while (next())
42
+ ;
43
+ }
44
+ class BaseCache {
45
+ }
30
46
  class MultiItemCache {
31
47
  /**
32
- * @param {ItemCacheFacade[]} items item caches
48
+ * @param items item caches
49
+ * @returns
33
50
  */
34
51
  constructor(items) {
35
52
  this._items = items;
36
53
  if (items.length === 1)
37
- return /** @type {any} */ (items[0]);
54
+ return items[0];
38
55
  }
39
56
  /**
40
- * @template T
41
- * @param {CallbackCache<T>} callback signals when the value is retrieved
42
- * @returns {void}
57
+ * @param callback signals when the value is retrieved
58
+ * @returns
43
59
  */
44
60
  get(callback) {
45
- // @ts-expect-error
46
61
  forEachBail(this._items, (item, callback) => item.get(callback), callback);
47
62
  }
48
63
  /**
49
- * @template T
50
- * @returns {Promise<T>} promise with the data
64
+ * @returns promise with the data
51
65
  */
52
66
  getPromise() {
53
- // @ts-expect-error
54
- const next = i => {
55
- // @ts-ignore if your typescript version >= 5.5, this line will throw an error
56
- return this._items[i].getPromise().then(result => {
57
- if (result !== undefined)
58
- return result;
59
- if (++i < this._items.length)
60
- return next(i);
61
- });
67
+ const next = async (i) => {
68
+ const result_1 = await this._items[i].getPromise();
69
+ if (result_1 !== undefined)
70
+ return result_1;
71
+ if (++i < this._items.length)
72
+ return next(i);
62
73
  };
63
74
  return next(0);
64
75
  }
65
76
  /**
66
- * @template T
67
- * @param {T} data the value to store
68
- * @param {CallbackCache<void>} callback signals when the value is stored
69
- * @returns {void}
77
+ * @param data the value to store
78
+ * @param callback signals when the value is stored
79
+ * @returns
70
80
  */
71
81
  store(data, callback) {
72
- asyncLib.each(this._items, (item, callback) => item.store(data, callback), callback);
82
+ neo_async_1.default.each(this._items, (item, callback) => item.store(data, callback), callback);
73
83
  }
74
84
  /**
75
- * @template T
76
- * @param {T} data the value to store
77
- * @returns {Promise<void>} promise signals when the value is stored
85
+ * @param data the value to store
86
+ * @returns promise signals when the value is stored
78
87
  */
79
- storePromise(data) {
80
- return Promise.all(this._items.map(item => item.storePromise(data))).then(() => { });
88
+ async storePromise(data) {
89
+ await Promise.all(this._items.map(item => item.storePromise(data)));
81
90
  }
82
91
  }
92
+ exports.MultiItemCache = MultiItemCache;
83
93
  class ItemCacheFacade {
84
94
  /**
85
- * @param {Cache} cache the root cache
86
- * @param {string} name the child cache item name
87
- * @param {Etag | null} etag the etag
95
+ * @param cache the root cache
96
+ * @param name the child cache item name
97
+ * @param etag the etag
98
+ * @returns
88
99
  */
89
100
  constructor(cache, name, etag) {
90
101
  this._cache = cache;
@@ -92,16 +103,14 @@ class ItemCacheFacade {
92
103
  this._etag = etag;
93
104
  }
94
105
  /**
95
- * @template T
96
- * @param {CallbackCache<T>} callback signals when the value is retrieved
97
- * @returns {void}
106
+ * @param callback signals when the value is retrieved
107
+ * @returns
98
108
  */
99
109
  get(callback) {
100
110
  this._cache.get(this._name, this._etag, callback);
101
111
  }
102
112
  /**
103
- * @template T
104
- * @returns {Promise<T>} promise with the data
113
+ * @returns promise with the data
105
114
  */
106
115
  getPromise() {
107
116
  return new Promise((resolve, reject) => {
@@ -116,18 +125,16 @@ class ItemCacheFacade {
116
125
  });
117
126
  }
118
127
  /**
119
- * @template T
120
- * @param {T} data the value to store
121
- * @param {CallbackCache<void>} callback signals when the value is stored
122
- * @returns {void}
128
+ * @param data the value to store
129
+ * @param callback signals when the value is stored
130
+ * @returns
123
131
  */
124
132
  store(data, callback) {
125
133
  this._cache.store(this._name, this._etag, data, callback);
126
134
  }
127
135
  /**
128
- * @template T
129
- * @param {T} data the value to store
130
- * @returns {Promise<void>} promise signals when the value is stored
136
+ * @param data the value to store
137
+ * @returns promise signals when the value is stored
131
138
  */
132
139
  storePromise(data) {
133
140
  return new Promise((resolve, reject) => {
@@ -142,10 +149,9 @@ class ItemCacheFacade {
142
149
  });
143
150
  }
144
151
  /**
145
- * @template T
146
- * @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
147
- * @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
148
- * @returns {void}
152
+ * @param computer function to compute the value if not cached
153
+ * @param callback signals when the value is retrieved
154
+ * @returns
149
155
  */
150
156
  provide(computer, callback) {
151
157
  this.get((err, cacheEntry) => {
@@ -165,9 +171,8 @@ class ItemCacheFacade {
165
171
  });
166
172
  }
167
173
  /**
168
- * @template T
169
- * @param {function(): Promise<T> | T} computer function to compute the value if not cached
170
- * @returns {Promise<T>} promise with the data
174
+ * @param computer function to compute the value if not cached
175
+ * @returns promise with the data
171
176
  */
172
177
  async providePromise(computer) {
173
178
  const cacheEntry = await this.getPromise();
@@ -178,11 +183,12 @@ class ItemCacheFacade {
178
183
  return result;
179
184
  }
180
185
  }
186
+ exports.ItemCacheFacade = ItemCacheFacade;
181
187
  class CacheFacade {
182
188
  /**
183
- * @param {Cache} cache the root cache
184
- * @param {string} name the child cache name
185
- * @param {string | HashConstructor} hashFunction the hash function to use
189
+ * @param cache the root cache
190
+ * @param name the child cache name
191
+ * @param hashFunction the hash function to use
186
192
  */
187
193
  constructor(cache, name, hashFunction) {
188
194
  this._cache = cache;
@@ -190,50 +196,48 @@ class CacheFacade {
190
196
  this._hashFunction = hashFunction;
191
197
  }
192
198
  /**
193
- * @param {string} name the child cache name#
194
- * @returns {CacheFacade} child cache
199
+ * @param name the child cache name#
200
+ * @returns child cache
195
201
  */
196
202
  getChildCache(name) {
197
203
  return new CacheFacade(this._cache, `${this._name}|${name}`, this._hashFunction);
198
204
  }
199
205
  /**
200
- * @param {string} identifier the cache identifier
201
- * @param {Etag | null} etag the etag
202
- * @returns {ItemCacheFacade} item cache
206
+ * @param identifier the cache identifier
207
+ * @param etag the etag
208
+ * @returns item cache
203
209
  */
204
210
  getItemCache(identifier, etag) {
205
211
  return new ItemCacheFacade(this._cache, `${this._name}|${identifier}`, etag);
206
212
  }
207
213
  /**
208
- * @param {HashableObject} obj an hashable object
209
- * @returns {Etag} an etag that is lazy hashed
214
+ * @param obj an hashable object
215
+ * @returns an etag that is lazy hashed
210
216
  */
211
217
  getLazyHashedEtag(obj) {
212
- return getLazyHashedEtag(obj, this._hashFunction);
218
+ return (0, getLazyHashedEtag_js_1.getter)(obj, this._hashFunction);
213
219
  }
214
220
  /**
215
- * @param {Etag} a an etag
216
- * @param {Etag} b another etag
217
- * @returns {Etag} an etag that represents both
221
+ * @param a an etag
222
+ * @param b another etag
223
+ * @returns an etag that represents both
218
224
  */
219
225
  mergeEtags(a, b) {
220
- return mergeEtags(a, b);
226
+ return (0, mergeEtags_js_1.mergeEtags)(a, b);
221
227
  }
222
228
  /**
223
- * @template T
224
- * @param {string} identifier the cache identifier
225
- * @param {Etag | null} etag the etag
226
- * @param {CallbackCache<T>} callback signals when the value is retrieved
227
- * @returns {void}
229
+ * @param identifier the cache identifier
230
+ * @param etag the etag
231
+ * @param callback signals when the value is retrieved
232
+ * @returns
228
233
  */
229
234
  get(identifier, etag, callback) {
230
235
  this._cache.get(`${this._name}|${identifier}`, etag, callback);
231
236
  }
232
237
  /**
233
- * @template T
234
- * @param {string} identifier the cache identifier
235
- * @param {Etag | null} etag the etag
236
- * @returns {Promise<T>} promise with the data
238
+ * @param identifier the cache identifier
239
+ * @param etag the etag
240
+ * @returns promise with the data
237
241
  */
238
242
  getPromise(identifier, etag) {
239
243
  return new Promise((resolve, reject) => {
@@ -248,22 +252,20 @@ class CacheFacade {
248
252
  });
249
253
  }
250
254
  /**
251
- * @template T
252
- * @param {string} identifier the cache identifier
253
- * @param {Etag | null} etag the etag
254
- * @param {T} data the value to store
255
- * @param {CallbackCache<void>} callback signals when the value is stored
256
- * @returns {void}
255
+ * @param identifier the cache identifier
256
+ * @param etag the etag
257
+ * @param data the value to store
258
+ * @param callback signals when the value is stored
259
+ * @returns
257
260
  */
258
261
  store(identifier, etag, data, callback) {
259
262
  this._cache.store(`${this._name}|${identifier}`, etag, data, callback);
260
263
  }
261
264
  /**
262
- * @template T
263
- * @param {string} identifier the cache identifier
264
- * @param {Etag | null} etag the etag
265
- * @param {T} data the value to store
266
- * @returns {Promise<void>} promise signals when the value is stored
265
+ * @param identifier the cache identifier
266
+ * @param etag the etag
267
+ * @param data the value to store
268
+ * @returns promise signals when the value is stored
267
269
  */
268
270
  storePromise(identifier, etag, data) {
269
271
  return new Promise((resolve, reject) => {
@@ -278,12 +280,11 @@ class CacheFacade {
278
280
  });
279
281
  }
280
282
  /**
281
- * @template T
282
- * @param {string} identifier the cache identifier
283
- * @param {Etag | null} etag the etag
284
- * @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
285
- * @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
286
- * @returns {void}
283
+ * @param identifier the cache identifier
284
+ * @param etag the etag
285
+ * @param computer function to compute the value if not cached
286
+ * @param callback signals when the value is retrieved
287
+ * @returns
287
288
  */
288
289
  provide(identifier, etag, computer, callback) {
289
290
  this.get(identifier, etag, (err, cacheEntry) => {
@@ -303,11 +304,10 @@ class CacheFacade {
303
304
  });
304
305
  }
305
306
  /**
306
- * @template T
307
- * @param {string} identifier the cache identifier
308
- * @param {Etag | null} etag the etag
309
- * @param {function(): Promise<T> | T} computer function to compute the value if not cached
310
- * @returns {Promise<T>} promise with the data
307
+ * @param identifier the cache identifier
308
+ * @param etag the etag
309
+ * @param computer function to compute the value if not cached
310
+ * @returns promise with the data
311
311
  */
312
312
  async providePromise(identifier, etag, computer) {
313
313
  const cacheEntry = await this.getPromise(identifier, etag);
@@ -318,6 +318,5 @@ class CacheFacade {
318
318
  return result;
319
319
  }
320
320
  }
321
- module.exports = CacheFacade;
322
- module.exports.ItemCacheFacade = ItemCacheFacade;
323
- module.exports.MultiItemCache = MultiItemCache;
321
+ exports.CacheFacade = CacheFacade;
322
+ exports.default = CacheFacade;
@@ -8,9 +8,26 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type { Compiler, EntryDescriptionNormalized, EntryNormalized } from "..";
11
- import { type EntryOptions } from "../builtin-plugin";
12
- export default class EntryOptionPlugin {
11
+ import type { EntryOptions } from "../builtin-plugin";
12
+ export declare class EntryOptionPlugin {
13
+ /**
14
+ * @param compiler the compiler instance one is tapping into
15
+ * @returns
16
+ */
13
17
  apply(compiler: Compiler): void;
18
+ /**
19
+ * @param compiler the compiler
20
+ * @param context context directory
21
+ * @param entry request
22
+ * @returns
23
+ */
14
24
  static applyEntryOption(compiler: Compiler, context: string, entry: EntryNormalized): void;
25
+ /**
26
+ * @param compiler the compiler
27
+ * @param name entry name
28
+ * @param desc entry description
29
+ * @returns options for the entry
30
+ */
15
31
  static entryDescriptionToOptions(compiler: Compiler, name: string, desc: EntryDescriptionNormalized): EntryOptions;
16
32
  }
33
+ export default EntryOptionPlugin;
@@ -12,15 +12,26 @@ 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
+ exports.EntryOptionPlugin = void 0;
15
16
  const node_assert_1 = __importDefault(require("node:assert"));
16
17
  const builtin_plugin_1 = require("../builtin-plugin");
17
18
  class EntryOptionPlugin {
19
+ /**
20
+ * @param compiler the compiler instance one is tapping into
21
+ * @returns
22
+ */
18
23
  apply(compiler) {
19
24
  compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
20
25
  EntryOptionPlugin.applyEntryOption(compiler, context, entry);
21
26
  return true;
22
27
  });
23
28
  }
29
+ /**
30
+ * @param compiler the compiler
31
+ * @param context context directory
32
+ * @param entry request
33
+ * @returns
34
+ */
24
35
  static applyEntryOption(compiler, context, entry) {
25
36
  if (typeof entry === "function") {
26
37
  new builtin_plugin_1.DynamicEntryPlugin(context, entry).apply(compiler);
@@ -36,12 +47,18 @@ class EntryOptionPlugin {
36
47
  }
37
48
  }
38
49
  }
50
+ /**
51
+ * @param compiler the compiler
52
+ * @param name entry name
53
+ * @param desc entry description
54
+ * @returns options for the entry
55
+ */
39
56
  static entryDescriptionToOptions(compiler, name, desc) {
40
57
  const options = {
41
58
  name,
42
59
  filename: desc.filename,
43
60
  runtime: desc.runtime,
44
- // layer: desc.layer,
61
+ layer: desc.layer,
45
62
  dependOn: desc.dependOn,
46
63
  baseUri: desc.baseUri,
47
64
  publicPath: desc.publicPath,
@@ -50,11 +67,9 @@ class EntryOptionPlugin {
50
67
  // wasmLoading: desc.wasmLoading,
51
68
  library: desc.library
52
69
  };
53
- // if (desc.layer !== undefined && !compiler.options.experiments.layers) {
54
- // throw new Error(
55
- // "'entryOptions.layer' is only allowed when 'experiments.layers' is enabled"
56
- // );
57
- // }
70
+ if (desc.layer !== undefined && !compiler.options.experiments.layers) {
71
+ throw new Error("'entryOptions.layer' is only allowed when 'experiments.layers' is enabled");
72
+ }
58
73
  // if (desc.chunkLoading) {
59
74
  // const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
60
75
  // EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
@@ -70,4 +85,5 @@ class EntryOptionPlugin {
70
85
  return options;
71
86
  }
72
87
  }
88
+ exports.EntryOptionPlugin = EntryOptionPlugin;
73
89
  exports.default = EntryOptionPlugin;
@@ -1,15 +1,22 @@
1
- export type Compiler = any;
2
- export type CodeValue = any;
3
- /** @typedef {any} Compiler */
4
- /** @typedef {any} CodeValue */
5
- export class EnvironmentPlugin {
6
- constructor(...keys: any[]);
7
- keys: any[];
8
- defaultValues: any;
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/EnvironmentPlugin.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 type { Compiler } from "../Compiler";
11
+ declare class EnvironmentPlugin {
12
+ keys: string[];
13
+ defaultValues: Record<string, string>;
14
+ constructor(...keys: string[] | [Record<string, string> | string]);
9
15
  /**
10
16
  * Apply the plugin
11
- * @param {Compiler} compiler the compiler instance
12
- * @returns {void}
17
+ * @param compiler the compiler instance
18
+ * @returns
13
19
  */
14
20
  apply(compiler: Compiler): void;
15
21
  }
22
+ export { EnvironmentPlugin };
@@ -1,18 +1,21 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
4
- */
5
1
  "use strict";
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/EnvironmentPlugin.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
+ };
6
14
  Object.defineProperty(exports, "__esModule", { value: true });
7
15
  exports.EnvironmentPlugin = void 0;
8
16
  const builtin_plugin_1 = require("../builtin-plugin");
9
- const WebpackError = require("./WebpackError");
10
- // /** @typedef {import("./Compiler")} Compiler */
11
- // /** @typedef {import("./DefinePlugin").CodeValue} CodeValue */
12
- /** @typedef {any} Compiler */
13
- /** @typedef {any} CodeValue */
17
+ const WebpackError_1 = __importDefault(require("./WebpackError"));
14
18
  class EnvironmentPlugin {
15
- // @ts-expect-error
16
19
  constructor(...keys) {
17
20
  if (keys.length === 1 && Array.isArray(keys[0])) {
18
21
  this.keys = keys[0];
@@ -29,20 +32,18 @@ class EnvironmentPlugin {
29
32
  }
30
33
  /**
31
34
  * Apply the plugin
32
- * @param {Compiler} compiler the compiler instance
33
- * @returns {void}
35
+ * @param compiler the compiler instance
36
+ * @returns
34
37
  */
35
38
  apply(compiler) {
36
- /** @type {Record<string, CodeValue>} */
37
39
  const definitions = {};
38
40
  for (const key of this.keys) {
39
41
  const value = process.env[key] !== undefined
40
42
  ? process.env[key]
41
43
  : this.defaultValues[key];
42
44
  if (value === undefined) {
43
- // @ts-expect-error
44
45
  compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
45
- const error = new WebpackError(`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
46
+ const error = new WebpackError_1.default(`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
46
47
  "You can pass an object with default values to suppress this warning.\n" +
47
48
  "See https://webpack.js.org/plugins/environment-plugin for example.");
48
49
  error.name = "EnvVariableNotDefinedError";
@@ -1,46 +1,40 @@
1
- export = HookWebpackError;
2
- /** @typedef {any} Module */
3
1
  /**
4
- * @template T
5
- * @callback Callback
6
- * @param {Error=} err
7
- * @param {T=} stats
8
- * @returns {void}
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/HookWebpackError.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
9
  */
10
- declare class HookWebpackError extends WebpackError {
10
+ import type { Callback } from "@rspack/lite-tapable";
11
+ import WebpackError from "./WebpackError";
12
+ export declare class HookWebpackError extends WebpackError {
13
+ hook: string;
14
+ error: Error;
11
15
  /**
12
16
  * Creates an instance of HookWebpackError.
13
- * @param {Error} error inner error
14
- * @param {string} hook name of hook
17
+ * @param error inner error
18
+ * @param hook name of hook
15
19
  */
16
20
  constructor(error: Error, hook: string);
17
- hook: string;
18
- error: Error;
19
- details: string;
20
- }
21
- declare namespace HookWebpackError {
22
- export { makeWebpackError, makeWebpackErrorCallback, tryRunOrWebpackError, Module, Callback };
23
21
  }
24
- import WebpackError = require("./WebpackError.js");
22
+ export default HookWebpackError;
25
23
  /**
26
- * @param {Error} error an error
27
- * @param {string} hook name of the hook
28
- * @returns {WebpackError} a webpack error
24
+ * @param error an error
25
+ * @param hook name of the hook
26
+ * @returns a webpack error
29
27
  */
30
- declare function makeWebpackError(error: Error, hook: string): WebpackError;
28
+ export declare const makeWebpackError: (error: Error, hook: string) => WebpackError;
31
29
  /**
32
- * @template T
33
- * @param {function((WebpackError | null)=, T=): void} callback webpack error callback
34
- * @param {string} hook name of hook
35
- * @returns {Callback<T>} generic callback
30
+ * @param callback webpack error callback
31
+ * @param hook name of hook
32
+ * @returns generic callback
36
33
  */
37
- declare function makeWebpackErrorCallback<T>(callback: (arg0?: (WebpackError | null) | undefined, arg1?: T | undefined) => void, hook: string): Callback<T>;
34
+ export declare const makeWebpackErrorCallback: <T>(callback: (error?: WebpackError | null, result?: T | undefined) => void, hook: string) => Callback<Error, T>;
38
35
  /**
39
- * @template T
40
- * @param {function(): T} fn function which will be wrapping in try catch
41
- * @param {string} hook name of hook
42
- * @returns {T} the result
36
+ * @param fn function which will be wrapping in try catch
37
+ * @param hook name of hook
38
+ * @returns the result
43
39
  */
44
- declare function tryRunOrWebpackError<T>(fn: () => T, hook: string): T;
45
- type Module = any;
46
- type Callback<T> = (err?: Error | undefined, stats?: T | undefined) => void;
40
+ export declare const tryRunOrWebpackError: <T>(fn: () => T, hook: string) => T;