webpack 5.51.2 → 5.52.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/bin/webpack.js +0 -0
- package/lib/ExternalModule.js +25 -16
- package/lib/InitFragment.js +23 -0
- package/lib/NormalModuleFactory.js +7 -4
- package/lib/WebpackOptionsApply.js +1 -3
- package/lib/config/defaults.js +0 -1
- package/lib/dependencies/LoaderPlugin.js +94 -98
- package/lib/optimize/MangleExportsPlugin.js +21 -4
- package/lib/util/internalSerializables.js +1 -0
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +0 -4
- package/types.d.ts +2 -5
package/bin/webpack.js
CHANGED
File without changes
|
package/lib/ExternalModule.js
CHANGED
@@ -13,6 +13,7 @@ const Module = require("./Module");
|
|
13
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
14
14
|
const Template = require("./Template");
|
15
15
|
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
16
|
+
const createHash = require("./util/createHash");
|
16
17
|
const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
|
17
18
|
const makeSerializable = require("./util/makeSerializable");
|
18
19
|
const propertyAccess = require("./util/propertyAccess");
|
@@ -159,18 +160,25 @@ const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => {
|
|
159
160
|
};
|
160
161
|
|
161
162
|
class ModuleExternalInitFragment extends InitFragment {
|
162
|
-
constructor(
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
constructor(request, ident) {
|
164
|
+
if (ident === undefined) {
|
165
|
+
ident = Template.toIdentifier(request);
|
166
|
+
if (ident !== request) {
|
167
|
+
ident += `_${createHash("md4")
|
168
|
+
.update(request)
|
169
|
+
.digest("hex")
|
170
|
+
.slice(0, 8)}`;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
166
174
|
super(
|
167
175
|
`import * as ${identifier} from ${JSON.stringify(request)};\n`,
|
168
176
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
169
177
|
0,
|
170
|
-
`external module import ${
|
178
|
+
`external module import ${ident}`
|
171
179
|
);
|
180
|
+
this._ident = ident;
|
172
181
|
this._identifier = identifier;
|
173
|
-
this._id = id;
|
174
182
|
this._request = request;
|
175
183
|
}
|
176
184
|
|
@@ -185,8 +193,8 @@ register(
|
|
185
193
|
"ModuleExternalInitFragment",
|
186
194
|
{
|
187
195
|
serialize(obj, { write }) {
|
188
|
-
write(obj._id);
|
189
196
|
write(obj._request);
|
197
|
+
write(obj._ident);
|
190
198
|
},
|
191
199
|
deserialize({ read }) {
|
192
200
|
return new ModuleExternalInitFragment(read(), read());
|
@@ -236,10 +244,7 @@ const getSourceForModuleExternal = (
|
|
236
244
|
) => {
|
237
245
|
if (!Array.isArray(moduleAndSpecifiers))
|
238
246
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
239
|
-
const initFragment = new ModuleExternalInitFragment(
|
240
|
-
id,
|
241
|
-
moduleAndSpecifiers[0]
|
242
|
-
);
|
247
|
+
const initFragment = new ModuleExternalInitFragment(moduleAndSpecifiers[0]);
|
243
248
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
244
249
|
moduleAndSpecifiers,
|
245
250
|
1
|
@@ -400,7 +405,7 @@ class ExternalModule extends Module {
|
|
400
405
|
* @returns {string} a unique identifier of the module
|
401
406
|
*/
|
402
407
|
identifier() {
|
403
|
-
return
|
408
|
+
return `external ${this.externalType} ${JSON.stringify(this.request)}`;
|
404
409
|
}
|
405
410
|
|
406
411
|
/**
|
@@ -531,18 +536,20 @@ class ExternalModule extends Module {
|
|
531
536
|
case "umd":
|
532
537
|
case "umd2":
|
533
538
|
case "system":
|
534
|
-
case "jsonp":
|
539
|
+
case "jsonp": {
|
540
|
+
const id = chunkGraph.getModuleId(this);
|
535
541
|
return getSourceForAmdOrUmdExternal(
|
536
|
-
|
542
|
+
id !== null ? id : this.identifier(),
|
537
543
|
this.isOptional(moduleGraph),
|
538
544
|
request,
|
539
545
|
runtimeTemplate
|
540
546
|
);
|
547
|
+
}
|
541
548
|
case "import":
|
542
549
|
return getSourceForImportExternal(request, runtimeTemplate);
|
543
550
|
case "script":
|
544
551
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
545
|
-
case "module":
|
552
|
+
case "module": {
|
546
553
|
if (!this.buildInfo.module) {
|
547
554
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
548
555
|
throw new Error(
|
@@ -559,12 +566,14 @@ class ExternalModule extends Module {
|
|
559
566
|
"The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
|
560
567
|
);
|
561
568
|
}
|
569
|
+
const id = chunkGraph.getModuleId(this);
|
562
570
|
return getSourceForModuleExternal(
|
563
|
-
|
571
|
+
id !== null ? id : this.identifier(),
|
564
572
|
request,
|
565
573
|
moduleGraph.getExportsInfo(this),
|
566
574
|
runtime
|
567
575
|
);
|
576
|
+
}
|
568
577
|
case "var":
|
569
578
|
case "promise":
|
570
579
|
case "const":
|
package/lib/InitFragment.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
9
10
|
|
10
11
|
/** @typedef {import("webpack-sources").Source} Source */
|
11
12
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
@@ -123,8 +124,30 @@ class InitFragment {
|
|
123
124
|
return source;
|
124
125
|
}
|
125
126
|
}
|
127
|
+
|
128
|
+
serialize(context) {
|
129
|
+
const { write } = context;
|
130
|
+
|
131
|
+
write(this.content);
|
132
|
+
write(this.stage);
|
133
|
+
write(this.position);
|
134
|
+
write(this.key);
|
135
|
+
write(this.endContent);
|
136
|
+
}
|
137
|
+
|
138
|
+
deserialize(context) {
|
139
|
+
const { read } = context;
|
140
|
+
|
141
|
+
this.content = read();
|
142
|
+
this.stage = read();
|
143
|
+
this.position = read();
|
144
|
+
this.key = read();
|
145
|
+
this.endContent = read();
|
146
|
+
}
|
126
147
|
}
|
127
148
|
|
149
|
+
makeSerializable(InitFragment, "webpack/lib/InitFragment");
|
150
|
+
|
128
151
|
InitFragment.prototype.merge = undefined;
|
129
152
|
|
130
153
|
InitFragment.STAGE_CONSTANTS = 10;
|
@@ -540,15 +540,18 @@ class NormalModuleFactory extends ModuleFactory {
|
|
540
540
|
for (const loader of preLoaders) allLoaders.push(loader);
|
541
541
|
let type = settings.type;
|
542
542
|
if (!type) {
|
543
|
-
|
544
|
-
(matchResourceData && matchResourceData.resource) ||
|
545
|
-
resourceData.resource;
|
543
|
+
let resource;
|
546
544
|
let match;
|
547
545
|
if (
|
548
|
-
|
546
|
+
matchResourceData &&
|
547
|
+
typeof (resource = matchResourceData.resource) === "string" &&
|
549
548
|
(match = /\.webpack\[([^\]]+)\]$/.exec(resource))
|
550
549
|
) {
|
551
550
|
type = match[1];
|
551
|
+
matchResourceData.resource = matchResourceData.resource.slice(
|
552
|
+
0,
|
553
|
+
-type.length - 10
|
554
|
+
);
|
552
555
|
} else {
|
553
556
|
type = "javascript/auto";
|
554
557
|
}
|
@@ -305,9 +305,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
305
305
|
new RequireJsStuffPlugin().apply(compiler);
|
306
306
|
}
|
307
307
|
new CommonJsPlugin().apply(compiler);
|
308
|
-
new LoaderPlugin({
|
309
|
-
enableExecuteModule: options.experiments.executeModule
|
310
|
-
}).apply(compiler);
|
308
|
+
new LoaderPlugin({}).apply(compiler);
|
311
309
|
if (options.node !== false) {
|
312
310
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
313
311
|
new NodeStuffPlugin(options.node).apply(compiler);
|
package/lib/config/defaults.js
CHANGED
@@ -259,7 +259,6 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
|
|
259
259
|
D(experiments, "asyncWebAssembly", false);
|
260
260
|
D(experiments, "outputModule", false);
|
261
261
|
D(experiments, "asset", false);
|
262
|
-
D(experiments, "executeModule", false);
|
263
262
|
D(experiments, "layers", false);
|
264
263
|
D(experiments, "lazyCompilation", false);
|
265
264
|
D(experiments, "buildHttp", false);
|
@@ -37,11 +37,9 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
37
37
|
class LoaderPlugin {
|
38
38
|
/**
|
39
39
|
* @param {Object} options options
|
40
|
-
* @param {boolean=} options.enableExecuteModule execute module enabled
|
41
40
|
*/
|
42
|
-
constructor(options = {}) {
|
43
|
-
|
44
|
-
}
|
41
|
+
constructor(options = {}) {}
|
42
|
+
|
45
43
|
/**
|
46
44
|
* Apply the plugin
|
47
45
|
* @param {Compiler} compiler the compiler instance
|
@@ -155,106 +153,104 @@ class LoaderPlugin {
|
|
155
153
|
);
|
156
154
|
};
|
157
155
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
const
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
156
|
+
/**
|
157
|
+
* @param {string} request the request string to load the module from
|
158
|
+
* @param {ImportModuleOptions=} options options
|
159
|
+
* @param {ImportModuleCallback=} callback callback returning the exports
|
160
|
+
* @returns {void}
|
161
|
+
*/
|
162
|
+
const importModule = (request, options, callback) => {
|
163
|
+
const dep = new LoaderImportDependency(request);
|
164
|
+
dep.loc = {
|
165
|
+
name: request
|
166
|
+
};
|
167
|
+
const factory = compilation.dependencyFactories.get(
|
168
|
+
/** @type {DepConstructor} */ (dep.constructor)
|
169
|
+
);
|
170
|
+
if (factory === undefined) {
|
171
|
+
return callback(
|
172
|
+
new Error(
|
173
|
+
`No module factory available for dependency type: ${dep.constructor.name}`
|
174
|
+
)
|
172
175
|
);
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
{
|
183
|
-
factory,
|
184
|
-
dependencies: [dep],
|
185
|
-
originModule: loaderContext._module,
|
186
|
-
contextInfo: {
|
187
|
-
issuerLayer: options.layer
|
188
|
-
},
|
189
|
-
context: loaderContext.context,
|
190
|
-
connectOrigin: false
|
176
|
+
}
|
177
|
+
compilation.buildQueue.increaseParallelism();
|
178
|
+
compilation.handleModuleCreation(
|
179
|
+
{
|
180
|
+
factory,
|
181
|
+
dependencies: [dep],
|
182
|
+
originModule: loaderContext._module,
|
183
|
+
contextInfo: {
|
184
|
+
issuerLayer: options.layer
|
191
185
|
},
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
buildInfo.assets
|
231
|
-
buildInfo.assetsInfo
|
186
|
+
context: loaderContext.context,
|
187
|
+
connectOrigin: false
|
188
|
+
},
|
189
|
+
err => {
|
190
|
+
compilation.buildQueue.decreaseParallelism();
|
191
|
+
if (err) {
|
192
|
+
return callback(err);
|
193
|
+
}
|
194
|
+
const referencedModule = moduleGraph.getModule(dep);
|
195
|
+
if (!referencedModule) {
|
196
|
+
return callback(new Error("Cannot load the module"));
|
197
|
+
}
|
198
|
+
compilation.executeModule(
|
199
|
+
referencedModule,
|
200
|
+
{
|
201
|
+
entryOptions: {
|
202
|
+
publicPath: options.publicPath
|
203
|
+
}
|
204
|
+
},
|
205
|
+
(err, result) => {
|
206
|
+
if (err) return callback(err);
|
207
|
+
for (const d of result.fileDependencies) {
|
208
|
+
loaderContext.addDependency(d);
|
209
|
+
}
|
210
|
+
for (const d of result.contextDependencies) {
|
211
|
+
loaderContext.addContextDependency(d);
|
212
|
+
}
|
213
|
+
for (const d of result.missingDependencies) {
|
214
|
+
loaderContext.addMissingDependency(d);
|
215
|
+
}
|
216
|
+
for (const d of result.buildDependencies) {
|
217
|
+
loaderContext.addBuildDependency(d);
|
218
|
+
}
|
219
|
+
if (result.cacheable === false)
|
220
|
+
loaderContext.cacheable(false);
|
221
|
+
for (const [name, { source, info }] of result.assets) {
|
222
|
+
const { buildInfo } = loaderContext._module;
|
223
|
+
if (!buildInfo.assets) {
|
224
|
+
buildInfo.assets = Object.create(null);
|
225
|
+
buildInfo.assetsInfo = new Map();
|
232
226
|
}
|
233
|
-
|
227
|
+
buildInfo.assets[name] = source;
|
228
|
+
buildInfo.assetsInfo.set(name, info);
|
234
229
|
}
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
230
|
+
callback(null, result.exports);
|
231
|
+
}
|
232
|
+
);
|
233
|
+
}
|
234
|
+
);
|
235
|
+
};
|
239
236
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
});
|
237
|
+
/**
|
238
|
+
* @param {string} request the request string to load the module from
|
239
|
+
* @param {ImportModuleOptions} options options
|
240
|
+
* @param {ImportModuleCallback=} callback callback returning the exports
|
241
|
+
* @returns {Promise<any> | void} exports
|
242
|
+
*/
|
243
|
+
loaderContext.importModule = (request, options, callback) => {
|
244
|
+
if (!callback) {
|
245
|
+
return new Promise((resolve, reject) => {
|
246
|
+
importModule(request, options || {}, (err, result) => {
|
247
|
+
if (err) reject(err);
|
248
|
+
else resolve(result);
|
253
249
|
});
|
254
|
-
}
|
255
|
-
|
256
|
-
};
|
257
|
-
}
|
250
|
+
});
|
251
|
+
}
|
252
|
+
return importModule(request, options || {}, callback);
|
253
|
+
};
|
258
254
|
}
|
259
255
|
);
|
260
256
|
});
|
@@ -39,13 +39,28 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
|
|
39
39
|
/**
|
40
40
|
* @param {boolean} deterministic use deterministic names
|
41
41
|
* @param {ExportsInfo} exportsInfo exports info
|
42
|
+
* @param {boolean} isNamespace is namespace object
|
42
43
|
* @returns {void}
|
43
44
|
*/
|
44
|
-
const mangleExportsInfo = (deterministic, exportsInfo) => {
|
45
|
+
const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
45
46
|
if (!canMangle(exportsInfo)) return;
|
46
47
|
const usedNames = new Set();
|
47
48
|
/** @type {ExportInfo[]} */
|
48
49
|
const mangleableExports = [];
|
50
|
+
|
51
|
+
// Avoid to renamed exports that are not provided when
|
52
|
+
// 1. it's not a namespace export: non-provided exports can be found in prototype chain
|
53
|
+
// 2. there are other provided exports and deterministic mode is chosen:
|
54
|
+
// non-provided exports would break the determinism
|
55
|
+
let avoidMangleNonProvided = !isNamespace;
|
56
|
+
if (!avoidMangleNonProvided && deterministic) {
|
57
|
+
for (const exportInfo of exportsInfo.ownedExports) {
|
58
|
+
if (exportInfo.provided !== false) {
|
59
|
+
avoidMangleNonProvided = true;
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
49
64
|
for (const exportInfo of exportsInfo.ownedExports) {
|
50
65
|
const name = exportInfo.name;
|
51
66
|
if (!exportInfo.hasUsedName()) {
|
@@ -59,7 +74,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
|
|
59
74
|
name.length === 2 &&
|
60
75
|
/^[a-zA-Z_$][a-zA-Z0-9_$]|^[1-9][0-9]/.test(name)) ||
|
61
76
|
// Don't rename exports that are not provided
|
62
|
-
exportInfo.provided !== true
|
77
|
+
(avoidMangleNonProvided && exportInfo.provided !== true)
|
63
78
|
) {
|
64
79
|
exportInfo.setUsedName(name);
|
65
80
|
usedNames.add(name);
|
@@ -73,7 +88,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
|
|
73
88
|
used === UsageState.OnlyPropertiesUsed ||
|
74
89
|
used === UsageState.Unused
|
75
90
|
) {
|
76
|
-
mangleExportsInfo(deterministic, exportInfo.exportsInfo);
|
91
|
+
mangleExportsInfo(deterministic, exportInfo.exportsInfo, false);
|
77
92
|
}
|
78
93
|
}
|
79
94
|
}
|
@@ -143,8 +158,10 @@ class MangleExportsPlugin {
|
|
143
158
|
"MangleExportsPlugin",
|
144
159
|
modules => {
|
145
160
|
for (const module of modules) {
|
161
|
+
const isNamespace =
|
162
|
+
module.buildMeta && module.buildMeta.exportsType === "namespace";
|
146
163
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
147
|
-
mangleExportsInfo(deterministic, exportsInfo);
|
164
|
+
mangleExportsInfo(deterministic, exportsInfo, isNamespace);
|
148
165
|
}
|
149
166
|
}
|
150
167
|
);
|
@@ -164,6 +164,7 @@ module.exports = {
|
|
164
164
|
DllModule: () => require("../DllModule"),
|
165
165
|
ExternalModule: () => require("../ExternalModule"),
|
166
166
|
FileSystemInfo: () => require("../FileSystemInfo"),
|
167
|
+
InitFragment: () => require("../InitFragment"),
|
167
168
|
InvalidDependenciesModuleWarning: () =>
|
168
169
|
require("../InvalidDependenciesModuleWarning"),
|
169
170
|
Module: () => require("../Module"),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.52.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
@@ -58,15 +58,15 @@
|
|
58
58
|
"eslint-plugin-jest": "^24.3.6",
|
59
59
|
"eslint-plugin-jsdoc": "^33.0.0",
|
60
60
|
"eslint-plugin-node": "^11.0.0",
|
61
|
-
"eslint-plugin-prettier": "^
|
61
|
+
"eslint-plugin-prettier": "^4.0.0",
|
62
62
|
"file-loader": "^6.0.0",
|
63
63
|
"fork-ts-checker-webpack-plugin": "^6.0.5",
|
64
64
|
"husky": "^6.0.0",
|
65
65
|
"is-ci": "^3.0.0",
|
66
66
|
"istanbul": "^0.4.5",
|
67
67
|
"jest": "^27.0.6",
|
68
|
-
"jest-cli": "^27.0.6",
|
69
68
|
"jest-circus": "^27.0.6",
|
69
|
+
"jest-cli": "^27.0.6",
|
70
70
|
"jest-diff": "^27.0.2",
|
71
71
|
"jest-junit": "^12.0.0",
|
72
72
|
"json-loader": "^0.5.7",
|