webpack 5.69.1 → 5.70.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/lib/BannerPlugin.js +10 -4
- package/lib/CleanPlugin.js +64 -18
- package/lib/Compilation.js +41 -17
- package/lib/ContextModule.js +90 -26
- package/lib/ContextModuleFactory.js +65 -21
- package/lib/EntryOptionPlugin.js +1 -0
- package/lib/Generator.js +1 -0
- package/lib/ModuleHashingError.js +29 -0
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +21 -16
- package/lib/NormalModuleFactory.js +15 -8
- package/lib/ProgressPlugin.js +3 -4
- package/lib/RuntimeTemplate.js +1 -0
- package/lib/WebpackOptionsApply.js +2 -0
- package/lib/asset/AssetGenerator.js +119 -31
- package/lib/cache/ResolverCachePlugin.js +89 -28
- package/lib/config/browserslistTargetHandler.js +3 -5
- package/lib/config/normalization.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/LoaderPlugin.js +2 -0
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
- package/lib/schemes/HttpUriPlugin.js +44 -3
- package/lib/util/internalSerializables.js +2 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +15 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
- package/module.d.ts +15 -0
- package/package.json +2 -2
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +164 -73
package/lib/Generator.js
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
|
10
|
+
/** @typedef {import("./Module")} Module */
|
11
|
+
|
12
|
+
class ModuleHashingError extends WebpackError {
|
13
|
+
/**
|
14
|
+
* Create a new ModuleHashingError
|
15
|
+
* @param {Module} module related module
|
16
|
+
* @param {Error} error Original error
|
17
|
+
*/
|
18
|
+
constructor(module, error) {
|
19
|
+
super();
|
20
|
+
|
21
|
+
this.name = "ModuleHashingError";
|
22
|
+
this.error = error;
|
23
|
+
this.message = error.message;
|
24
|
+
this.details = error.stack;
|
25
|
+
this.module = module;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
module.exports = ModuleHashingError;
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -69,6 +69,16 @@ class NodeStuffPlugin {
|
|
69
69
|
);
|
70
70
|
}
|
71
71
|
});
|
72
|
+
parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
|
73
|
+
const dep = new ConstDependency(
|
74
|
+
RuntimeGlobals.global,
|
75
|
+
expr.range,
|
76
|
+
[RuntimeGlobals.global]
|
77
|
+
);
|
78
|
+
dep.loc = expr.loc;
|
79
|
+
parser.state.module.addPresentationalDependency(dep);
|
80
|
+
return false;
|
81
|
+
});
|
72
82
|
}
|
73
83
|
|
74
84
|
const setModuleConstant = (expressionName, fn, warning) => {
|
package/lib/NormalModule.js
CHANGED
@@ -50,6 +50,7 @@ const memoize = require("./util/memoize");
|
|
50
50
|
/** @typedef {import("webpack-sources").Source} Source */
|
51
51
|
/** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
|
52
52
|
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
|
53
|
+
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
53
54
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
54
55
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
55
56
|
/** @typedef {import("./Compiler")} Compiler */
|
@@ -194,6 +195,25 @@ makeSerializable(
|
|
194
195
|
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
195
196
|
*/
|
196
197
|
|
198
|
+
/**
|
199
|
+
* @typedef {Object} NormalModuleCreateData
|
200
|
+
* @property {string=} layer an optional layer in which the module is
|
201
|
+
* @property {string} type module type
|
202
|
+
* @property {string} request request string
|
203
|
+
* @property {string} userRequest request intended by user (without loaders from config)
|
204
|
+
* @property {string} rawRequest request without resolving
|
205
|
+
* @property {LoaderItem[]} loaders list of loaders
|
206
|
+
* @property {string} resource path + query of the real resource
|
207
|
+
* @property {Record<string, any>=} resourceResolveData resource resolve data
|
208
|
+
* @property {string} context context directory for resolving
|
209
|
+
* @property {string=} matchResource path + query of the matched resource (virtual)
|
210
|
+
* @property {Parser} parser the parser used
|
211
|
+
* @property {Record<string, any>=} parserOptions the options of the parser used
|
212
|
+
* @property {Generator} generator the generator used
|
213
|
+
* @property {Record<string, any>=} generatorOptions the options of the generator used
|
214
|
+
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
215
|
+
*/
|
216
|
+
|
197
217
|
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
|
198
218
|
const compilationHooksMap = new WeakMap();
|
199
219
|
|
@@ -246,22 +266,7 @@ class NormalModule extends Module {
|
|
246
266
|
}
|
247
267
|
|
248
268
|
/**
|
249
|
-
* @param {
|
250
|
-
* @param {string=} options.layer an optional layer in which the module is
|
251
|
-
* @param {string} options.type module type
|
252
|
-
* @param {string} options.request request string
|
253
|
-
* @param {string} options.userRequest request intended by user (without loaders from config)
|
254
|
-
* @param {string} options.rawRequest request without resolving
|
255
|
-
* @param {LoaderItem[]} options.loaders list of loaders
|
256
|
-
* @param {string} options.resource path + query of the real resource
|
257
|
-
* @param {Record<string, any>=} options.resourceResolveData resource resolve data
|
258
|
-
* @param {string} options.context context directory for resolving
|
259
|
-
* @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
|
260
|
-
* @param {Parser} options.parser the parser used
|
261
|
-
* @param {object} options.parserOptions the options of the parser used
|
262
|
-
* @param {Generator} options.generator the generator used
|
263
|
-
* @param {object} options.generatorOptions the options of the generator used
|
264
|
-
* @param {Object} options.resolveOptions options used for resolving requests from this module
|
269
|
+
* @param {NormalModuleCreateData} options options object
|
265
270
|
*/
|
266
271
|
constructor({
|
267
272
|
layer,
|
@@ -34,14 +34,19 @@ const {
|
|
34
34
|
} = require("./util/identifier");
|
35
35
|
|
36
36
|
/** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
37
|
+
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
37
38
|
/** @typedef {import("./Generator")} Generator */
|
38
39
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
39
40
|
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
41
|
+
/** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */
|
40
42
|
/** @typedef {import("./Parser")} Parser */
|
41
43
|
/** @typedef {import("./ResolverFactory")} ResolverFactory */
|
42
44
|
/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
|
43
45
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
44
46
|
|
47
|
+
/** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
|
48
|
+
/** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
|
49
|
+
|
45
50
|
/**
|
46
51
|
* @typedef {Object} ResolveData
|
47
52
|
* @property {ModuleFactoryCreateData["contextInfo"]} contextInfo
|
@@ -51,7 +56,7 @@ const {
|
|
51
56
|
* @property {Record<string, any> | undefined} assertions
|
52
57
|
* @property {ModuleDependency[]} dependencies
|
53
58
|
* @property {string} dependencyType
|
54
|
-
* @property {
|
59
|
+
* @property {CreateData} createData
|
55
60
|
* @property {LazySet<string>} fileDependencies
|
56
61
|
* @property {LazySet<string>} missingDependencies
|
57
62
|
* @property {LazySet<string>} contextDependencies
|
@@ -199,7 +204,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
199
204
|
}) {
|
200
205
|
super();
|
201
206
|
this.hooks = Object.freeze({
|
202
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
207
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
|
203
208
|
resolve: new AsyncSeriesBailHook(["resolveData"]),
|
204
209
|
/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
|
205
210
|
resolveForScheme: new HookMap(
|
@@ -209,15 +214,15 @@ class NormalModuleFactory extends ModuleFactory {
|
|
209
214
|
resolveInScheme: new HookMap(
|
210
215
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
211
216
|
),
|
212
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
217
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
|
213
218
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
214
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
219
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
|
215
220
|
beforeResolve: new AsyncSeriesBailHook(["resolveData"]),
|
216
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
221
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
|
217
222
|
afterResolve: new AsyncSeriesBailHook(["resolveData"]),
|
218
|
-
/** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData],
|
223
|
+
/** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
|
219
224
|
createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
|
220
|
-
/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData],
|
225
|
+
/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
|
221
226
|
module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
|
222
227
|
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
|
223
228
|
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
|
@@ -301,7 +306,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|
301
306
|
return callback(new Error("Empty dependency (no request)"));
|
302
307
|
}
|
303
308
|
|
304
|
-
createdModule = new NormalModule(
|
309
|
+
createdModule = new NormalModule(
|
310
|
+
/** @type {NormalModuleCreateData} */ (createData)
|
311
|
+
);
|
305
312
|
}
|
306
313
|
|
307
314
|
createdModule = this.hooks.module.call(
|
package/lib/ProgressPlugin.js
CHANGED
@@ -531,15 +531,14 @@ class ProgressPlugin {
|
|
531
531
|
}
|
532
532
|
});
|
533
533
|
interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
|
534
|
-
compiler.hooks.
|
534
|
+
compiler.hooks.beforeRun.intercept({
|
535
535
|
name: "ProgressPlugin",
|
536
536
|
call() {
|
537
537
|
handler(0, "");
|
538
538
|
}
|
539
539
|
});
|
540
|
-
interceptHook(compiler.hooks.
|
541
|
-
interceptHook(compiler.hooks.
|
542
|
-
interceptHook(compiler.hooks.run, 0.03, "setup", "run");
|
540
|
+
interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
|
541
|
+
interceptHook(compiler.hooks.run, 0.02, "setup", "run");
|
543
542
|
interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
|
544
543
|
interceptHook(
|
545
544
|
compiler.hooks.normalModuleFactory,
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -83,6 +83,7 @@ class RuntimeTemplate {
|
|
83
83
|
this.outputOptions = outputOptions || {};
|
84
84
|
this.requestShortener = requestShortener;
|
85
85
|
this.globalObject = getGlobalObject(outputOptions.globalObject);
|
86
|
+
this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
|
86
87
|
}
|
87
88
|
|
88
89
|
isIIFE() {
|
@@ -35,6 +35,7 @@ const ResolverCachePlugin = require("./cache/ResolverCachePlugin");
|
|
35
35
|
|
36
36
|
const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
|
37
37
|
const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
|
38
|
+
const ImportMetaContextPlugin = require("./dependencies/ImportMetaContextPlugin");
|
38
39
|
const ImportMetaPlugin = require("./dependencies/ImportMetaPlugin");
|
39
40
|
const ImportPlugin = require("./dependencies/ImportPlugin");
|
40
41
|
const LoaderPlugin = require("./dependencies/LoaderPlugin");
|
@@ -361,6 +362,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
361
362
|
new RequireEnsurePlugin().apply(compiler);
|
362
363
|
new RequireContextPlugin().apply(compiler);
|
363
364
|
new ImportPlugin().apply(compiler);
|
365
|
+
new ImportMetaContextPlugin().apply(compiler);
|
364
366
|
new SystemPlugin().apply(compiler);
|
365
367
|
new ImportMetaPlugin().apply(compiler);
|
366
368
|
new URLPlugin().apply(compiler);
|
@@ -113,6 +113,7 @@ const decodeDataUriContent = (encoding, content) => {
|
|
113
113
|
|
114
114
|
const JS_TYPES = new Set(["javascript"]);
|
115
115
|
const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]);
|
116
|
+
const DEFAULT_ENCODING = "base64";
|
116
117
|
|
117
118
|
class AssetGenerator extends Generator {
|
118
119
|
/**
|
@@ -131,6 +132,65 @@ class AssetGenerator extends Generator {
|
|
131
132
|
this.emit = emit;
|
132
133
|
}
|
133
134
|
|
135
|
+
/**
|
136
|
+
* @param {NormalModule} module module
|
137
|
+
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
138
|
+
* @returns {string} source file name
|
139
|
+
*/
|
140
|
+
getSourceFileName(module, runtimeTemplate) {
|
141
|
+
return makePathsRelative(
|
142
|
+
runtimeTemplate.compilation.compiler.context,
|
143
|
+
module.matchResource || module.resource,
|
144
|
+
runtimeTemplate.compilation.compiler.root
|
145
|
+
).replace(/^\.\//, "");
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* @param {NormalModule} module module
|
150
|
+
* @returns {string} mime type
|
151
|
+
*/
|
152
|
+
getMimeType(module) {
|
153
|
+
if (typeof this.dataUrlOptions === "function") {
|
154
|
+
throw new Error(
|
155
|
+
"This method must not be called when dataUrlOptions is a function"
|
156
|
+
);
|
157
|
+
}
|
158
|
+
|
159
|
+
let mimeType = this.dataUrlOptions.mimetype;
|
160
|
+
if (mimeType === undefined) {
|
161
|
+
const ext = path.extname(module.nameForCondition());
|
162
|
+
if (
|
163
|
+
module.resourceResolveData &&
|
164
|
+
module.resourceResolveData.mimetype !== undefined
|
165
|
+
) {
|
166
|
+
mimeType =
|
167
|
+
module.resourceResolveData.mimetype +
|
168
|
+
module.resourceResolveData.parameters;
|
169
|
+
} else if (ext) {
|
170
|
+
mimeType = mimeTypes.lookup(ext);
|
171
|
+
|
172
|
+
if (typeof mimeType !== "string") {
|
173
|
+
throw new Error(
|
174
|
+
"DataUrl can't be generated automatically, " +
|
175
|
+
`because there is no mimetype for "${ext}" in mimetype database. ` +
|
176
|
+
'Either pass a mimetype via "generator.mimetype" or ' +
|
177
|
+
'use type: "asset/resource" to create a resource file instead of a DataUrl'
|
178
|
+
);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
if (typeof mimeType !== "string") {
|
184
|
+
throw new Error(
|
185
|
+
"DataUrl can't be generated automatically. " +
|
186
|
+
'Either pass a mimetype via "generator.mimetype" or ' +
|
187
|
+
'use type: "asset/resource" to create a resource file instead of a DataUrl'
|
188
|
+
);
|
189
|
+
}
|
190
|
+
|
191
|
+
return mimeType;
|
192
|
+
}
|
193
|
+
|
134
194
|
/**
|
135
195
|
* @param {NormalModule} module module for which the code should be generated
|
136
196
|
* @param {GenerateContext} generateContext context for generate
|
@@ -170,31 +230,9 @@ class AssetGenerator extends Generator {
|
|
170
230
|
}
|
171
231
|
}
|
172
232
|
if (encoding === undefined) {
|
173
|
-
encoding =
|
174
|
-
}
|
175
|
-
let ext;
|
176
|
-
let mimeType = this.dataUrlOptions.mimetype;
|
177
|
-
if (mimeType === undefined) {
|
178
|
-
ext = path.extname(module.nameForCondition());
|
179
|
-
if (
|
180
|
-
module.resourceResolveData &&
|
181
|
-
module.resourceResolveData.mimetype !== undefined
|
182
|
-
) {
|
183
|
-
mimeType =
|
184
|
-
module.resourceResolveData.mimetype +
|
185
|
-
module.resourceResolveData.parameters;
|
186
|
-
} else if (ext) {
|
187
|
-
mimeType = mimeTypes.lookup(ext);
|
188
|
-
}
|
189
|
-
}
|
190
|
-
if (typeof mimeType !== "string") {
|
191
|
-
throw new Error(
|
192
|
-
"DataUrl can't be generated automatically, " +
|
193
|
-
`because there is no mimetype for "${ext}" in mimetype database. ` +
|
194
|
-
'Either pass a mimetype via "generator.mimetype" or ' +
|
195
|
-
'use type: "asset/resource" to create a resource file instead of a DataUrl'
|
196
|
-
);
|
233
|
+
encoding = DEFAULT_ENCODING;
|
197
234
|
}
|
235
|
+
const mimeType = this.getMimeType(module);
|
198
236
|
|
199
237
|
let encodedContent;
|
200
238
|
|
@@ -238,11 +276,10 @@ class AssetGenerator extends Generator {
|
|
238
276
|
runtimeTemplate.outputOptions.hashDigestLength
|
239
277
|
);
|
240
278
|
module.buildInfo.fullContentHash = fullHash;
|
241
|
-
const sourceFilename =
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
).replace(/^\.\//, "");
|
279
|
+
const sourceFilename = this.getSourceFileName(
|
280
|
+
module,
|
281
|
+
runtimeTemplate
|
282
|
+
);
|
246
283
|
let { path: filename, info: assetInfo } =
|
247
284
|
runtimeTemplate.compilation.getAssetPathWithInfo(
|
248
285
|
assetModuleFilename,
|
@@ -368,8 +405,59 @@ class AssetGenerator extends Generator {
|
|
368
405
|
* @param {Hash} hash hash that will be modified
|
369
406
|
* @param {UpdateHashContext} updateHashContext context for updating hash
|
370
407
|
*/
|
371
|
-
updateHash(hash, { module }) {
|
372
|
-
|
408
|
+
updateHash(hash, { module, runtime, runtimeTemplate, chunkGraph }) {
|
409
|
+
if (module.buildInfo.dataUrl) {
|
410
|
+
hash.update("data-url");
|
411
|
+
// this.dataUrlOptions as function should be pure and only depend on input source and filename
|
412
|
+
// therefore it doesn't need to be hashed
|
413
|
+
if (typeof this.dataUrlOptions === "function") {
|
414
|
+
const ident = /** @type {{ ident?: string }} */ (this.dataUrlOptions)
|
415
|
+
.ident;
|
416
|
+
if (ident) hash.update(ident);
|
417
|
+
} else {
|
418
|
+
if (
|
419
|
+
this.dataUrlOptions.encoding &&
|
420
|
+
this.dataUrlOptions.encoding !== DEFAULT_ENCODING
|
421
|
+
) {
|
422
|
+
hash.update(this.dataUrlOptions.encoding);
|
423
|
+
}
|
424
|
+
if (this.dataUrlOptions.mimetype)
|
425
|
+
hash.update(this.dataUrlOptions.mimetype);
|
426
|
+
// computed mimetype depends only on module filename which is already part of the hash
|
427
|
+
}
|
428
|
+
} else {
|
429
|
+
hash.update("resource");
|
430
|
+
|
431
|
+
const pathData = {
|
432
|
+
module,
|
433
|
+
runtime,
|
434
|
+
filename: this.getSourceFileName(module, runtimeTemplate),
|
435
|
+
chunkGraph,
|
436
|
+
contentHash: runtimeTemplate.contentHashReplacement
|
437
|
+
};
|
438
|
+
|
439
|
+
if (typeof this.publicPath === "function") {
|
440
|
+
hash.update("path");
|
441
|
+
const assetInfo = {};
|
442
|
+
hash.update(this.publicPath(pathData, assetInfo));
|
443
|
+
hash.update(JSON.stringify(assetInfo));
|
444
|
+
} else if (this.publicPath) {
|
445
|
+
hash.update("path");
|
446
|
+
hash.update(this.publicPath);
|
447
|
+
} else {
|
448
|
+
hash.update("no-path");
|
449
|
+
}
|
450
|
+
|
451
|
+
const assetModuleFilename =
|
452
|
+
this.filename || runtimeTemplate.outputOptions.assetModuleFilename;
|
453
|
+
const { path: filename, info } =
|
454
|
+
runtimeTemplate.compilation.getAssetPathWithInfo(
|
455
|
+
assetModuleFilename,
|
456
|
+
pathData
|
457
|
+
);
|
458
|
+
hash.update(filename);
|
459
|
+
hash.update(JSON.stringify(info));
|
460
|
+
}
|
373
461
|
}
|
374
462
|
}
|
375
463
|
|
@@ -128,6 +128,13 @@ class ResolverCachePlugin {
|
|
128
128
|
fileDependencies: new LazySet(),
|
129
129
|
contextDependencies: new LazySet()
|
130
130
|
};
|
131
|
+
let yieldResult;
|
132
|
+
let withYield = false;
|
133
|
+
if (typeof newResolveContext.yield === "function") {
|
134
|
+
yieldResult = [];
|
135
|
+
withYield = true;
|
136
|
+
newResolveContext.yield = obj => yieldResult.push(obj);
|
137
|
+
}
|
131
138
|
const propagate = key => {
|
132
139
|
if (resolveContext[key]) {
|
133
140
|
addAllToSet(resolveContext[key], newResolveContext[key]);
|
@@ -155,15 +162,22 @@ class ResolverCachePlugin {
|
|
155
162
|
snapshotOptions,
|
156
163
|
(err, snapshot) => {
|
157
164
|
if (err) return callback(err);
|
165
|
+
const resolveResult = withYield ? yieldResult : result;
|
166
|
+
// since we intercept resolve hook
|
167
|
+
// we still can get result in callback
|
168
|
+
if (withYield && result) yieldResult.push(result);
|
158
169
|
if (!snapshot) {
|
159
|
-
if (
|
170
|
+
if (resolveResult) return callback(null, resolveResult);
|
160
171
|
return callback();
|
161
172
|
}
|
162
|
-
itemCache.store(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
173
|
+
itemCache.store(
|
174
|
+
new CacheEntry(resolveResult, snapshot),
|
175
|
+
storeErr => {
|
176
|
+
if (storeErr) return callback(storeErr);
|
177
|
+
if (resolveResult) return callback(null, resolveResult);
|
178
|
+
callback();
|
179
|
+
}
|
180
|
+
);
|
167
181
|
}
|
168
182
|
);
|
169
183
|
}
|
@@ -173,6 +187,8 @@ class ResolverCachePlugin {
|
|
173
187
|
factory(type, hook) {
|
174
188
|
/** @type {Map<string, (function(Error=, Object=): void)[]>} */
|
175
189
|
const activeRequests = new Map();
|
190
|
+
/** @type {Map<string, [function(Error=, Object=): void, function(Error=, Object=): void][]>} */
|
191
|
+
const activeRequestsWithYield = new Map();
|
176
192
|
hook.tap(
|
177
193
|
"ResolverCachePlugin",
|
178
194
|
/**
|
@@ -197,29 +213,67 @@ class ResolverCachePlugin {
|
|
197
213
|
if (request._ResolverCachePluginCacheMiss || !fileSystemInfo) {
|
198
214
|
return callback();
|
199
215
|
}
|
200
|
-
const
|
201
|
-
|
202
|
-
|
203
|
-
)}`;
|
204
|
-
|
205
|
-
if (
|
206
|
-
activeRequest.
|
207
|
-
|
216
|
+
const withYield = typeof resolveContext.yield === "function";
|
217
|
+
const identifier = `${type}${
|
218
|
+
withYield ? "|yield" : "|default"
|
219
|
+
}${optionsIdent}${objectToString(request, !cacheWithContext)}`;
|
220
|
+
|
221
|
+
if (withYield) {
|
222
|
+
const activeRequest = activeRequestsWithYield.get(identifier);
|
223
|
+
if (activeRequest) {
|
224
|
+
activeRequest[0].push(callback);
|
225
|
+
activeRequest[1].push(resolveContext.yield);
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
} else {
|
229
|
+
const activeRequest = activeRequests.get(identifier);
|
230
|
+
if (activeRequest) {
|
231
|
+
activeRequest.push(callback);
|
232
|
+
return;
|
233
|
+
}
|
208
234
|
}
|
209
235
|
const itemCache = cache.getItemCache(identifier, null);
|
210
|
-
let callbacks;
|
211
|
-
const done =
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
236
|
+
let callbacks, yields;
|
237
|
+
const done = withYield
|
238
|
+
? (err, result) => {
|
239
|
+
if (callbacks === undefined) {
|
240
|
+
if (err) {
|
241
|
+
callback(err);
|
242
|
+
} else {
|
243
|
+
if (result)
|
244
|
+
for (const r of result) resolveContext.yield(r);
|
245
|
+
callback(null, null);
|
246
|
+
}
|
247
|
+
yields = undefined;
|
248
|
+
callbacks = false;
|
249
|
+
} else {
|
250
|
+
if (err) {
|
251
|
+
for (const cb of callbacks) cb(err);
|
252
|
+
} else {
|
253
|
+
for (let i = 0; i < callbacks.length; i++) {
|
254
|
+
const cb = callbacks[i];
|
255
|
+
const yield_ = yields[i];
|
256
|
+
if (result) for (const r of result) yield_(r);
|
257
|
+
cb(null, null);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
activeRequestsWithYield.delete(identifier);
|
261
|
+
yields = undefined;
|
262
|
+
callbacks = false;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
: (err, result) => {
|
266
|
+
if (callbacks === undefined) {
|
267
|
+
callback(err, result);
|
268
|
+
callbacks = false;
|
269
|
+
} else {
|
270
|
+
for (const callback of callbacks) {
|
271
|
+
callback(err, result);
|
272
|
+
}
|
273
|
+
activeRequests.delete(identifier);
|
274
|
+
callbacks = false;
|
275
|
+
}
|
276
|
+
};
|
223
277
|
/**
|
224
278
|
* @param {Error=} err error if any
|
225
279
|
* @param {CacheEntry=} cacheEntry cache entry
|
@@ -276,7 +330,14 @@ class ResolverCachePlugin {
|
|
276
330
|
}
|
277
331
|
};
|
278
332
|
itemCache.get(processCacheResult);
|
279
|
-
if (callbacks === undefined) {
|
333
|
+
if (withYield && callbacks === undefined) {
|
334
|
+
callbacks = [callback];
|
335
|
+
yields = [resolveContext.yield];
|
336
|
+
activeRequestsWithYield.set(
|
337
|
+
identifier,
|
338
|
+
/** @type {[any, any]} */ ([callbacks, yields])
|
339
|
+
);
|
340
|
+
} else if (callbacks === undefined) {
|
280
341
|
callbacks = [callback];
|
281
342
|
activeRequests.set(identifier, callbacks);
|
282
343
|
}
|
@@ -121,8 +121,7 @@ const resolve = browsers => {
|
|
121
121
|
// baidu: Not supported
|
122
122
|
// and_uc: Not supported
|
123
123
|
// kaios: Not supported
|
124
|
-
|
125
|
-
node: [13, 14]
|
124
|
+
node: [12, 17]
|
126
125
|
});
|
127
126
|
|
128
127
|
return {
|
@@ -248,8 +247,7 @@ const resolve = browsers => {
|
|
248
247
|
// baidu: Not supported
|
249
248
|
// and_uc: Not supported
|
250
249
|
// kaios: Not supported
|
251
|
-
|
252
|
-
node: [13, 14]
|
250
|
+
node: [12, 17]
|
253
251
|
}),
|
254
252
|
dynamicImport: es6DynamicImport,
|
255
253
|
dynamicImportInWorker: es6DynamicImport && !anyNode,
|
@@ -272,7 +270,7 @@ const resolve = browsers => {
|
|
272
270
|
// baidu: Unknown support
|
273
271
|
// and_uc: Unknown support
|
274
272
|
// kaios: Unknown support
|
275
|
-
node:
|
273
|
+
node: 12
|
276
274
|
}),
|
277
275
|
optionalChaining: rawChecker({
|
278
276
|
chrome: 80,
|
@@ -488,6 +488,7 @@ const getNormalizedEntryStatic = entry => {
|
|
488
488
|
filename: value.filename,
|
489
489
|
layer: value.layer,
|
490
490
|
runtime: value.runtime,
|
491
|
+
baseUri: value.baseUri,
|
491
492
|
publicPath: value.publicPath,
|
492
493
|
chunkLoading: value.chunkLoading,
|
493
494
|
asyncChunks: value.asyncChunks,
|
@@ -37,7 +37,7 @@ const splitContextFromPrefix = prefix => {
|
|
37
37
|
};
|
38
38
|
};
|
39
39
|
|
40
|
-
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource"
|
40
|
+
/** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
|
41
41
|
|
42
42
|
/** @typedef {{ new(options: ContextDependencyOptions, range: [number, number], valueRange: [number, number]): ContextDependency }} ContextDependencyConstructor */
|
43
43
|
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
9
9
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
10
|
+
const NullDependency = require("./NullDependency");
|
10
11
|
|
11
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
13
|
/** @typedef {import("../Dependency")} Dependency */
|
@@ -28,8 +29,9 @@ makeSerializable(
|
|
28
29
|
"webpack/lib/dependencies/HarmonyAcceptImportDependency"
|
29
30
|
);
|
30
31
|
|
31
|
-
HarmonyAcceptImportDependency.Template =
|
32
|
-
HarmonyImportDependency.Template
|
33
|
-
|
32
|
+
HarmonyAcceptImportDependency.Template =
|
33
|
+
/** @type {typeof HarmonyImportDependency.Template} */ (
|
34
|
+
NullDependency.Template
|
35
|
+
);
|
34
36
|
|
35
37
|
module.exports = HarmonyAcceptImportDependency;
|
@@ -145,7 +145,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
145
145
|
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
146
146
|
: "";
|
147
147
|
const definitions = [];
|
148
|
-
|
148
|
+
const orderedExportMap = Array.from(this.exportMap).sort(([a], [b]) =>
|
149
|
+
a < b ? -1 : 1
|
150
|
+
);
|
151
|
+
for (const [key, value] of orderedExportMap) {
|
149
152
|
definitions.push(
|
150
153
|
`\n/* harmony export */ ${JSON.stringify(
|
151
154
|
key
|
@@ -28,7 +28,6 @@ class ImportContextDependency extends ContextDependency {
|
|
28
28
|
serialize(context) {
|
29
29
|
const { write } = context;
|
30
30
|
|
31
|
-
write(this.range);
|
32
31
|
write(this.valueRange);
|
33
32
|
|
34
33
|
super.serialize(context);
|
@@ -37,7 +36,6 @@ class ImportContextDependency extends ContextDependency {
|
|
37
36
|
deserialize(context) {
|
38
37
|
const { read } = context;
|
39
38
|
|
40
|
-
this.range = read();
|
41
39
|
this.valueRange = read();
|
42
40
|
|
43
41
|
super.deserialize(context);
|