webpack 5.42.0 → 5.45.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/Compiler.js +4 -4
- package/lib/ExternalModule.js +18 -0
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +14 -15
- package/lib/FlagDependencyUsagePlugin.js +5 -1
- package/lib/MultiCompiler.js +10 -8
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleFactory.js +9 -2
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/Template.js +1 -0
- package/lib/Watching.js +12 -0
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/config/defaults.js +18 -12
- package/lib/container/ContainerPlugin.js +4 -1
- package/lib/container/ModuleFederationPlugin.js +1 -0
- 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/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +29 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +91 -11
- package/lib/esm/ModuleChunkLoadingPlugin.js +13 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +46 -37
- package/lib/hmr/lazyCompilationBackend.js +5 -2
- package/lib/javascript/JavascriptParser.js +14 -9
- package/lib/json/JsonData.js +41 -0
- package/lib/json/JsonGenerator.js +8 -2
- package/lib/json/JsonParser.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +16 -0
- package/lib/optimize/RuntimeChunkPlugin.js +1 -1
- package/lib/rules/{DescriptionDataMatcherRulePlugin.js → ObjectMatcherRulePlugin.js} +14 -10
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/util/StackedCacheMap.js +110 -0
- package/lib/util/internalSerializables.js +1 -0
- package/lib/util/makeSerializable.js +0 -1
- package/lib/webpack.js +1 -1
- package/package.json +25 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +16 -2
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +15 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +15 -0
- package/types.d.ts +60 -17
- package/lib/util/StackedSetMap.js +0 -166
package/lib/Compilation.js
CHANGED
@@ -855,10 +855,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
855
855
|
logger: this.getLogger("webpack.FileSystemInfo")
|
856
856
|
});
|
857
857
|
if (compiler.fileTimestamps) {
|
858
|
-
this.fileSystemInfo.addFileTimestamps(compiler.fileTimestamps);
|
858
|
+
this.fileSystemInfo.addFileTimestamps(compiler.fileTimestamps, true);
|
859
859
|
}
|
860
860
|
if (compiler.contextTimestamps) {
|
861
|
-
this.fileSystemInfo.addContextTimestamps(
|
861
|
+
this.fileSystemInfo.addContextTimestamps(
|
862
|
+
compiler.contextTimestamps,
|
863
|
+
true
|
864
|
+
);
|
862
865
|
}
|
863
866
|
/** @type {Map<string, string | Set<string>>} */
|
864
867
|
this.valueCacheVersions = new Map();
|
package/lib/Compiler.js
CHANGED
@@ -222,13 +222,13 @@ class Compiler {
|
|
222
222
|
/** @type {Set<string>} */
|
223
223
|
this.immutablePaths = new Set();
|
224
224
|
|
225
|
-
/** @type {
|
225
|
+
/** @type {ReadonlySet<string>} */
|
226
226
|
this.modifiedFiles = undefined;
|
227
|
-
/** @type {
|
227
|
+
/** @type {ReadonlySet<string>} */
|
228
228
|
this.removedFiles = undefined;
|
229
|
-
/** @type {
|
229
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
230
230
|
this.fileTimestamps = undefined;
|
231
|
-
/** @type {
|
231
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
232
232
|
this.contextTimestamps = undefined;
|
233
233
|
/** @type {number} */
|
234
234
|
this.fsStartTime = undefined;
|
package/lib/ExternalModule.js
CHANGED
@@ -16,6 +16,7 @@ const StaticExportsDependency = require("./dependencies/StaticExportsDependency"
|
|
16
16
|
const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
|
17
17
|
const makeSerializable = require("./util/makeSerializable");
|
18
18
|
const propertyAccess = require("./util/propertyAccess");
|
19
|
+
const { register } = require("./util/serialization");
|
19
20
|
|
20
21
|
/** @typedef {import("webpack-sources").Source} Source */
|
21
22
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
@@ -169,6 +170,8 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
169
170
|
`external module import ${id}`
|
170
171
|
);
|
171
172
|
this._identifier = identifier;
|
173
|
+
this._id = id;
|
174
|
+
this._request = request;
|
172
175
|
}
|
173
176
|
|
174
177
|
getNamespaceIdentifier() {
|
@@ -176,6 +179,21 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
176
179
|
}
|
177
180
|
}
|
178
181
|
|
182
|
+
register(
|
183
|
+
ModuleExternalInitFragment,
|
184
|
+
"webpack/lib/ExternalModule",
|
185
|
+
"ModuleExternalInitFragment",
|
186
|
+
{
|
187
|
+
serialize(obj, { write }) {
|
188
|
+
write(obj._id);
|
189
|
+
write(obj._request);
|
190
|
+
},
|
191
|
+
deserialize({ read }) {
|
192
|
+
return new ModuleExternalInitFragment(read(), read());
|
193
|
+
}
|
194
|
+
}
|
195
|
+
);
|
196
|
+
|
179
197
|
const generateModuleRemapping = (input, exportsInfo, runtime) => {
|
180
198
|
if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
|
181
199
|
const properties = [];
|
@@ -12,7 +12,7 @@ const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
|
12
12
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
13
13
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
14
14
|
|
15
|
-
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9]+ /;
|
15
|
+
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
16
16
|
const EMPTY_RESOLVE_OPTIONS = {};
|
17
17
|
|
18
18
|
// TODO webpack 6 remove this
|
package/lib/FileSystemInfo.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
const { create: createResolver } = require("enhanced-resolve");
|
9
9
|
const asyncLib = require("neo-async");
|
10
10
|
const AsyncQueue = require("./util/AsyncQueue");
|
11
|
+
const StackedCacheMap = require("./util/StackedCacheMap");
|
11
12
|
const createHash = require("./util/createHash");
|
12
13
|
const { join, dirname, relative } = require("./util/fs");
|
13
14
|
const makeSerializable = require("./util/makeSerializable");
|
@@ -365,7 +366,7 @@ class Snapshot {
|
|
365
366
|
}
|
366
367
|
|
367
368
|
/**
|
368
|
-
* @param {function(Snapshot): (
|
369
|
+
* @param {function(Snapshot): (ReadonlyMap<string, any> | ReadonlySet<string>)[]} getMaps first
|
369
370
|
* @returns {Iterable<string>} iterable
|
370
371
|
*/
|
371
372
|
_createIterable(getMaps) {
|
@@ -853,14 +854,14 @@ class FileSystemInfo {
|
|
853
854
|
(s, v) => s.setManagedMissing(v),
|
854
855
|
true
|
855
856
|
);
|
856
|
-
/** @type {
|
857
|
-
this._fileTimestamps = new
|
857
|
+
/** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
858
|
+
this._fileTimestamps = new StackedCacheMap();
|
858
859
|
/** @type {Map<string, string>} */
|
859
860
|
this._fileHashes = new Map();
|
860
861
|
/** @type {Map<string, TimestampAndHash | string>} */
|
861
862
|
this._fileTshs = new Map();
|
862
|
-
/** @type {
|
863
|
-
this._contextTimestamps = new
|
863
|
+
/** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
864
|
+
this._contextTimestamps = new StackedCacheMap();
|
864
865
|
/** @type {Map<string, string>} */
|
865
866
|
this._contextHashes = new Map();
|
866
867
|
/** @type {Map<string, TimestampAndHash | string>} */
|
@@ -1060,24 +1061,22 @@ class FileSystemInfo {
|
|
1060
1061
|
}
|
1061
1062
|
|
1062
1063
|
/**
|
1063
|
-
* @param {
|
1064
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
|
1065
|
+
* @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
|
1064
1066
|
* @returns {void}
|
1065
1067
|
*/
|
1066
|
-
addFileTimestamps(map) {
|
1067
|
-
|
1068
|
-
this._fileTimestamps.set(path, ts);
|
1069
|
-
}
|
1068
|
+
addFileTimestamps(map, immutable) {
|
1069
|
+
this._fileTimestamps.addAll(map, immutable);
|
1070
1070
|
this._cachedDeprecatedFileTimestamps = undefined;
|
1071
1071
|
}
|
1072
1072
|
|
1073
1073
|
/**
|
1074
|
-
* @param {
|
1074
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
|
1075
|
+
* @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
|
1075
1076
|
* @returns {void}
|
1076
1077
|
*/
|
1077
|
-
addContextTimestamps(map) {
|
1078
|
-
|
1079
|
-
this._contextTimestamps.set(path, ts);
|
1080
|
-
}
|
1078
|
+
addContextTimestamps(map, immutable) {
|
1079
|
+
this._contextTimestamps.addAll(map, immutable);
|
1081
1080
|
this._cachedDeprecatedContextTimestamps = undefined;
|
1082
1081
|
}
|
1083
1082
|
|
@@ -180,7 +180,11 @@ class FlagDependencyUsagePlugin {
|
|
180
180
|
b.groupOptions &&
|
181
181
|
b.groupOptions.entryOptions
|
182
182
|
) {
|
183
|
-
processModule(
|
183
|
+
processModule(
|
184
|
+
b,
|
185
|
+
b.groupOptions.entryOptions.runtime || undefined,
|
186
|
+
true
|
187
|
+
);
|
184
188
|
} else {
|
185
189
|
queue.enqueue(b);
|
186
190
|
}
|
package/lib/MultiCompiler.js
CHANGED
@@ -313,12 +313,12 @@ module.exports = class MultiCompiler {
|
|
313
313
|
/**
|
314
314
|
* @template SetupResult
|
315
315
|
* @param {function(Compiler, number, Callback<Stats>, function(): boolean, function(): void, function(): void): SetupResult} setup setup a single compiler
|
316
|
-
* @param {function(Compiler, Callback<Stats>): void} run run/continue a single compiler
|
316
|
+
* @param {function(Compiler, SetupResult, Callback<Stats>): void} run run/continue a single compiler
|
317
317
|
* @param {Callback<MultiStats>} callback callback when all compilers are done, result includes Stats of all changed compilers
|
318
318
|
* @returns {SetupResult[]} result of setup
|
319
319
|
*/
|
320
320
|
_runGraph(setup, run, callback) {
|
321
|
-
/** @typedef {{ compiler: Compiler, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
|
321
|
+
/** @typedef {{ compiler: Compiler, setupResult: SetupResult, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
|
322
322
|
|
323
323
|
// State transitions for nodes:
|
324
324
|
// -> blocked (initial)
|
@@ -335,6 +335,7 @@ module.exports = class MultiCompiler {
|
|
335
335
|
/** @type {Node[]} */
|
336
336
|
const nodes = this.compilers.map(compiler => ({
|
337
337
|
compiler,
|
338
|
+
setupResult: undefined,
|
338
339
|
result: undefined,
|
339
340
|
state: "blocked",
|
340
341
|
children: [],
|
@@ -444,14 +445,14 @@ module.exports = class MultiCompiler {
|
|
444
445
|
const setupResults = [];
|
445
446
|
nodes.forEach((node, i) => {
|
446
447
|
setupResults.push(
|
447
|
-
setup(
|
448
|
+
(node.setupResult = setup(
|
448
449
|
node.compiler,
|
449
450
|
i,
|
450
451
|
nodeDone.bind(null, node),
|
451
452
|
() => node.state !== "starting" && node.state !== "running",
|
452
453
|
() => nodeChange(node),
|
453
454
|
() => nodeInvalid(node)
|
454
|
-
)
|
455
|
+
))
|
455
456
|
);
|
456
457
|
});
|
457
458
|
let processing = true;
|
@@ -470,7 +471,7 @@ module.exports = class MultiCompiler {
|
|
470
471
|
) {
|
471
472
|
running++;
|
472
473
|
node.state = "starting";
|
473
|
-
run(node.compiler, nodeDone.bind(null, node));
|
474
|
+
run(node.compiler, node.setupResult, nodeDone.bind(null, node));
|
474
475
|
node.state = "running";
|
475
476
|
}
|
476
477
|
}
|
@@ -522,8 +523,9 @@ module.exports = class MultiCompiler {
|
|
522
523
|
}
|
523
524
|
return watching;
|
524
525
|
},
|
525
|
-
(compiler,
|
526
|
-
if (
|
526
|
+
(compiler, watching, callback) => {
|
527
|
+
if (compiler.watching !== watching) return;
|
528
|
+
if (!watching.running) watching.invalidate();
|
527
529
|
},
|
528
530
|
handler
|
529
531
|
);
|
@@ -546,7 +548,7 @@ module.exports = class MultiCompiler {
|
|
546
548
|
if (this.validateDependencies(callback)) {
|
547
549
|
this._runGraph(
|
548
550
|
() => {},
|
549
|
-
(compiler, callback) => compiler.run(callback),
|
551
|
+
(compiler, setupResult, callback) => compiler.run(callback),
|
550
552
|
(err, stats) => {
|
551
553
|
this.running = false;
|
552
554
|
|
package/lib/NormalModule.js
CHANGED
@@ -293,9 +293,13 @@ class NormalModule extends Module {
|
|
293
293
|
*/
|
294
294
|
identifier() {
|
295
295
|
if (this.layer === null) {
|
296
|
-
|
296
|
+
if (this.type === "javascript/auto") {
|
297
|
+
return this.request;
|
298
|
+
} else {
|
299
|
+
return `${this.type}|${this.request}`;
|
300
|
+
}
|
297
301
|
} else {
|
298
|
-
return `${this.request}|${this.layer}`;
|
302
|
+
return `${this.type}|${this.request}|${this.layer}`;
|
299
303
|
}
|
300
304
|
}
|
301
305
|
|
@@ -20,7 +20,7 @@ const ModuleGraph = require("./ModuleGraph");
|
|
20
20
|
const NormalModule = require("./NormalModule");
|
21
21
|
const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
|
22
22
|
const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
|
23
|
-
const
|
23
|
+
const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin");
|
24
24
|
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
25
25
|
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
26
26
|
const LazySet = require("./util/LazySet");
|
@@ -44,6 +44,7 @@ const { parseResource } = require("./util/identifier");
|
|
44
44
|
* @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
|
45
45
|
* @property {string} context
|
46
46
|
* @property {string} request
|
47
|
+
* @property {Record<string, any> | undefined} assertions
|
47
48
|
* @property {ModuleDependency[]} dependencies
|
48
49
|
* @property {Object} createData
|
49
50
|
* @property {LazySet<string>} fileDependencies
|
@@ -182,7 +183,8 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
182
183
|
new BasicMatcherRulePlugin("issuer"),
|
183
184
|
new BasicMatcherRulePlugin("compiler"),
|
184
185
|
new BasicMatcherRulePlugin("issuerLayer"),
|
185
|
-
new
|
186
|
+
new ObjectMatcherRulePlugin("assert", "assertions"),
|
187
|
+
new ObjectMatcherRulePlugin("descriptionData"),
|
186
188
|
new BasicEffectRulePlugin("type"),
|
187
189
|
new BasicEffectRulePlugin("sideEffects"),
|
188
190
|
new BasicEffectRulePlugin("parser"),
|
@@ -339,6 +341,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
339
341
|
context,
|
340
342
|
dependencies,
|
341
343
|
request,
|
344
|
+
assertions,
|
342
345
|
resolveOptions,
|
343
346
|
fileDependencies,
|
344
347
|
missingDependencies,
|
@@ -447,6 +450,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
447
450
|
resourceQuery: resourceDataForRules.query,
|
448
451
|
resourceFragment: resourceDataForRules.fragment,
|
449
452
|
scheme,
|
453
|
+
assertions,
|
450
454
|
mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
|
451
455
|
dependency: dependencyType,
|
452
456
|
descriptionData: matchResourceData
|
@@ -694,6 +698,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
694
698
|
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
|
695
699
|
const dependency = dependencies[0];
|
696
700
|
const request = dependency.request;
|
701
|
+
const assertions = dependency.assertions;
|
697
702
|
const contextInfo = data.contextInfo;
|
698
703
|
const fileDependencies = new LazySet();
|
699
704
|
const missingDependencies = new LazySet();
|
@@ -704,6 +709,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
704
709
|
resolveOptions,
|
705
710
|
context,
|
706
711
|
request,
|
712
|
+
assertions,
|
707
713
|
dependencies,
|
708
714
|
fileDependencies,
|
709
715
|
missingDependencies,
|
@@ -766,6 +772,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
766
772
|
if (!unsafeCacheData.has(module)) {
|
767
773
|
unsafeCacheData.set(module, module.getUnsafeCacheData());
|
768
774
|
}
|
775
|
+
this._restoredUnsafeCacheEntries.add(module);
|
769
776
|
}
|
770
777
|
|
771
778
|
callback(null, factoryResult);
|
@@ -152,7 +152,7 @@ class SourceMapDevToolPlugin {
|
|
152
152
|
const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
153
153
|
const requestShortener = compiler.requestShortener;
|
154
154
|
const options = this.options;
|
155
|
-
options.test = options.test || /\.(m?js|css)($|\?)/i;
|
155
|
+
options.test = options.test || /\.((c|m)?js|css)($|\?)/i;
|
156
156
|
|
157
157
|
const matchObject = ModuleFilenameHelpers.matchObject.bind(
|
158
158
|
undefined,
|
package/lib/Template.js
CHANGED
@@ -379,6 +379,7 @@ class Template {
|
|
379
379
|
source.add(Template.toNormalComment(module.identifier()) + "\n");
|
380
380
|
if (!module.shouldIsolate()) {
|
381
381
|
source.add(runtimeSource);
|
382
|
+
source.add("\n\n");
|
382
383
|
} else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
|
383
384
|
source.add("(() => {\n");
|
384
385
|
if (renderContext.useStrict) source.add('\t"use strict";\n');
|
package/lib/Watching.js
CHANGED
@@ -10,6 +10,7 @@ const Stats = require("./Stats");
|
|
10
10
|
/** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
11
11
|
/** @typedef {import("./Compilation")} Compilation */
|
12
12
|
/** @typedef {import("./Compiler")} Compiler */
|
13
|
+
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
13
14
|
|
14
15
|
/**
|
15
16
|
* @template T
|
@@ -67,6 +68,10 @@ class Watching {
|
|
67
68
|
});
|
68
69
|
}
|
69
70
|
|
71
|
+
/**
|
72
|
+
* @param {ReadonlySet<string>} changedFiles changed files
|
73
|
+
* @param {ReadonlySet<string>} removedFiles removed files
|
74
|
+
*/
|
70
75
|
_mergeWithCollected(changedFiles, removedFiles) {
|
71
76
|
if (!changedFiles) return;
|
72
77
|
if (!this._collectedChangedFiles) {
|
@@ -84,6 +89,13 @@ class Watching {
|
|
84
89
|
}
|
85
90
|
}
|
86
91
|
|
92
|
+
/**
|
93
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files
|
94
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories
|
95
|
+
* @param {ReadonlySet<string>=} changedFiles changed files
|
96
|
+
* @param {ReadonlySet<string>=} removedFiles removed files
|
97
|
+
* @returns {void}
|
98
|
+
*/
|
87
99
|
_go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) {
|
88
100
|
this._initial = false;
|
89
101
|
if (this.startTime === null) this.startTime = Date.now();
|
@@ -265,7 +265,7 @@ class AssetGenerator extends Generator {
|
|
265
265
|
* @returns {Set<string>} available types (do not mutate)
|
266
266
|
*/
|
267
267
|
getTypes(module) {
|
268
|
-
if (module.buildInfo.dataUrl || this.emit === false) {
|
268
|
+
if ((module.buildInfo && module.buildInfo.dataUrl) || this.emit === false) {
|
269
269
|
return JS_TYPES;
|
270
270
|
} else {
|
271
271
|
return JS_AND_ASSET_TYPES;
|
@@ -289,7 +289,7 @@ class AssetGenerator extends Generator {
|
|
289
289
|
return originalSource.size();
|
290
290
|
}
|
291
291
|
default:
|
292
|
-
if (module.buildInfo.dataUrl) {
|
292
|
+
if (module.buildInfo && module.buildInfo.dataUrl) {
|
293
293
|
const originalSource = module.originalSource();
|
294
294
|
|
295
295
|
if (!originalSource) {
|
package/lib/config/defaults.js
CHANGED
@@ -482,18 +482,6 @@ const applyModuleDefaults = (
|
|
482
482
|
or: ["text/javascript", "application/javascript"]
|
483
483
|
},
|
484
484
|
...esm
|
485
|
-
},
|
486
|
-
{
|
487
|
-
dependency: "url",
|
488
|
-
oneOf: [
|
489
|
-
{
|
490
|
-
scheme: /^data$/,
|
491
|
-
type: "asset/inline"
|
492
|
-
},
|
493
|
-
{
|
494
|
-
type: "asset/resource"
|
495
|
-
}
|
496
|
-
]
|
497
485
|
}
|
498
486
|
];
|
499
487
|
if (asyncWebAssembly) {
|
@@ -541,6 +529,24 @@ const applyModuleDefaults = (
|
|
541
529
|
...wasm
|
542
530
|
});
|
543
531
|
}
|
532
|
+
rules.push(
|
533
|
+
{
|
534
|
+
dependency: "url",
|
535
|
+
oneOf: [
|
536
|
+
{
|
537
|
+
scheme: /^data$/,
|
538
|
+
type: "asset/inline"
|
539
|
+
},
|
540
|
+
{
|
541
|
+
type: "asset/resource"
|
542
|
+
}
|
543
|
+
]
|
544
|
+
},
|
545
|
+
{
|
546
|
+
assert: { type: "json" },
|
547
|
+
type: "json"
|
548
|
+
}
|
549
|
+
);
|
544
550
|
return rules;
|
545
551
|
});
|
546
552
|
};
|
@@ -39,6 +39,7 @@ class ContainerPlugin {
|
|
39
39
|
type: "var",
|
40
40
|
name: options.name
|
41
41
|
},
|
42
|
+
runtime: options.runtime,
|
42
43
|
filename: options.filename || undefined,
|
43
44
|
exposes: parseOptions(
|
44
45
|
options.exposes,
|
@@ -60,7 +61,8 @@ class ContainerPlugin {
|
|
60
61
|
* @returns {void}
|
61
62
|
*/
|
62
63
|
apply(compiler) {
|
63
|
-
const { name, exposes, shareScope, filename, library } =
|
64
|
+
const { name, exposes, shareScope, filename, library, runtime } =
|
65
|
+
this._options;
|
64
66
|
|
65
67
|
compiler.options.output.enabledLibraryTypes.push(library.type);
|
66
68
|
|
@@ -73,6 +75,7 @@ class ContainerPlugin {
|
|
73
75
|
{
|
74
76
|
name,
|
75
77
|
filename,
|
78
|
+
runtime,
|
76
79
|
library
|
77
80
|
},
|
78
81
|
error => {
|
@@ -12,7 +12,8 @@ const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency")
|
|
12
12
|
const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
|
13
13
|
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
14
14
|
const {
|
15
|
-
harmonySpecifierTag
|
15
|
+
harmonySpecifierTag,
|
16
|
+
getAssertions
|
16
17
|
} = require("./HarmonyImportDependencyParserPlugin");
|
17
18
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
18
19
|
|
@@ -48,7 +49,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
48
49
|
parser.state.module.addPresentationalDependency(clearDep);
|
49
50
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
50
51
|
source,
|
51
|
-
parser.state.lastHarmonyImportOrder
|
52
|
+
parser.state.lastHarmonyImportOrder,
|
53
|
+
getAssertions(statement)
|
52
54
|
);
|
53
55
|
sideEffectDep.loc = Object.create(statement.loc);
|
54
56
|
sideEffectDep.loc.index = -1;
|
@@ -127,7 +129,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
127
129
|
harmonyNamedExports,
|
128
130
|
null,
|
129
131
|
this.strictExportPresence,
|
130
|
-
null
|
132
|
+
null,
|
133
|
+
settings.assertions
|
131
134
|
);
|
132
135
|
} else {
|
133
136
|
dep = new HarmonyExportSpecifierDependency(id, name);
|
@@ -159,6 +159,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
159
159
|
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module before this import
|
160
160
|
* @param {boolean} strictExportPresence when true, missing exports in the imported module lead to errors instead of warnings
|
161
161
|
* @param {HarmonyStarExportsList} allStarExports all star exports in the module
|
162
|
+
* @param {Record<string, any>=} assertions import assertions
|
162
163
|
*/
|
163
164
|
constructor(
|
164
165
|
request,
|
@@ -168,9 +169,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
168
169
|
activeExports,
|
169
170
|
otherStarExports,
|
170
171
|
strictExportPresence,
|
171
|
-
allStarExports
|
172
|
+
allStarExports,
|
173
|
+
assertions
|
172
174
|
) {
|
173
|
-
super(request, sourceOrder);
|
175
|
+
super(request, sourceOrder, assertions);
|
174
176
|
|
175
177
|
this.ids = ids;
|
176
178
|
this.name = name;
|
@@ -32,10 +32,12 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
32
32
|
*
|
33
33
|
* @param {string} request request string
|
34
34
|
* @param {number} sourceOrder source order
|
35
|
+
* @param {Record<string, any>=} assertions import assertions
|
35
36
|
*/
|
36
|
-
constructor(request, sourceOrder) {
|
37
|
+
constructor(request, sourceOrder, assertions) {
|
37
38
|
super(request);
|
38
39
|
this.sourceOrder = sourceOrder;
|
40
|
+
this.assertions = assertions;
|
39
41
|
}
|
40
42
|
|
41
43
|
get category() {
|
@@ -201,12 +203,14 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
201
203
|
serialize(context) {
|
202
204
|
const { write } = context;
|
203
205
|
write(this.sourceOrder);
|
206
|
+
write(this.assertions);
|
204
207
|
super.serialize(context);
|
205
208
|
}
|
206
209
|
|
207
210
|
deserialize(context) {
|
208
211
|
const { read } = context;
|
209
212
|
this.sourceOrder = read();
|
213
|
+
this.assertions = read();
|
210
214
|
super.deserialize(context);
|
211
215
|
}
|
212
216
|
}
|
@@ -14,7 +14,11 @@ const HarmonyExports = require("./HarmonyExports");
|
|
14
14
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
15
15
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
16
16
|
|
17
|
+
/** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
|
18
|
+
/** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
|
17
19
|
/** @typedef {import("estree").Identifier} Identifier */
|
20
|
+
/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
|
21
|
+
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
18
22
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
19
23
|
/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
|
20
24
|
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
@@ -29,8 +33,32 @@ const harmonySpecifierTag = Symbol("harmony import");
|
|
29
33
|
* @property {number} sourceOrder
|
30
34
|
* @property {string} name
|
31
35
|
* @property {boolean} await
|
36
|
+
* @property {Record<string, any> | undefined} assertions
|
32
37
|
*/
|
33
38
|
|
39
|
+
/**
|
40
|
+
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
|
41
|
+
* @returns {Record<string, any> | undefined} assertions
|
42
|
+
*/
|
43
|
+
function getAssertions(node) {
|
44
|
+
// TODO remove cast when @types/estree has been updated to import assertions
|
45
|
+
const assertions = /** @type {{ assertions?: ImportAttributeNode[] }} */ (
|
46
|
+
node
|
47
|
+
).assertions;
|
48
|
+
if (assertions === undefined) {
|
49
|
+
return undefined;
|
50
|
+
}
|
51
|
+
const result = {};
|
52
|
+
for (const assertion of assertions) {
|
53
|
+
const key =
|
54
|
+
assertion.key.type === "Identifier"
|
55
|
+
? assertion.key.name
|
56
|
+
: assertion.key.value;
|
57
|
+
result[key] = assertion.value.value;
|
58
|
+
}
|
59
|
+
return result;
|
60
|
+
}
|
61
|
+
|
34
62
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
35
63
|
constructor(options) {
|
36
64
|
this.strictExportPresence = options.strictExportPresence;
|
@@ -65,9 +93,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
65
93
|
clearDep.loc = statement.loc;
|
66
94
|
parser.state.module.addPresentationalDependency(clearDep);
|
67
95
|
parser.unsetAsiPosition(statement.range[1]);
|
96
|
+
const assertions = getAssertions(statement);
|
68
97
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
69
98
|
source,
|
70
|
-
parser.state.lastHarmonyImportOrder
|
99
|
+
parser.state.lastHarmonyImportOrder,
|
100
|
+
assertions
|
71
101
|
);
|
72
102
|
sideEffectDep.loc = statement.loc;
|
73
103
|
parser.state.module.addDependency(sideEffectDep);
|
@@ -82,7 +112,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
82
112
|
name,
|
83
113
|
source,
|
84
114
|
ids,
|
85
|
-
sourceOrder: parser.state.lastHarmonyImportOrder
|
115
|
+
sourceOrder: parser.state.lastHarmonyImportOrder,
|
116
|
+
assertions: getAssertions(statement)
|
86
117
|
});
|
87
118
|
return true;
|
88
119
|
}
|
@@ -97,7 +128,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
97
128
|
settings.ids,
|
98
129
|
settings.name,
|
99
130
|
expr.range,
|
100
|
-
this.strictExportPresence
|
131
|
+
this.strictExportPresence,
|
132
|
+
settings.assertions
|
101
133
|
);
|
102
134
|
dep.shorthand = parser.scope.inShorthand;
|
103
135
|
dep.directImport = true;
|
@@ -118,7 +150,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
118
150
|
ids,
|
119
151
|
settings.name,
|
120
152
|
expr.range,
|
121
|
-
this.strictExportPresence
|
153
|
+
this.strictExportPresence,
|
154
|
+
settings.assertions
|
122
155
|
);
|
123
156
|
dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
|
124
157
|
dep.loc = expr.loc;
|
@@ -138,7 +171,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
138
171
|
ids,
|
139
172
|
settings.name,
|
140
173
|
callee.range,
|
141
|
-
this.strictExportPresence
|
174
|
+
this.strictExportPresence,
|
175
|
+
settings.assertions
|
142
176
|
);
|
143
177
|
dep.directImport = members.length === 0;
|
144
178
|
dep.call = true;
|
@@ -206,3 +240,4 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
206
240
|
};
|
207
241
|
|
208
242
|
module.exports.harmonySpecifierTag = harmonySpecifierTag;
|
243
|
+
module.exports.getAssertions = getAssertions;
|
@@ -20,8 +20,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
20
20
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
21
21
|
|
22
22
|
class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
23
|
-
constructor(request, sourceOrder) {
|
24
|
-
super(request, sourceOrder);
|
23
|
+
constructor(request, sourceOrder, assertions) {
|
24
|
+
super(request, sourceOrder, assertions);
|
25
25
|
}
|
26
26
|
|
27
27
|
get type() {
|