webpack 5.48.0 → 5.51.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +4 -16
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/CompatibilityPlugin.js +21 -4
- package/lib/Compilation.js +8 -3
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +665 -193
- package/lib/HotModuleReplacementPlugin.js +4 -4
- package/lib/Module.js +1 -0
- package/lib/MultiCompiler.js +0 -2
- package/lib/NormalModule.js +51 -20
- package/lib/NormalModuleFactory.js +137 -74
- package/lib/Parser.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +8 -0
- package/lib/asset/AssetModulesPlugin.js +0 -1
- package/lib/config/defaults.js +27 -6
- package/lib/config/normalization.js +6 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
- package/lib/index.js +0 -3
- package/lib/javascript/JavascriptParser.js +2 -0
- package/lib/library/ModuleLibraryPlugin.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -1
- package/lib/optimize/ConcatenatedModule.js +3 -3
- package/lib/optimize/SplitChunksPlugin.js +4 -4
- package/lib/schemes/HttpUriPlugin.js +942 -25
- package/lib/serialization/BinaryMiddleware.js +293 -267
- package/lib/util/fs.js +40 -0
- package/lib/util/identifier.js +26 -8
- package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js} +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -2
- package/lib/web/FetchCompileWasmPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +7 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +43 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
- package/schemas/plugins/schemes/HttpUriPlugin.json +42 -0
- package/types.d.ts +110 -14
- package/lib/schemes/HttpsUriPlugin.js +0 -63
@@ -297,10 +297,10 @@ class HotModuleReplacementPlugin {
|
|
297
297
|
records.hotIndex = hotIndex;
|
298
298
|
records.fullHashChunkModuleHashes = fullHashChunkModuleHashes;
|
299
299
|
records.chunkModuleHashes = chunkModuleHashes;
|
300
|
-
records.
|
300
|
+
records.chunkHashes = {};
|
301
301
|
records.chunkRuntime = {};
|
302
302
|
for (const chunk of compilation.chunks) {
|
303
|
-
records.
|
303
|
+
records.chunkHashes[chunk.id] = chunk.hash;
|
304
304
|
records.chunkRuntime[chunk.id] = getRuntimeKey(chunk.runtime);
|
305
305
|
}
|
306
306
|
records.chunkModuleIds = {};
|
@@ -420,7 +420,7 @@ class HotModuleReplacementPlugin {
|
|
420
420
|
if (records.hash === compilation.hash) return;
|
421
421
|
if (
|
422
422
|
!records.chunkModuleHashes ||
|
423
|
-
!records.
|
423
|
+
!records.chunkHashes ||
|
424
424
|
!records.chunkModuleIds
|
425
425
|
) {
|
426
426
|
return;
|
@@ -477,7 +477,7 @@ class HotModuleReplacementPlugin {
|
|
477
477
|
/** @type {Set<string | number>} */
|
478
478
|
const completelyRemovedModules = new Set();
|
479
479
|
|
480
|
-
for (const key of Object.keys(records.
|
480
|
+
for (const key of Object.keys(records.chunkHashes)) {
|
481
481
|
const oldRuntime = keyToRuntime(records.chunkRuntime[key]);
|
482
482
|
/** @type {Module[]} */
|
483
483
|
const remainingModules = [];
|
package/lib/Module.js
CHANGED
@@ -93,6 +93,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
93
93
|
|
94
94
|
/**
|
95
95
|
* @typedef {Object} NeedBuildContext
|
96
|
+
* @property {Compilation} compilation
|
96
97
|
* @property {FileSystemInfo} fileSystemInfo
|
97
98
|
* @property {Map<string, string | Set<string>>} valueCacheVersions
|
98
99
|
*/
|
package/lib/MultiCompiler.js
CHANGED
@@ -87,7 +87,6 @@ module.exports = class MultiCompiler {
|
|
87
87
|
const compiler = this.compilers[index];
|
88
88
|
const compilerIndex = index;
|
89
89
|
let compilerDone = false;
|
90
|
-
// eslint-disable-next-line no-loop-func
|
91
90
|
compiler.hooks.done.tap("MultiCompiler", stats => {
|
92
91
|
if (!compilerDone) {
|
93
92
|
compilerDone = true;
|
@@ -98,7 +97,6 @@ module.exports = class MultiCompiler {
|
|
98
97
|
this.hooks.done.call(new MultiStats(compilerStats));
|
99
98
|
}
|
100
99
|
});
|
101
|
-
// eslint-disable-next-line no-loop-func
|
102
100
|
compiler.hooks.invalid.tap("MultiCompiler", () => {
|
103
101
|
if (compilerDone) {
|
104
102
|
compilerDone = false;
|
package/lib/NormalModule.js
CHANGED
@@ -16,6 +16,7 @@ const {
|
|
16
16
|
SourceMapSource
|
17
17
|
} = require("webpack-sources");
|
18
18
|
const Compilation = require("./Compilation");
|
19
|
+
const HookWebpackError = require("./HookWebpackError");
|
19
20
|
const Module = require("./Module");
|
20
21
|
const ModuleBuildError = require("./ModuleBuildError");
|
21
22
|
const ModuleError = require("./ModuleError");
|
@@ -37,7 +38,11 @@ const {
|
|
37
38
|
} = require("./util/comparators");
|
38
39
|
const createHash = require("./util/createHash");
|
39
40
|
const { join } = require("./util/fs");
|
40
|
-
const {
|
41
|
+
const {
|
42
|
+
contextify,
|
43
|
+
absolutify,
|
44
|
+
makePathsRelative
|
45
|
+
} = require("./util/identifier");
|
41
46
|
const makeSerializable = require("./util/makeSerializable");
|
42
47
|
const memoize = require("./util/memoize");
|
43
48
|
|
@@ -101,7 +106,11 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
|
|
101
106
|
*/
|
102
107
|
const contextifySourceUrl = (context, source, associatedObjectForCache) => {
|
103
108
|
if (source.startsWith("webpack://")) return source;
|
104
|
-
return `webpack://${
|
109
|
+
return `webpack://${makePathsRelative(
|
110
|
+
context,
|
111
|
+
source,
|
112
|
+
associatedObjectForCache
|
113
|
+
)}`;
|
105
114
|
};
|
106
115
|
|
107
116
|
/**
|
@@ -178,6 +187,7 @@ makeSerializable(
|
|
178
187
|
* @property {SyncHook<[object, NormalModule]>} loader
|
179
188
|
* @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
|
180
189
|
* @property {HookMap<AsyncSeriesBailHook<[string, NormalModule], string | Buffer>>} readResourceForScheme
|
190
|
+
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
181
191
|
*/
|
182
192
|
|
183
193
|
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
|
@@ -201,7 +211,8 @@ class NormalModule extends Module {
|
|
201
211
|
beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
|
202
212
|
readResourceForScheme: new HookMap(
|
203
213
|
() => new AsyncSeriesBailHook(["resource", "module"])
|
204
|
-
)
|
214
|
+
),
|
215
|
+
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
205
216
|
};
|
206
217
|
compilationHooksMap.set(compilation, hooks);
|
207
218
|
}
|
@@ -218,6 +229,7 @@ class NormalModule extends Module {
|
|
218
229
|
* @param {LoaderItem[]} options.loaders list of loaders
|
219
230
|
* @param {string} options.resource path + query of the real resource
|
220
231
|
* @param {Record<string, any>=} options.resourceResolveData resource resolve data
|
232
|
+
* @param {string} options.context context directory for resolving
|
221
233
|
* @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
|
222
234
|
* @param {Parser} options.parser the parser used
|
223
235
|
* @param {object} options.parserOptions the options of the parser used
|
@@ -234,6 +246,7 @@ class NormalModule extends Module {
|
|
234
246
|
loaders,
|
235
247
|
resource,
|
236
248
|
resourceResolveData,
|
249
|
+
context,
|
237
250
|
matchResource,
|
238
251
|
parser,
|
239
252
|
parserOptions,
|
@@ -241,7 +254,7 @@ class NormalModule extends Module {
|
|
241
254
|
generatorOptions,
|
242
255
|
resolveOptions
|
243
256
|
}) {
|
244
|
-
super(type, getContext(resource), layer);
|
257
|
+
super(type, context || getContext(resource), layer);
|
245
258
|
|
246
259
|
// Info from Factory
|
247
260
|
/** @type {string} */
|
@@ -352,6 +365,7 @@ class NormalModule extends Module {
|
|
352
365
|
this.generator = m.generator;
|
353
366
|
this.generatorOptions = m.generatorOptions;
|
354
367
|
this.resource = m.resource;
|
368
|
+
this.context = m.context;
|
355
369
|
this.matchResource = m.matchResource;
|
356
370
|
this.loaders = m.loaders;
|
357
371
|
}
|
@@ -751,6 +765,13 @@ class NormalModule extends Module {
|
|
751
765
|
|
752
766
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
753
767
|
|
768
|
+
this.buildInfo.fileDependencies = new LazySet();
|
769
|
+
this.buildInfo.contextDependencies = new LazySet();
|
770
|
+
this.buildInfo.missingDependencies = new LazySet();
|
771
|
+
if (this.loaders.length > 0) {
|
772
|
+
this.buildInfo.buildDependencies = new LazySet();
|
773
|
+
}
|
774
|
+
this.buildInfo.cacheable = true;
|
754
775
|
try {
|
755
776
|
hooks.beforeLoaders.call(this.loaders, this, loaderContext);
|
756
777
|
} catch (err) {
|
@@ -762,7 +783,8 @@ class NormalModule extends Module {
|
|
762
783
|
resource: this.resource,
|
763
784
|
loaders: this.loaders,
|
764
785
|
context: loaderContext,
|
765
|
-
processResource: (loaderContext,
|
786
|
+
processResource: (loaderContext, resourcePath, callback) => {
|
787
|
+
const resource = loaderContext.resource;
|
766
788
|
const scheme = getScheme(resource);
|
767
789
|
if (scheme) {
|
768
790
|
hooks.readResourceForScheme
|
@@ -775,8 +797,8 @@ class NormalModule extends Module {
|
|
775
797
|
return callback(null, result);
|
776
798
|
});
|
777
799
|
} else {
|
778
|
-
loaderContext.addDependency(
|
779
|
-
fs.readFile(
|
800
|
+
loaderContext.addDependency(resourcePath);
|
801
|
+
fs.readFile(resourcePath, callback);
|
780
802
|
}
|
781
803
|
}
|
782
804
|
},
|
@@ -789,27 +811,19 @@ class NormalModule extends Module {
|
|
789
811
|
undefined;
|
790
812
|
|
791
813
|
if (!result) {
|
814
|
+
this.buildInfo.cacheable = false;
|
792
815
|
return processResult(
|
793
816
|
err || new Error("No result from loader-runner processing"),
|
794
817
|
null
|
795
818
|
);
|
796
819
|
}
|
797
|
-
this.buildInfo.fileDependencies = new LazySet();
|
798
820
|
this.buildInfo.fileDependencies.addAll(result.fileDependencies);
|
799
|
-
this.buildInfo.contextDependencies = new LazySet();
|
800
821
|
this.buildInfo.contextDependencies.addAll(result.contextDependencies);
|
801
|
-
this.buildInfo.missingDependencies = new LazySet();
|
802
822
|
this.buildInfo.missingDependencies.addAll(result.missingDependencies);
|
803
|
-
if (
|
804
|
-
this.loaders.length > 0 &&
|
805
|
-
this.buildInfo.buildDependencies === undefined
|
806
|
-
) {
|
807
|
-
this.buildInfo.buildDependencies = new LazySet();
|
808
|
-
}
|
809
823
|
for (const loader of this.loaders) {
|
810
824
|
this.buildInfo.buildDependencies.add(loader.loader);
|
811
825
|
}
|
812
|
-
this.buildInfo.cacheable = result.cacheable;
|
826
|
+
this.buildInfo.cacheable = this.buildInfo.cacheable && result.cacheable;
|
813
827
|
processResult(err, result.result);
|
814
828
|
}
|
815
829
|
);
|
@@ -1019,7 +1033,9 @@ class NormalModule extends Module {
|
|
1019
1033
|
|
1020
1034
|
let result;
|
1021
1035
|
try {
|
1022
|
-
|
1036
|
+
const source = this._source.source();
|
1037
|
+
result = this.parser.parse(this._ast || source, {
|
1038
|
+
source,
|
1023
1039
|
current: this,
|
1024
1040
|
module: this,
|
1025
1041
|
compilation: compilation,
|
@@ -1178,7 +1194,8 @@ class NormalModule extends Module {
|
|
1178
1194
|
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
1179
1195
|
* @returns {void}
|
1180
1196
|
*/
|
1181
|
-
needBuild(
|
1197
|
+
needBuild(context, callback) {
|
1198
|
+
const { fileSystemInfo, compilation, valueCacheVersions } = context;
|
1182
1199
|
// build if enforced
|
1183
1200
|
if (this._forceBuild) return callback(null, true);
|
1184
1201
|
|
@@ -1213,7 +1230,20 @@ class NormalModule extends Module {
|
|
1213
1230
|
|
1214
1231
|
// check snapshot for validity
|
1215
1232
|
fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
|
1216
|
-
callback(err
|
1233
|
+
if (err) return callback(err);
|
1234
|
+
if (!valid) return callback(null, true);
|
1235
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
1236
|
+
hooks.needBuild.callAsync(this, context, (err, needBuild) => {
|
1237
|
+
if (err) {
|
1238
|
+
return callback(
|
1239
|
+
HookWebpackError.makeWebpackError(
|
1240
|
+
err,
|
1241
|
+
"NormalModule.getCompilationHooks().needBuild"
|
1242
|
+
)
|
1243
|
+
);
|
1244
|
+
}
|
1245
|
+
callback(null, !!needBuild);
|
1246
|
+
});
|
1217
1247
|
});
|
1218
1248
|
}
|
1219
1249
|
|
@@ -1298,6 +1328,7 @@ class NormalModule extends Module {
|
|
1298
1328
|
type: "",
|
1299
1329
|
// will be filled by updateCacheModule
|
1300
1330
|
resource: "",
|
1331
|
+
context: "",
|
1301
1332
|
request: null,
|
1302
1333
|
userRequest: null,
|
1303
1334
|
rawRequest: null,
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { getContext } = require("loader-runner");
|
8
9
|
const asyncLib = require("neo-async");
|
9
10
|
const {
|
10
11
|
AsyncSeriesBailHook,
|
@@ -46,6 +47,7 @@ const { parseResource } = require("./util/identifier");
|
|
46
47
|
* @property {string} request
|
47
48
|
* @property {Record<string, any> | undefined} assertions
|
48
49
|
* @property {ModuleDependency[]} dependencies
|
50
|
+
* @property {string} dependencyType
|
49
51
|
* @property {Object} createData
|
50
52
|
* @property {LazySet<string>} fileDependencies
|
51
53
|
* @property {LazySet<string>} missingDependencies
|
@@ -59,6 +61,7 @@ const { parseResource } = require("./util/identifier");
|
|
59
61
|
* @property {string} path
|
60
62
|
* @property {string} query
|
61
63
|
* @property {string} fragment
|
64
|
+
* @property {string=} context
|
62
65
|
*/
|
63
66
|
|
64
67
|
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
|
@@ -66,6 +69,7 @@ const { parseResource } = require("./util/identifier");
|
|
66
69
|
const EMPTY_RESOLVE_OPTIONS = {};
|
67
70
|
const EMPTY_PARSER_OPTIONS = {};
|
68
71
|
const EMPTY_GENERATOR_OPTIONS = {};
|
72
|
+
const EMPTY_ELEMENTS = [];
|
69
73
|
|
70
74
|
const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/;
|
71
75
|
|
@@ -220,6 +224,10 @@ class NormalModuleFactory extends ModuleFactory {
|
|
220
224
|
resolveForScheme: new HookMap(
|
221
225
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
222
226
|
),
|
227
|
+
/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
|
228
|
+
resolveInScheme: new HookMap(
|
229
|
+
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
230
|
+
),
|
223
231
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
224
232
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
225
233
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
@@ -340,6 +348,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
340
348
|
contextInfo,
|
341
349
|
context,
|
342
350
|
dependencies,
|
351
|
+
dependencyType,
|
343
352
|
request,
|
344
353
|
assertions,
|
345
354
|
resolveOptions,
|
@@ -347,49 +356,76 @@ class NormalModuleFactory extends ModuleFactory {
|
|
347
356
|
missingDependencies,
|
348
357
|
contextDependencies
|
349
358
|
} = data;
|
350
|
-
const dependencyType =
|
351
|
-
(dependencies.length > 0 && dependencies[0].category) || "";
|
352
359
|
const loaderResolver = this.getResolver("loader");
|
353
360
|
|
354
361
|
/** @type {ResourceData | undefined} */
|
355
362
|
let matchResourceData = undefined;
|
356
363
|
/** @type {string} */
|
357
|
-
let
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
364
|
+
let unresolvedResource;
|
365
|
+
/** @type {{loader: string, options: string|undefined}[]} */
|
366
|
+
let elements;
|
367
|
+
let noPreAutoLoaders = false;
|
368
|
+
let noAutoLoaders = false;
|
369
|
+
let noPrePostAutoLoaders = false;
|
370
|
+
|
371
|
+
const contextScheme = getScheme(context);
|
372
|
+
/** @type {string | undefined} */
|
373
|
+
let scheme = getScheme(request);
|
374
|
+
|
375
|
+
if (!scheme) {
|
376
|
+
/** @type {string} */
|
377
|
+
let requestWithoutMatchResource = request;
|
378
|
+
const matchResourceMatch = MATCH_RESOURCE_REGEX.exec(request);
|
379
|
+
if (matchResourceMatch) {
|
380
|
+
let matchResource = matchResourceMatch[1];
|
381
|
+
if (matchResource.charCodeAt(0) === 46) {
|
382
|
+
// 46 === ".", 47 === "/"
|
383
|
+
const secondChar = matchResource.charCodeAt(1);
|
384
|
+
if (
|
385
|
+
secondChar === 47 ||
|
386
|
+
(secondChar === 46 && matchResource.charCodeAt(2) === 47)
|
387
|
+
) {
|
388
|
+
// if matchResources startsWith ../ or ./
|
389
|
+
matchResource = join(this.fs, context, matchResource);
|
390
|
+
}
|
370
391
|
}
|
392
|
+
matchResourceData = {
|
393
|
+
resource: matchResource,
|
394
|
+
...cacheParseResource(matchResource)
|
395
|
+
};
|
396
|
+
requestWithoutMatchResource = request.substr(
|
397
|
+
matchResourceMatch[0].length
|
398
|
+
);
|
371
399
|
}
|
372
|
-
matchResourceData = {
|
373
|
-
resource: matchResource,
|
374
|
-
...cacheParseResource(matchResource)
|
375
|
-
};
|
376
|
-
requestWithoutMatchResource = request.substr(
|
377
|
-
matchResourceMatch[0].length
|
378
|
-
);
|
379
|
-
}
|
380
400
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
401
|
+
scheme = getScheme(requestWithoutMatchResource);
|
402
|
+
|
403
|
+
if (!scheme && !contextScheme) {
|
404
|
+
const firstChar = requestWithoutMatchResource.charCodeAt(0);
|
405
|
+
const secondChar = requestWithoutMatchResource.charCodeAt(1);
|
406
|
+
noPreAutoLoaders = firstChar === 45 && secondChar === 33; // startsWith "-!"
|
407
|
+
noAutoLoaders = noPreAutoLoaders || firstChar === 33; // startsWith "!"
|
408
|
+
noPrePostAutoLoaders = firstChar === 33 && secondChar === 33; // startsWith "!!";
|
409
|
+
const rawElements = requestWithoutMatchResource
|
410
|
+
.slice(
|
411
|
+
noPreAutoLoaders || noPrePostAutoLoaders
|
412
|
+
? 2
|
413
|
+
: noAutoLoaders
|
414
|
+
? 1
|
415
|
+
: 0
|
416
|
+
)
|
417
|
+
.split(/!+/);
|
418
|
+
unresolvedResource = rawElements.pop();
|
419
|
+
elements = rawElements.map(identToLoaderRequest);
|
420
|
+
scheme = getScheme(unresolvedResource);
|
421
|
+
} else {
|
422
|
+
unresolvedResource = requestWithoutMatchResource;
|
423
|
+
elements = EMPTY_ELEMENTS;
|
424
|
+
}
|
425
|
+
} else {
|
426
|
+
unresolvedResource = request;
|
427
|
+
elements = EMPTY_ELEMENTS;
|
428
|
+
}
|
393
429
|
|
394
430
|
const resolveContext = {
|
395
431
|
fileDependencies,
|
@@ -399,8 +435,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
399
435
|
|
400
436
|
/** @type {ResourceDataWithData} */
|
401
437
|
let resourceData;
|
402
|
-
/** @type {string | undefined} */
|
403
|
-
const scheme = getScheme(unresolvedResource);
|
404
438
|
|
405
439
|
let loaders;
|
406
440
|
|
@@ -540,6 +574,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
540
574
|
rawRequest: request,
|
541
575
|
loaders: allLoaders,
|
542
576
|
resource: resourceData.resource,
|
577
|
+
context:
|
578
|
+
resourceData.context || getContext(resourceData.resource),
|
543
579
|
matchResource: matchResourceData
|
544
580
|
? matchResourceData.resource
|
545
581
|
: undefined,
|
@@ -594,7 +630,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
594
630
|
|
595
631
|
this.resolveRequestArray(
|
596
632
|
contextInfo,
|
597
|
-
context,
|
633
|
+
contextScheme ? this.context : context,
|
598
634
|
elements,
|
599
635
|
loaderResolver,
|
600
636
|
resolveContext,
|
@@ -605,6 +641,49 @@ class NormalModuleFactory extends ModuleFactory {
|
|
605
641
|
}
|
606
642
|
);
|
607
643
|
|
644
|
+
const defaultResolve = context => {
|
645
|
+
if (/^($|\?)/.test(unresolvedResource)) {
|
646
|
+
resourceData = {
|
647
|
+
resource: unresolvedResource,
|
648
|
+
data: {},
|
649
|
+
...cacheParseResource(unresolvedResource)
|
650
|
+
};
|
651
|
+
continueCallback();
|
652
|
+
}
|
653
|
+
|
654
|
+
// resource without scheme and with path
|
655
|
+
else {
|
656
|
+
const normalResolver = this.getResolver(
|
657
|
+
"normal",
|
658
|
+
dependencyType
|
659
|
+
? cachedSetProperty(
|
660
|
+
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
661
|
+
"dependencyType",
|
662
|
+
dependencyType
|
663
|
+
)
|
664
|
+
: resolveOptions
|
665
|
+
);
|
666
|
+
this.resolveResource(
|
667
|
+
contextInfo,
|
668
|
+
context,
|
669
|
+
unresolvedResource,
|
670
|
+
normalResolver,
|
671
|
+
resolveContext,
|
672
|
+
(err, resolvedResource, resolvedResourceResolveData) => {
|
673
|
+
if (err) return continueCallback(err);
|
674
|
+
if (resolvedResource !== false) {
|
675
|
+
resourceData = {
|
676
|
+
resource: resolvedResource,
|
677
|
+
data: resolvedResourceResolveData,
|
678
|
+
...cacheParseResource(resolvedResource)
|
679
|
+
};
|
680
|
+
}
|
681
|
+
continueCallback();
|
682
|
+
}
|
683
|
+
);
|
684
|
+
}
|
685
|
+
};
|
686
|
+
|
608
687
|
// resource with scheme
|
609
688
|
if (scheme) {
|
610
689
|
resourceData = {
|
@@ -612,7 +691,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
612
691
|
data: {},
|
613
692
|
path: undefined,
|
614
693
|
query: undefined,
|
615
|
-
fragment: undefined
|
694
|
+
fragment: undefined,
|
695
|
+
context: undefined
|
616
696
|
};
|
617
697
|
this.hooks.resolveForScheme
|
618
698
|
.for(scheme)
|
@@ -622,47 +702,27 @@ class NormalModuleFactory extends ModuleFactory {
|
|
622
702
|
});
|
623
703
|
}
|
624
704
|
|
625
|
-
// resource
|
626
|
-
else if (
|
705
|
+
// resource within scheme
|
706
|
+
else if (contextScheme) {
|
627
707
|
resourceData = {
|
628
708
|
resource: unresolvedResource,
|
629
709
|
data: {},
|
630
|
-
|
710
|
+
path: undefined,
|
711
|
+
query: undefined,
|
712
|
+
fragment: undefined,
|
713
|
+
context: undefined
|
631
714
|
};
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
// resource without scheme and with path
|
636
|
-
else {
|
637
|
-
const normalResolver = this.getResolver(
|
638
|
-
"normal",
|
639
|
-
dependencyType
|
640
|
-
? cachedSetProperty(
|
641
|
-
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
642
|
-
"dependencyType",
|
643
|
-
dependencyType
|
644
|
-
)
|
645
|
-
: resolveOptions
|
646
|
-
);
|
647
|
-
this.resolveResource(
|
648
|
-
contextInfo,
|
649
|
-
context,
|
650
|
-
unresolvedResource,
|
651
|
-
normalResolver,
|
652
|
-
resolveContext,
|
653
|
-
(err, resolvedResource, resolvedResourceResolveData) => {
|
715
|
+
this.hooks.resolveInScheme
|
716
|
+
.for(contextScheme)
|
717
|
+
.callAsync(resourceData, data, (err, handled) => {
|
654
718
|
if (err) return continueCallback(err);
|
655
|
-
if (
|
656
|
-
resourceData = {
|
657
|
-
resource: resolvedResource,
|
658
|
-
data: resolvedResourceResolveData,
|
659
|
-
...cacheParseResource(resolvedResource)
|
660
|
-
};
|
661
|
-
}
|
719
|
+
if (!handled) return defaultResolve(this.context);
|
662
720
|
continueCallback();
|
663
|
-
}
|
664
|
-
);
|
721
|
+
});
|
665
722
|
}
|
723
|
+
|
724
|
+
// resource without scheme and without path
|
725
|
+
else defaultResolve(context);
|
666
726
|
}
|
667
727
|
);
|
668
728
|
}
|
@@ -703,6 +763,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
703
763
|
const fileDependencies = new LazySet();
|
704
764
|
const missingDependencies = new LazySet();
|
705
765
|
const contextDependencies = new LazySet();
|
766
|
+
const dependencyType =
|
767
|
+
(dependencies.length > 0 && dependencies[0].category) || "";
|
706
768
|
/** @type {ResolveData} */
|
707
769
|
const resolveData = {
|
708
770
|
contextInfo,
|
@@ -711,6 +773,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
711
773
|
request,
|
712
774
|
assertions,
|
713
775
|
dependencies,
|
776
|
+
dependencyType,
|
714
777
|
fileDependencies,
|
715
778
|
missingDependencies,
|
716
779
|
contextDependencies,
|
@@ -857,7 +920,7 @@ ${hints.join("\n\n")}`;
|
|
857
920
|
null,
|
858
921
|
`Did you mean '${resource}'?
|
859
922
|
BREAKING CHANGE: The request '${unresolvedResource}' failed to resolve only because it was resolved as fully specified
|
860
|
-
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
|
923
|
+
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
|
861
924
|
The extension in the request is mandatory for it to be fully specified.
|
862
925
|
Add the extension to the request.`
|
863
926
|
);
|
package/lib/Parser.js
CHANGED
package/lib/RuntimeGlobals.js
CHANGED
@@ -297,6 +297,11 @@ exports.hmrModuleData = "__webpack_require__.hmrD";
|
|
297
297
|
*/
|
298
298
|
exports.hmrInvalidateModuleHandlers = "__webpack_require__.hmrI";
|
299
299
|
|
300
|
+
/**
|
301
|
+
* the prefix for storing state of runtime modules when hmr is enabled
|
302
|
+
*/
|
303
|
+
exports.hmrRuntimeStatePrefix = "__webpack_require__.hmrS";
|
304
|
+
|
300
305
|
/**
|
301
306
|
* the AMD define function
|
302
307
|
*/
|
@@ -14,7 +14,7 @@ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOpt
|
|
14
14
|
const createSchemaValidation = require("./util/create-schema-validation");
|
15
15
|
const createHash = require("./util/createHash");
|
16
16
|
const { relative, dirname } = require("./util/fs");
|
17
|
-
const {
|
17
|
+
const { makePathsAbsolute } = require("./util/identifier");
|
18
18
|
|
19
19
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
20
20
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -91,7 +91,7 @@ const getTaskForFile = (
|
|
91
91
|
if (!sourceMap || typeof source !== "string") return;
|
92
92
|
const context = compilation.options.context;
|
93
93
|
const root = compilation.compiler.root;
|
94
|
-
const cachedAbsolutify =
|
94
|
+
const cachedAbsolutify = makePathsAbsolute.bindContextCache(context, root);
|
95
95
|
const modules = sourceMap.sources.map(source => {
|
96
96
|
if (!source.startsWith("webpack://")) return source;
|
97
97
|
source = cachedAbsolutify(source.slice(10));
|
@@ -276,6 +276,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
276
276
|
}).apply(compiler);
|
277
277
|
}
|
278
278
|
|
279
|
+
if (options.experiments.buildHttp) {
|
280
|
+
const HttpUriPlugin = require("./schemes/HttpUriPlugin");
|
281
|
+
const httpOptions = options.experiments.buildHttp;
|
282
|
+
if (httpOptions === true)
|
283
|
+
throw new Error("Unexpected due to normalization");
|
284
|
+
new HttpUriPlugin(httpOptions).apply(compiler);
|
285
|
+
}
|
286
|
+
|
279
287
|
new EntryOptionPlugin().apply(compiler);
|
280
288
|
compiler.hooks.entryOption.call(options.context, options.entry);
|
281
289
|
|
@@ -120,7 +120,6 @@ class AssetModulesPlugin {
|
|
120
120
|
for (const type of ["asset", "asset/inline", "asset/resource"]) {
|
121
121
|
normalModuleFactory.hooks.createGenerator
|
122
122
|
.for(type)
|
123
|
-
// eslint-disable-next-line no-loop-func
|
124
123
|
.tap(plugin, generatorOptions => {
|
125
124
|
validateGeneratorOptions[type](generatorOptions);
|
126
125
|
|