webpack 5.46.0 → 5.49.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/Compilation.js +5 -2
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +4 -4
- package/lib/Module.js +1 -0
- package/lib/MultiCompiler.js +0 -2
- package/lib/NormalModule.js +44 -19
- package/lib/NormalModuleFactory.js +145 -76
- package/lib/Template.js +1 -4
- package/lib/WebpackOptionsApply.js +8 -0
- package/lib/asset/AssetGenerator.js +1 -1
- package/lib/asset/AssetModulesPlugin.js +0 -1
- package/lib/config/defaults.js +44 -17
- package/lib/config/normalization.js +6 -1
- package/lib/dependencies/AMDRequireDependency.js +2 -8
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -2
- package/lib/dependencies/HarmonyImportDependency.js +5 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -5
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -2
- package/lib/dependencies/ModuleDependency.js +8 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
- package/lib/index.js +0 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -8
- package/lib/javascript/JavascriptModulesPlugin.js +48 -29
- package/lib/javascript/JavascriptParser.js +14 -9
- package/lib/optimize/SplitChunksPlugin.js +4 -4
- package/lib/rules/{DescriptionDataMatcherRulePlugin.js → ObjectMatcherRulePlugin.js} +14 -10
- package/lib/schemes/HttpUriPlugin.js +942 -25
- package/lib/serialization/BinaryMiddleware.js +0 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/package.json +3 -2
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +50 -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 +148 -18
- package/lib/schemes/HttpsUriPlugin.js +0 -63
package/lib/Compilation.js
CHANGED
@@ -1302,6 +1302,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1302
1302
|
|
1303
1303
|
module.needBuild(
|
1304
1304
|
{
|
1305
|
+
compilation: this,
|
1305
1306
|
fileSystemInfo: this.fileSystemInfo,
|
1306
1307
|
valueCacheVersions: this.valueCacheVersions
|
1307
1308
|
},
|
@@ -1573,10 +1574,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1573
1574
|
if (err) {
|
1574
1575
|
if (dependencies.every(d => d.optional)) {
|
1575
1576
|
this.warnings.push(err);
|
1577
|
+
return callback();
|
1576
1578
|
} else {
|
1577
1579
|
this.errors.push(err);
|
1580
|
+
return callback(err);
|
1578
1581
|
}
|
1579
|
-
return callback(err);
|
1580
1582
|
}
|
1581
1583
|
|
1582
1584
|
if (!newModule) {
|
@@ -3784,8 +3786,9 @@ This prevents using hashes of each other and should be avoided.`);
|
|
3784
3786
|
/** @type {Map<string, {hash: string, source: Source, chunk: Chunk}>} */
|
3785
3787
|
const alreadyWrittenFiles = new Map();
|
3786
3788
|
|
3787
|
-
asyncLib.
|
3789
|
+
asyncLib.forEachLimit(
|
3788
3790
|
this.chunks,
|
3791
|
+
15,
|
3789
3792
|
(chunk, callback) => {
|
3790
3793
|
/** @type {RenderManifestEntry[]} */
|
3791
3794
|
let manifest;
|
@@ -62,6 +62,7 @@ class ExternalModuleFactoryPlugin {
|
|
62
62
|
const context = data.context;
|
63
63
|
const contextInfo = data.contextInfo;
|
64
64
|
const dependency = data.dependencies[0];
|
65
|
+
const dependencyType = data.dependencyType;
|
65
66
|
|
66
67
|
/**
|
67
68
|
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
|
@@ -172,7 +173,6 @@ class ExternalModuleFactoryPlugin {
|
|
172
173
|
cb
|
173
174
|
);
|
174
175
|
} else {
|
175
|
-
const dependencyType = dependency.category || "";
|
176
176
|
const promise = externals(
|
177
177
|
{
|
178
178
|
context,
|
@@ -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");
|
@@ -178,6 +179,7 @@ makeSerializable(
|
|
178
179
|
* @property {SyncHook<[object, NormalModule]>} loader
|
179
180
|
* @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
|
180
181
|
* @property {HookMap<AsyncSeriesBailHook<[string, NormalModule], string | Buffer>>} readResourceForScheme
|
182
|
+
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
181
183
|
*/
|
182
184
|
|
183
185
|
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
|
@@ -201,7 +203,8 @@ class NormalModule extends Module {
|
|
201
203
|
beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
|
202
204
|
readResourceForScheme: new HookMap(
|
203
205
|
() => new AsyncSeriesBailHook(["resource", "module"])
|
204
|
-
)
|
206
|
+
),
|
207
|
+
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
205
208
|
};
|
206
209
|
compilationHooksMap.set(compilation, hooks);
|
207
210
|
}
|
@@ -218,6 +221,7 @@ class NormalModule extends Module {
|
|
218
221
|
* @param {LoaderItem[]} options.loaders list of loaders
|
219
222
|
* @param {string} options.resource path + query of the real resource
|
220
223
|
* @param {Record<string, any>=} options.resourceResolveData resource resolve data
|
224
|
+
* @param {string} options.context context directory for resolving
|
221
225
|
* @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
|
222
226
|
* @param {Parser} options.parser the parser used
|
223
227
|
* @param {object} options.parserOptions the options of the parser used
|
@@ -234,6 +238,7 @@ class NormalModule extends Module {
|
|
234
238
|
loaders,
|
235
239
|
resource,
|
236
240
|
resourceResolveData,
|
241
|
+
context,
|
237
242
|
matchResource,
|
238
243
|
parser,
|
239
244
|
parserOptions,
|
@@ -241,7 +246,7 @@ class NormalModule extends Module {
|
|
241
246
|
generatorOptions,
|
242
247
|
resolveOptions
|
243
248
|
}) {
|
244
|
-
super(type, getContext(resource), layer);
|
249
|
+
super(type, context || getContext(resource), layer);
|
245
250
|
|
246
251
|
// Info from Factory
|
247
252
|
/** @type {string} */
|
@@ -293,9 +298,13 @@ class NormalModule extends Module {
|
|
293
298
|
*/
|
294
299
|
identifier() {
|
295
300
|
if (this.layer === null) {
|
296
|
-
|
301
|
+
if (this.type === "javascript/auto") {
|
302
|
+
return this.request;
|
303
|
+
} else {
|
304
|
+
return `${this.type}|${this.request}`;
|
305
|
+
}
|
297
306
|
} else {
|
298
|
-
return `${this.request}|${this.layer}`;
|
307
|
+
return `${this.type}|${this.request}|${this.layer}`;
|
299
308
|
}
|
300
309
|
}
|
301
310
|
|
@@ -348,6 +357,7 @@ class NormalModule extends Module {
|
|
348
357
|
this.generator = m.generator;
|
349
358
|
this.generatorOptions = m.generatorOptions;
|
350
359
|
this.resource = m.resource;
|
360
|
+
this.context = m.context;
|
351
361
|
this.matchResource = m.matchResource;
|
352
362
|
this.loaders = m.loaders;
|
353
363
|
}
|
@@ -747,6 +757,13 @@ class NormalModule extends Module {
|
|
747
757
|
|
748
758
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
749
759
|
|
760
|
+
this.buildInfo.fileDependencies = new LazySet();
|
761
|
+
this.buildInfo.contextDependencies = new LazySet();
|
762
|
+
this.buildInfo.missingDependencies = new LazySet();
|
763
|
+
if (this.loaders.length > 0) {
|
764
|
+
this.buildInfo.buildDependencies = new LazySet();
|
765
|
+
}
|
766
|
+
this.buildInfo.cacheable = true;
|
750
767
|
try {
|
751
768
|
hooks.beforeLoaders.call(this.loaders, this, loaderContext);
|
752
769
|
} catch (err) {
|
@@ -758,7 +775,8 @@ class NormalModule extends Module {
|
|
758
775
|
resource: this.resource,
|
759
776
|
loaders: this.loaders,
|
760
777
|
context: loaderContext,
|
761
|
-
processResource: (loaderContext,
|
778
|
+
processResource: (loaderContext, resourcePath, callback) => {
|
779
|
+
const resource = loaderContext.resource;
|
762
780
|
const scheme = getScheme(resource);
|
763
781
|
if (scheme) {
|
764
782
|
hooks.readResourceForScheme
|
@@ -771,8 +789,8 @@ class NormalModule extends Module {
|
|
771
789
|
return callback(null, result);
|
772
790
|
});
|
773
791
|
} else {
|
774
|
-
loaderContext.addDependency(
|
775
|
-
fs.readFile(
|
792
|
+
loaderContext.addDependency(resourcePath);
|
793
|
+
fs.readFile(resourcePath, callback);
|
776
794
|
}
|
777
795
|
}
|
778
796
|
},
|
@@ -785,27 +803,19 @@ class NormalModule extends Module {
|
|
785
803
|
undefined;
|
786
804
|
|
787
805
|
if (!result) {
|
806
|
+
this.buildInfo.cacheable = false;
|
788
807
|
return processResult(
|
789
808
|
err || new Error("No result from loader-runner processing"),
|
790
809
|
null
|
791
810
|
);
|
792
811
|
}
|
793
|
-
this.buildInfo.fileDependencies = new LazySet();
|
794
812
|
this.buildInfo.fileDependencies.addAll(result.fileDependencies);
|
795
|
-
this.buildInfo.contextDependencies = new LazySet();
|
796
813
|
this.buildInfo.contextDependencies.addAll(result.contextDependencies);
|
797
|
-
this.buildInfo.missingDependencies = new LazySet();
|
798
814
|
this.buildInfo.missingDependencies.addAll(result.missingDependencies);
|
799
|
-
if (
|
800
|
-
this.loaders.length > 0 &&
|
801
|
-
this.buildInfo.buildDependencies === undefined
|
802
|
-
) {
|
803
|
-
this.buildInfo.buildDependencies = new LazySet();
|
804
|
-
}
|
805
815
|
for (const loader of this.loaders) {
|
806
816
|
this.buildInfo.buildDependencies.add(loader.loader);
|
807
817
|
}
|
808
|
-
this.buildInfo.cacheable = result.cacheable;
|
818
|
+
this.buildInfo.cacheable = this.buildInfo.cacheable && result.cacheable;
|
809
819
|
processResult(err, result.result);
|
810
820
|
}
|
811
821
|
);
|
@@ -1174,7 +1184,8 @@ class NormalModule extends Module {
|
|
1174
1184
|
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
1175
1185
|
* @returns {void}
|
1176
1186
|
*/
|
1177
|
-
needBuild(
|
1187
|
+
needBuild(context, callback) {
|
1188
|
+
const { fileSystemInfo, compilation, valueCacheVersions } = context;
|
1178
1189
|
// build if enforced
|
1179
1190
|
if (this._forceBuild) return callback(null, true);
|
1180
1191
|
|
@@ -1209,7 +1220,20 @@ class NormalModule extends Module {
|
|
1209
1220
|
|
1210
1221
|
// check snapshot for validity
|
1211
1222
|
fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
|
1212
|
-
callback(err
|
1223
|
+
if (err) return callback(err);
|
1224
|
+
if (!valid) return callback(null, true);
|
1225
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
1226
|
+
hooks.needBuild.callAsync(this, context, (err, needBuild) => {
|
1227
|
+
if (err) {
|
1228
|
+
return callback(
|
1229
|
+
HookWebpackError.makeWebpackError(
|
1230
|
+
err,
|
1231
|
+
"NormalModule.getCompilationHooks().needBuild"
|
1232
|
+
)
|
1233
|
+
);
|
1234
|
+
}
|
1235
|
+
callback(null, !!needBuild);
|
1236
|
+
});
|
1213
1237
|
});
|
1214
1238
|
}
|
1215
1239
|
|
@@ -1294,6 +1318,7 @@ class NormalModule extends Module {
|
|
1294
1318
|
type: "",
|
1295
1319
|
// will be filled by updateCacheModule
|
1296
1320
|
resource: "",
|
1321
|
+
context: "",
|
1297
1322
|
request: null,
|
1298
1323
|
userRequest: null,
|
1299
1324
|
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,
|
@@ -20,7 +21,7 @@ const ModuleGraph = require("./ModuleGraph");
|
|
20
21
|
const NormalModule = require("./NormalModule");
|
21
22
|
const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
|
22
23
|
const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
|
23
|
-
const
|
24
|
+
const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin");
|
24
25
|
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
25
26
|
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
26
27
|
const LazySet = require("./util/LazySet");
|
@@ -44,7 +45,9 @@ const { parseResource } = require("./util/identifier");
|
|
44
45
|
* @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
|
45
46
|
* @property {string} context
|
46
47
|
* @property {string} request
|
48
|
+
* @property {Record<string, any> | undefined} assertions
|
47
49
|
* @property {ModuleDependency[]} dependencies
|
50
|
+
* @property {string} dependencyType
|
48
51
|
* @property {Object} createData
|
49
52
|
* @property {LazySet<string>} fileDependencies
|
50
53
|
* @property {LazySet<string>} missingDependencies
|
@@ -58,6 +61,7 @@ const { parseResource } = require("./util/identifier");
|
|
58
61
|
* @property {string} path
|
59
62
|
* @property {string} query
|
60
63
|
* @property {string} fragment
|
64
|
+
* @property {string=} context
|
61
65
|
*/
|
62
66
|
|
63
67
|
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
|
@@ -65,6 +69,7 @@ const { parseResource } = require("./util/identifier");
|
|
65
69
|
const EMPTY_RESOLVE_OPTIONS = {};
|
66
70
|
const EMPTY_PARSER_OPTIONS = {};
|
67
71
|
const EMPTY_GENERATOR_OPTIONS = {};
|
72
|
+
const EMPTY_ELEMENTS = [];
|
68
73
|
|
69
74
|
const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/;
|
70
75
|
|
@@ -182,7 +187,8 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
182
187
|
new BasicMatcherRulePlugin("issuer"),
|
183
188
|
new BasicMatcherRulePlugin("compiler"),
|
184
189
|
new BasicMatcherRulePlugin("issuerLayer"),
|
185
|
-
new
|
190
|
+
new ObjectMatcherRulePlugin("assert", "assertions"),
|
191
|
+
new ObjectMatcherRulePlugin("descriptionData"),
|
186
192
|
new BasicEffectRulePlugin("type"),
|
187
193
|
new BasicEffectRulePlugin("sideEffects"),
|
188
194
|
new BasicEffectRulePlugin("parser"),
|
@@ -218,6 +224,10 @@ class NormalModuleFactory extends ModuleFactory {
|
|
218
224
|
resolveForScheme: new HookMap(
|
219
225
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
220
226
|
),
|
227
|
+
/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
|
228
|
+
resolveInScheme: new HookMap(
|
229
|
+
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
230
|
+
),
|
221
231
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
222
232
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
223
233
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
@@ -338,55 +348,84 @@ class NormalModuleFactory extends ModuleFactory {
|
|
338
348
|
contextInfo,
|
339
349
|
context,
|
340
350
|
dependencies,
|
351
|
+
dependencyType,
|
341
352
|
request,
|
353
|
+
assertions,
|
342
354
|
resolveOptions,
|
343
355
|
fileDependencies,
|
344
356
|
missingDependencies,
|
345
357
|
contextDependencies
|
346
358
|
} = data;
|
347
|
-
const dependencyType =
|
348
|
-
(dependencies.length > 0 && dependencies[0].category) || "";
|
349
359
|
const loaderResolver = this.getResolver("loader");
|
350
360
|
|
351
361
|
/** @type {ResourceData | undefined} */
|
352
362
|
let matchResourceData = undefined;
|
353
363
|
/** @type {string} */
|
354
|
-
let
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
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
|
+
}
|
367
391
|
}
|
392
|
+
matchResourceData = {
|
393
|
+
resource: matchResource,
|
394
|
+
...cacheParseResource(matchResource)
|
395
|
+
};
|
396
|
+
requestWithoutMatchResource = request.substr(
|
397
|
+
matchResourceMatch[0].length
|
398
|
+
);
|
368
399
|
}
|
369
|
-
matchResourceData = {
|
370
|
-
resource: matchResource,
|
371
|
-
...cacheParseResource(matchResource)
|
372
|
-
};
|
373
|
-
requestWithoutMatchResource = request.substr(
|
374
|
-
matchResourceMatch[0].length
|
375
|
-
);
|
376
|
-
}
|
377
400
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
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
|
+
}
|
390
429
|
|
391
430
|
const resolveContext = {
|
392
431
|
fileDependencies,
|
@@ -396,8 +435,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
396
435
|
|
397
436
|
/** @type {ResourceDataWithData} */
|
398
437
|
let resourceData;
|
399
|
-
/** @type {string | undefined} */
|
400
|
-
const scheme = getScheme(unresolvedResource);
|
401
438
|
|
402
439
|
let loaders;
|
403
440
|
|
@@ -447,6 +484,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
447
484
|
resourceQuery: resourceDataForRules.query,
|
448
485
|
resourceFragment: resourceDataForRules.fragment,
|
449
486
|
scheme,
|
487
|
+
assertions,
|
450
488
|
mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
|
451
489
|
dependency: dependencyType,
|
452
490
|
descriptionData: matchResourceData
|
@@ -536,6 +574,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
536
574
|
rawRequest: request,
|
537
575
|
loaders: allLoaders,
|
538
576
|
resource: resourceData.resource,
|
577
|
+
context:
|
578
|
+
resourceData.context || getContext(resourceData.resource),
|
539
579
|
matchResource: matchResourceData
|
540
580
|
? matchResourceData.resource
|
541
581
|
: undefined,
|
@@ -590,7 +630,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
590
630
|
|
591
631
|
this.resolveRequestArray(
|
592
632
|
contextInfo,
|
593
|
-
context,
|
633
|
+
contextScheme ? this.context : context,
|
594
634
|
elements,
|
595
635
|
loaderResolver,
|
596
636
|
resolveContext,
|
@@ -601,6 +641,49 @@ class NormalModuleFactory extends ModuleFactory {
|
|
601
641
|
}
|
602
642
|
);
|
603
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
|
+
|
604
687
|
// resource with scheme
|
605
688
|
if (scheme) {
|
606
689
|
resourceData = {
|
@@ -608,7 +691,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
608
691
|
data: {},
|
609
692
|
path: undefined,
|
610
693
|
query: undefined,
|
611
|
-
fragment: undefined
|
694
|
+
fragment: undefined,
|
695
|
+
context: undefined
|
612
696
|
};
|
613
697
|
this.hooks.resolveForScheme
|
614
698
|
.for(scheme)
|
@@ -618,47 +702,27 @@ class NormalModuleFactory extends ModuleFactory {
|
|
618
702
|
});
|
619
703
|
}
|
620
704
|
|
621
|
-
// resource
|
622
|
-
else if (
|
705
|
+
// resource within scheme
|
706
|
+
else if (contextScheme) {
|
623
707
|
resourceData = {
|
624
708
|
resource: unresolvedResource,
|
625
709
|
data: {},
|
626
|
-
|
710
|
+
path: undefined,
|
711
|
+
query: undefined,
|
712
|
+
fragment: undefined,
|
713
|
+
context: undefined
|
627
714
|
};
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
// resource without scheme and with path
|
632
|
-
else {
|
633
|
-
const normalResolver = this.getResolver(
|
634
|
-
"normal",
|
635
|
-
dependencyType
|
636
|
-
? cachedSetProperty(
|
637
|
-
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
638
|
-
"dependencyType",
|
639
|
-
dependencyType
|
640
|
-
)
|
641
|
-
: resolveOptions
|
642
|
-
);
|
643
|
-
this.resolveResource(
|
644
|
-
contextInfo,
|
645
|
-
context,
|
646
|
-
unresolvedResource,
|
647
|
-
normalResolver,
|
648
|
-
resolveContext,
|
649
|
-
(err, resolvedResource, resolvedResourceResolveData) => {
|
715
|
+
this.hooks.resolveInScheme
|
716
|
+
.for(contextScheme)
|
717
|
+
.callAsync(resourceData, data, (err, handled) => {
|
650
718
|
if (err) return continueCallback(err);
|
651
|
-
if (
|
652
|
-
resourceData = {
|
653
|
-
resource: resolvedResource,
|
654
|
-
data: resolvedResourceResolveData,
|
655
|
-
...cacheParseResource(resolvedResource)
|
656
|
-
};
|
657
|
-
}
|
719
|
+
if (!handled) return defaultResolve(this.context);
|
658
720
|
continueCallback();
|
659
|
-
}
|
660
|
-
);
|
721
|
+
});
|
661
722
|
}
|
723
|
+
|
724
|
+
// resource without scheme and without path
|
725
|
+
else defaultResolve(context);
|
662
726
|
}
|
663
727
|
);
|
664
728
|
}
|
@@ -694,17 +758,22 @@ class NormalModuleFactory extends ModuleFactory {
|
|
694
758
|
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
|
695
759
|
const dependency = dependencies[0];
|
696
760
|
const request = dependency.request;
|
761
|
+
const assertions = dependency.assertions;
|
697
762
|
const contextInfo = data.contextInfo;
|
698
763
|
const fileDependencies = new LazySet();
|
699
764
|
const missingDependencies = new LazySet();
|
700
765
|
const contextDependencies = new LazySet();
|
766
|
+
const dependencyType =
|
767
|
+
(dependencies.length > 0 && dependencies[0].category) || "";
|
701
768
|
/** @type {ResolveData} */
|
702
769
|
const resolveData = {
|
703
770
|
contextInfo,
|
704
771
|
resolveOptions,
|
705
772
|
context,
|
706
773
|
request,
|
774
|
+
assertions,
|
707
775
|
dependencies,
|
776
|
+
dependencyType,
|
708
777
|
fileDependencies,
|
709
778
|
missingDependencies,
|
710
779
|
contextDependencies,
|
@@ -851,7 +920,7 @@ ${hints.join("\n\n")}`;
|
|
851
920
|
null,
|
852
921
|
`Did you mean '${resource}'?
|
853
922
|
BREAKING CHANGE: The request '${unresolvedResource}' failed to resolve only because it was resolved as fully specified
|
854
|
-
(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"').
|
855
924
|
The extension in the request is mandatory for it to be fully specified.
|
856
925
|
Add the extension to the request.`
|
857
926
|
);
|
package/lib/Template.js
CHANGED
@@ -350,7 +350,7 @@ class Template {
|
|
350
350
|
|
351
351
|
/**
|
352
352
|
* @param {RuntimeModule[]} runtimeModules array of runtime modules in order
|
353
|
-
* @param {RenderContext & { codeGenerationResults?: CodeGenerationResults
|
353
|
+
* @param {RenderContext & { codeGenerationResults?: CodeGenerationResults }} renderContext render context
|
354
354
|
* @returns {Source} rendered runtime modules in a Source object
|
355
355
|
*/
|
356
356
|
static renderRuntimeModules(runtimeModules, renderContext) {
|
@@ -382,12 +382,10 @@ class Template {
|
|
382
382
|
source.add("\n\n");
|
383
383
|
} else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
|
384
384
|
source.add("(() => {\n");
|
385
|
-
if (renderContext.useStrict) source.add('\t"use strict";\n');
|
386
385
|
source.add(new PrefixSource("\t", runtimeSource));
|
387
386
|
source.add("\n})();\n\n");
|
388
387
|
} else {
|
389
388
|
source.add("!function() {\n");
|
390
|
-
if (renderContext.useStrict) source.add('\t"use strict";\n');
|
391
389
|
source.add(new PrefixSource("\t", runtimeSource));
|
392
390
|
source.add("\n}();\n\n");
|
393
391
|
}
|
@@ -406,7 +404,6 @@ class Template {
|
|
406
404
|
"/******/ ",
|
407
405
|
new ConcatSource(
|
408
406
|
"function(__webpack_require__) { // webpackRuntimeModules\n",
|
409
|
-
'"use strict";\n\n',
|
410
407
|
this.renderRuntimeModules(runtimeModules, renderContext),
|
411
408
|
"}\n"
|
412
409
|
)
|