webpack 5.47.0 → 5.50.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/CompatibilityPlugin.js +21 -4
- 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 +47 -20
- package/lib/NormalModuleFactory.js +145 -76
- package/lib/Parser.js +1 -0
- package/lib/WebpackOptionsApply.js +8 -0
- package/lib/asset/AssetModulesPlugin.js +0 -1
- package/lib/config/defaults.js +45 -18
- package/lib/config/normalization.js +6 -1
- 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/JavascriptParser.js +16 -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 +293 -267
- 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 +99 -15
- package/lib/schemes/HttpsUriPlugin.js +0 -63
@@ -69,7 +69,8 @@ class CompatibilityPlugin {
|
|
69
69
|
* @param {JavascriptParser} parser the parser
|
70
70
|
* @returns {void}
|
71
71
|
*/
|
72
|
-
const
|
72
|
+
const handler = parser => {
|
73
|
+
// Handle nested requires
|
73
74
|
parser.hooks.preStatement.tap("CompatibilityPlugin", statement => {
|
74
75
|
if (
|
75
76
|
statement.type === "FunctionDeclaration" &&
|
@@ -117,17 +118,33 @@ class CompatibilityPlugin {
|
|
117
118
|
parser.state.module.addPresentationalDependency(dep);
|
118
119
|
return true;
|
119
120
|
});
|
121
|
+
|
122
|
+
// Handle hashbang
|
123
|
+
parser.hooks.program.tap(
|
124
|
+
"CompatibilityPlugin",
|
125
|
+
(program, comments) => {
|
126
|
+
if (comments.length === 0) return;
|
127
|
+
const c = comments[0];
|
128
|
+
if (c.type === "Line" && c.range[0] === 0) {
|
129
|
+
if (parser.state.source.slice(0, 2).toString() !== "#!") return;
|
130
|
+
// this is a hashbang comment
|
131
|
+
const dep = new ConstDependency("//", 0);
|
132
|
+
dep.loc = c.loc;
|
133
|
+
parser.state.module.addPresentationalDependency(dep);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
);
|
120
137
|
};
|
121
138
|
|
122
139
|
normalModuleFactory.hooks.parser
|
123
140
|
.for("javascript/auto")
|
124
|
-
.tap("CompatibilityPlugin",
|
141
|
+
.tap("CompatibilityPlugin", handler);
|
125
142
|
normalModuleFactory.hooks.parser
|
126
143
|
.for("javascript/dynamic")
|
127
|
-
.tap("CompatibilityPlugin",
|
144
|
+
.tap("CompatibilityPlugin", handler);
|
128
145
|
normalModuleFactory.hooks.parser
|
129
146
|
.for("javascript/esm")
|
130
|
-
.tap("CompatibilityPlugin",
|
147
|
+
.tap("CompatibilityPlugin", handler);
|
131
148
|
}
|
132
149
|
);
|
133
150
|
}
|
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
|
);
|
@@ -1015,7 +1025,9 @@ class NormalModule extends Module {
|
|
1015
1025
|
|
1016
1026
|
let result;
|
1017
1027
|
try {
|
1018
|
-
|
1028
|
+
const source = this._source.source();
|
1029
|
+
result = this.parser.parse(this._ast || source, {
|
1030
|
+
source,
|
1019
1031
|
current: this,
|
1020
1032
|
module: this,
|
1021
1033
|
compilation: compilation,
|
@@ -1174,7 +1186,8 @@ class NormalModule extends Module {
|
|
1174
1186
|
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
1175
1187
|
* @returns {void}
|
1176
1188
|
*/
|
1177
|
-
needBuild(
|
1189
|
+
needBuild(context, callback) {
|
1190
|
+
const { fileSystemInfo, compilation, valueCacheVersions } = context;
|
1178
1191
|
// build if enforced
|
1179
1192
|
if (this._forceBuild) return callback(null, true);
|
1180
1193
|
|
@@ -1209,7 +1222,20 @@ class NormalModule extends Module {
|
|
1209
1222
|
|
1210
1223
|
// check snapshot for validity
|
1211
1224
|
fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
|
1212
|
-
callback(err
|
1225
|
+
if (err) return callback(err);
|
1226
|
+
if (!valid) return callback(null, true);
|
1227
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
1228
|
+
hooks.needBuild.callAsync(this, context, (err, needBuild) => {
|
1229
|
+
if (err) {
|
1230
|
+
return callback(
|
1231
|
+
HookWebpackError.makeWebpackError(
|
1232
|
+
err,
|
1233
|
+
"NormalModule.getCompilationHooks().needBuild"
|
1234
|
+
)
|
1235
|
+
);
|
1236
|
+
}
|
1237
|
+
callback(null, !!needBuild);
|
1238
|
+
});
|
1213
1239
|
});
|
1214
1240
|
}
|
1215
1241
|
|
@@ -1294,6 +1320,7 @@ class NormalModule extends Module {
|
|
1294
1320
|
type: "",
|
1295
1321
|
// will be filled by updateCacheModule
|
1296
1322
|
resource: "",
|
1323
|
+
context: "",
|
1297
1324
|
request: null,
|
1298
1325
|
userRequest: null,
|
1299
1326
|
rawRequest: null,
|