webpack 5.14.0 → 5.18.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/hot/lazy-compilation-node.js +38 -0
- package/hot/lazy-compilation-web.js +74 -0
- package/lib/AutomaticPrefetchPlugin.js +14 -7
- package/lib/CacheFacade.js +1 -0
- package/lib/ChunkGraph.js +132 -19
- package/lib/CodeGenerationResults.js +43 -8
- package/lib/Compilation.js +253 -149
- package/lib/Compiler.js +7 -2
- package/lib/ContextModule.js +2 -2
- package/lib/Dependency.js +1 -7
- package/lib/ExportsInfo.js +23 -5
- package/lib/ExternalModuleFactoryPlugin.js +46 -3
- package/lib/FileSystemInfo.js +192 -137
- package/lib/HotModuleReplacementPlugin.js +76 -29
- package/lib/IgnoreErrorModuleFactory.js +39 -0
- package/lib/Module.js +2 -3
- package/lib/NormalModuleFactory.js +27 -8
- package/lib/Template.js +32 -23
- package/lib/WebpackIsIncludedPlugin.js +85 -0
- package/lib/WebpackOptionsApply.js +27 -5
- package/lib/cache/PackFileCacheStrategy.js +5 -1
- package/lib/config/defaults.js +18 -18
- package/lib/config/normalization.js +44 -9
- package/lib/debug/ProfilingPlugin.js +20 -1
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDPlugin.js +6 -7
- package/lib/dependencies/CommonJsImportsParserPlugin.js +43 -1
- package/lib/dependencies/CommonJsPlugin.js +1 -6
- package/lib/dependencies/ContextDependencyHelpers.js +3 -2
- package/lib/dependencies/ExportsInfoDependency.js +0 -20
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +1 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +0 -29
- package/lib/dependencies/HarmonyImportDependency.js +0 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +2 -36
- package/lib/dependencies/HarmonyModulesPlugin.js +2 -2
- package/lib/dependencies/ImportPlugin.js +1 -6
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/ModuleDecoratorDependency.js +0 -1
- package/lib/dependencies/NullDependency.js +0 -8
- package/lib/dependencies/ProvidedDependency.js +0 -1
- package/lib/dependencies/StaticExportsDependency.js +0 -12
- package/lib/dependencies/SystemPlugin.js +0 -4
- package/lib/dependencies/URLDependency.js +45 -3
- package/lib/dependencies/URLPlugin.js +33 -7
- package/lib/dependencies/WebpackIsIncludedDependency.js +80 -0
- package/lib/hmr/LazyCompilationPlugin.js +348 -0
- package/lib/hmr/lazyCompilationBackend.js +86 -0
- package/lib/javascript/JavascriptModulesPlugin.js +4 -3
- package/lib/javascript/JavascriptParser.js +20 -5
- package/lib/library/AssignLibraryPlugin.js +13 -4
- package/lib/library/EnableLibraryPlugin.js +12 -0
- package/lib/optimize/ConcatenatedModule.js +0 -12
- package/lib/optimize/InnerGraph.js +32 -0
- package/lib/optimize/SplitChunksPlugin.js +4 -1
- package/lib/serialization/ObjectMiddleware.js +7 -5
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -0
- package/lib/util/MapHelpers.js +22 -0
- package/lib/util/binarySearchBounds.js +86 -0
- package/lib/util/createHash.js +13 -7
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/processAsyncTree.js +61 -0
- package/lib/util/runtime.js +12 -1
- package/package.json +3 -3
- package/schemas/WebpackOptions.json +330 -140
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +2 -1
- package/types.d.ts +320 -121
package/bin/webpack.js
CHANGED
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/* global __resourceQuery */
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
6
|
+
exports.keepAlive = function (options) {
|
7
|
+
var data = options.data;
|
8
|
+
var onError = options.onError;
|
9
|
+
var active = options.active;
|
10
|
+
var module = options.module;
|
11
|
+
var response;
|
12
|
+
var request = require("http").request(
|
13
|
+
urlBase + data,
|
14
|
+
{
|
15
|
+
agent: false,
|
16
|
+
headers: { accept: "text/event-stream" }
|
17
|
+
},
|
18
|
+
function (res) {
|
19
|
+
response = res;
|
20
|
+
response.on("error", errorHandler);
|
21
|
+
if (!active && !module.hot) {
|
22
|
+
console.log(
|
23
|
+
"Hot Module Replacement is not enabled. Waiting for process restart..."
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
);
|
28
|
+
function errorHandler(err) {
|
29
|
+
err.message =
|
30
|
+
"Problem communicating active modules to the server: " + err.message;
|
31
|
+
onError(err);
|
32
|
+
}
|
33
|
+
request.on("error", errorHandler);
|
34
|
+
request.end();
|
35
|
+
return function () {
|
36
|
+
response.destroy();
|
37
|
+
};
|
38
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
/* global __resourceQuery */
|
2
|
+
|
3
|
+
"use strict";
|
4
|
+
|
5
|
+
if (typeof EventSource !== "function") {
|
6
|
+
throw new Error(
|
7
|
+
"Environment doesn't support lazy compilation (requires EventSource)"
|
8
|
+
);
|
9
|
+
}
|
10
|
+
|
11
|
+
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
12
|
+
var activeEventSource;
|
13
|
+
var activeKeys = new Map();
|
14
|
+
var errorHandlers = new Set();
|
15
|
+
|
16
|
+
var updateEventSource = function updateEventSource() {
|
17
|
+
if (activeEventSource) activeEventSource.close();
|
18
|
+
if (activeKeys.size) {
|
19
|
+
activeEventSource = new EventSource(
|
20
|
+
urlBase + Array.from(activeKeys.keys()).join("@")
|
21
|
+
);
|
22
|
+
activeEventSource.onerror = function (event) {
|
23
|
+
errorHandlers.forEach(function (onError) {
|
24
|
+
onError(
|
25
|
+
new Error(
|
26
|
+
"Problem communicating active modules to the server: " +
|
27
|
+
event.message +
|
28
|
+
" " +
|
29
|
+
event.filename +
|
30
|
+
":" +
|
31
|
+
event.lineno +
|
32
|
+
":" +
|
33
|
+
event.colno +
|
34
|
+
" " +
|
35
|
+
event.error
|
36
|
+
)
|
37
|
+
);
|
38
|
+
});
|
39
|
+
};
|
40
|
+
} else {
|
41
|
+
activeEventSource = undefined;
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
exports.keepAlive = function (options) {
|
46
|
+
var data = options.data;
|
47
|
+
var onError = options.onError;
|
48
|
+
var active = options.active;
|
49
|
+
var module = options.module;
|
50
|
+
errorHandlers.add(onError);
|
51
|
+
var value = activeKeys.get(data) || 0;
|
52
|
+
activeKeys.set(data, value + 1);
|
53
|
+
if (value === 0) {
|
54
|
+
updateEventSource();
|
55
|
+
}
|
56
|
+
if (!active && !module.hot) {
|
57
|
+
console.log(
|
58
|
+
"Hot Module Replacement is not enabled. Waiting for process restart..."
|
59
|
+
);
|
60
|
+
}
|
61
|
+
|
62
|
+
return function () {
|
63
|
+
errorHandlers.delete(onError);
|
64
|
+
setTimeout(function () {
|
65
|
+
var value = activeKeys.get(data);
|
66
|
+
if (value === 1) {
|
67
|
+
activeKeys.delete(data);
|
68
|
+
updateEventSource();
|
69
|
+
} else {
|
70
|
+
activeKeys.set(data, value - 1);
|
71
|
+
}
|
72
|
+
}, 1000);
|
73
|
+
};
|
74
|
+
};
|
@@ -29,12 +29,16 @@ class AutomaticPrefetchPlugin {
|
|
29
29
|
);
|
30
30
|
let lastModules = null;
|
31
31
|
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
|
32
|
-
lastModules =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
lastModules = [];
|
33
|
+
|
34
|
+
for (const m of compilation.modules) {
|
35
|
+
if (m instanceof NormalModule) {
|
36
|
+
lastModules.push({
|
37
|
+
context: m.context,
|
38
|
+
request: m.request
|
39
|
+
});
|
40
|
+
}
|
41
|
+
}
|
38
42
|
});
|
39
43
|
compiler.hooks.make.tapAsync(
|
40
44
|
"AutomaticPrefetchPlugin",
|
@@ -49,7 +53,10 @@ class AutomaticPrefetchPlugin {
|
|
49
53
|
callback
|
50
54
|
);
|
51
55
|
},
|
52
|
-
|
56
|
+
err => {
|
57
|
+
lastModules = null;
|
58
|
+
callback(err);
|
59
|
+
}
|
53
60
|
);
|
54
61
|
}
|
55
62
|
);
|
package/lib/CacheFacade.js
CHANGED
package/lib/ChunkGraph.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
const util = require("util");
|
9
9
|
const ModuleGraphConnection = require("./ModuleGraphConnection");
|
10
10
|
const SortableSet = require("./util/SortableSet");
|
11
|
+
const StringXor = require("./util/StringXor");
|
11
12
|
const {
|
12
13
|
compareModulesById,
|
13
14
|
compareIterables,
|
@@ -16,12 +17,14 @@ const {
|
|
16
17
|
compareSelect,
|
17
18
|
compareIds
|
18
19
|
} = require("./util/comparators");
|
20
|
+
const createHash = require("./util/createHash");
|
19
21
|
const findGraphRoots = require("./util/findGraphRoots");
|
20
22
|
const {
|
21
23
|
RuntimeSpecMap,
|
22
24
|
RuntimeSpecSet,
|
23
25
|
runtimeToString,
|
24
|
-
mergeRuntime
|
26
|
+
mergeRuntime,
|
27
|
+
forEachRuntime
|
25
28
|
} = require("./util/runtime");
|
26
29
|
|
27
30
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
@@ -47,11 +50,12 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
|
|
47
50
|
* @property {number=} entryChunkMultiplicator multiplicator for initial chunks
|
48
51
|
*/
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
class ModuleHashInfo {
|
54
|
+
constructor(hash, renderedHash) {
|
55
|
+
this.hash = hash;
|
56
|
+
this.renderedHash = renderedHash;
|
57
|
+
}
|
58
|
+
}
|
55
59
|
|
56
60
|
/** @template T @typedef {(set: SortableSet<T>) => T[]} SetToArrayFunction<T> */
|
57
61
|
|
@@ -170,6 +174,10 @@ class ChunkGraphModule {
|
|
170
174
|
this.id = null;
|
171
175
|
/** @type {RuntimeSpecMap<Set<string>> | undefined} */
|
172
176
|
this.runtimeRequirements = undefined;
|
177
|
+
/** @type {RuntimeSpecMap<string>} */
|
178
|
+
this.graphHashes = undefined;
|
179
|
+
/** @type {RuntimeSpecMap<string>} */
|
180
|
+
this.graphHashesWithConnections = undefined;
|
173
181
|
}
|
174
182
|
}
|
175
183
|
|
@@ -1096,6 +1104,15 @@ class ChunkGraph {
|
|
1096
1104
|
return cgc.fullHashModules;
|
1097
1105
|
}
|
1098
1106
|
|
1107
|
+
/**
|
1108
|
+
* @param {Chunk} chunk the chunk
|
1109
|
+
* @returns {ReadonlySet<RuntimeModule> | undefined} set of modules (do not modify)
|
1110
|
+
*/
|
1111
|
+
getChunkFullHashModulesSet(chunk) {
|
1112
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
1113
|
+
return cgc.fullHashModules;
|
1114
|
+
}
|
1115
|
+
|
1099
1116
|
/** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
|
1100
1117
|
|
1101
1118
|
/**
|
@@ -1174,14 +1191,20 @@ class ChunkGraph {
|
|
1174
1191
|
}
|
1175
1192
|
|
1176
1193
|
/**
|
1194
|
+
* @template T
|
1177
1195
|
* @param {Module} module the module
|
1196
|
+
* @param {RuntimeSpecMap<T>} hashes hashes data
|
1178
1197
|
* @param {RuntimeSpec} runtime the runtime
|
1179
|
-
* @returns {
|
1180
|
-
*/
|
1181
|
-
_getModuleHashInfo(module, runtime) {
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1198
|
+
* @returns {T} hash
|
1199
|
+
*/
|
1200
|
+
_getModuleHashInfo(module, hashes, runtime) {
|
1201
|
+
if (!hashes) {
|
1202
|
+
throw new Error(
|
1203
|
+
`Module ${module.identifier()} has no hash info for runtime ${runtimeToString(
|
1204
|
+
runtime
|
1205
|
+
)} (hashes not set at all)`
|
1206
|
+
);
|
1207
|
+
} else if (runtime === undefined) {
|
1185
1208
|
const hashInfoItems = new Set(hashes.values());
|
1186
1209
|
if (hashInfoItems.size !== 1) {
|
1187
1210
|
throw new Error(
|
@@ -1194,14 +1217,15 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1194
1217
|
}
|
1195
1218
|
return hashInfoItems.values().next().value;
|
1196
1219
|
} else {
|
1197
|
-
const hashInfo = hashes
|
1220
|
+
const hashInfo = hashes.get(runtime);
|
1198
1221
|
if (!hashInfo) {
|
1199
1222
|
throw new Error(
|
1200
1223
|
`Module ${module.identifier()} has no hash info for runtime ${runtimeToString(
|
1201
1224
|
runtime
|
1202
|
-
)} (available runtimes ${
|
1203
|
-
hashes
|
1204
|
-
|
1225
|
+
)} (available runtimes ${Array.from(
|
1226
|
+
hashes.keys(),
|
1227
|
+
runtimeToString
|
1228
|
+
).join(", ")})`
|
1205
1229
|
);
|
1206
1230
|
}
|
1207
1231
|
return hashInfo;
|
@@ -1225,7 +1249,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1225
1249
|
* @returns {string} hash
|
1226
1250
|
*/
|
1227
1251
|
getModuleHash(module, runtime) {
|
1228
|
-
|
1252
|
+
const cgm = this._getChunkGraphModule(module);
|
1253
|
+
const hashes = cgm.hashes;
|
1254
|
+
return this._getModuleHashInfo(module, hashes, runtime).hash;
|
1229
1255
|
}
|
1230
1256
|
|
1231
1257
|
/**
|
@@ -1234,7 +1260,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1234
1260
|
* @returns {string} hash
|
1235
1261
|
*/
|
1236
1262
|
getRenderedModuleHash(module, runtime) {
|
1237
|
-
|
1263
|
+
const cgm = this._getChunkGraphModule(module);
|
1264
|
+
const hashes = cgm.hashes;
|
1265
|
+
return this._getModuleHashInfo(module, hashes, runtime).renderedHash;
|
1238
1266
|
}
|
1239
1267
|
|
1240
1268
|
/**
|
@@ -1249,7 +1277,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1249
1277
|
if (cgm.hashes === undefined) {
|
1250
1278
|
cgm.hashes = new RuntimeSpecMap();
|
1251
1279
|
}
|
1252
|
-
cgm.hashes.set(runtime,
|
1280
|
+
cgm.hashes.set(runtime, new ModuleHashInfo(hash, renderedHash));
|
1253
1281
|
}
|
1254
1282
|
|
1255
1283
|
/**
|
@@ -1331,6 +1359,91 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1331
1359
|
return runtimeRequirements === undefined ? EMPTY_SET : runtimeRequirements;
|
1332
1360
|
}
|
1333
1361
|
|
1362
|
+
getModuleGraphHash(module, runtime, withConnections = true) {
|
1363
|
+
const cgm = this._getChunkGraphModule(module);
|
1364
|
+
if (cgm.graphHashes === undefined) {
|
1365
|
+
cgm.graphHashes = new RuntimeSpecMap();
|
1366
|
+
}
|
1367
|
+
const graphHash = cgm.graphHashes.provide(runtime, () => {
|
1368
|
+
const hash = createHash("md4");
|
1369
|
+
hash.update(`${cgm.id}`);
|
1370
|
+
hash.update(`${this.moduleGraph.isAsync(module)}`);
|
1371
|
+
this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
|
1372
|
+
return /** @type {string} */ (hash.digest("hex"));
|
1373
|
+
});
|
1374
|
+
if (!withConnections) return graphHash;
|
1375
|
+
if (cgm.graphHashesWithConnections === undefined) {
|
1376
|
+
cgm.graphHashesWithConnections = new RuntimeSpecMap();
|
1377
|
+
}
|
1378
|
+
const activeStateToString = state => {
|
1379
|
+
if (state === false) return "false";
|
1380
|
+
if (state === true) return "true";
|
1381
|
+
if (state === ModuleGraphConnection.TRANSITIVE_ONLY) return "transitive";
|
1382
|
+
throw new Error("Not implemented active state");
|
1383
|
+
};
|
1384
|
+
const strict = module.buildMeta && module.buildMeta.strictHarmonyModule;
|
1385
|
+
return cgm.graphHashesWithConnections.provide(runtime, () => {
|
1386
|
+
const connections = this.moduleGraph.getOutgoingConnections(module);
|
1387
|
+
/** @type {Map<string, Module | Set<Module>>} */
|
1388
|
+
const connectedModules = new Map();
|
1389
|
+
for (const connection of connections) {
|
1390
|
+
let stateInfo;
|
1391
|
+
if (typeof runtime === "string") {
|
1392
|
+
const state = connection.getActiveState(runtime);
|
1393
|
+
if (state === false) continue;
|
1394
|
+
stateInfo = activeStateToString(state);
|
1395
|
+
} else {
|
1396
|
+
const states = new Set();
|
1397
|
+
stateInfo = "";
|
1398
|
+
forEachRuntime(
|
1399
|
+
runtime,
|
1400
|
+
runtime => {
|
1401
|
+
const state = connection.getActiveState(runtime);
|
1402
|
+
states.add(state);
|
1403
|
+
stateInfo += runtime + activeStateToString(state);
|
1404
|
+
},
|
1405
|
+
true
|
1406
|
+
);
|
1407
|
+
if (states.size === 1) {
|
1408
|
+
const state = states.values().next().value;
|
1409
|
+
if (state === false) continue;
|
1410
|
+
stateInfo = activeStateToString(state);
|
1411
|
+
}
|
1412
|
+
}
|
1413
|
+
const module = connection.module;
|
1414
|
+
stateInfo += module.getExportsType(this.moduleGraph, strict);
|
1415
|
+
const oldModule = connectedModules.get(stateInfo);
|
1416
|
+
if (oldModule === undefined) {
|
1417
|
+
connectedModules.set(stateInfo, module);
|
1418
|
+
} else if (oldModule instanceof Set) {
|
1419
|
+
oldModule.add(module);
|
1420
|
+
} else if (oldModule !== module) {
|
1421
|
+
connectedModules.set(stateInfo, new Set([oldModule, module]));
|
1422
|
+
}
|
1423
|
+
}
|
1424
|
+
if (connectedModules.size === 0) return graphHash;
|
1425
|
+
const connectedModulesInOrder =
|
1426
|
+
connectedModules.size > 1
|
1427
|
+
? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
|
1428
|
+
: connectedModules;
|
1429
|
+
const hash = createHash("md4");
|
1430
|
+
for (const [stateInfo, modules] of connectedModulesInOrder) {
|
1431
|
+
hash.update(stateInfo);
|
1432
|
+
if (modules instanceof Set) {
|
1433
|
+
const xor = new StringXor();
|
1434
|
+
for (const m of modules) {
|
1435
|
+
xor.add(this.getModuleGraphHash(m, runtime, false));
|
1436
|
+
}
|
1437
|
+
xor.updateHash(hash);
|
1438
|
+
} else {
|
1439
|
+
hash.update(this.getModuleGraphHash(modules, runtime, false));
|
1440
|
+
}
|
1441
|
+
}
|
1442
|
+
hash.update(graphHash);
|
1443
|
+
return /** @type {string} */ (hash.digest("hex"));
|
1444
|
+
});
|
1445
|
+
}
|
1446
|
+
|
1334
1447
|
/**
|
1335
1448
|
* @param {Chunk} chunk the chunk
|
1336
1449
|
* @returns {ReadonlySet<string>} runtime requirements
|
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { provide } = require("./util/MapHelpers");
|
9
|
+
const createHash = require("./util/createHash");
|
8
10
|
const { runtimeToString, RuntimeSpecMap } = require("./util/runtime");
|
9
11
|
|
10
12
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -16,6 +18,8 @@ class CodeGenerationResults {
|
|
16
18
|
constructor() {
|
17
19
|
/** @type {Map<Module, RuntimeSpecMap<CodeGenerationResult>>} */
|
18
20
|
this.map = new Map();
|
21
|
+
/** @type {Map<Module, RuntimeSpecMap<string>>} */
|
22
|
+
this.hashes = new Map();
|
19
23
|
}
|
20
24
|
|
21
25
|
/**
|
@@ -61,6 +65,24 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
61
65
|
}
|
62
66
|
}
|
63
67
|
|
68
|
+
/**
|
69
|
+
* @param {Module} module the module
|
70
|
+
* @param {RuntimeSpec} runtime runtime(s)
|
71
|
+
* @returns {boolean} true, when we have data for this
|
72
|
+
*/
|
73
|
+
has(module, runtime) {
|
74
|
+
const entry = this.map.get(module);
|
75
|
+
if (entry === undefined) {
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
if (runtime === undefined) {
|
79
|
+
const results = new Set(entry.values());
|
80
|
+
return results.size === 1;
|
81
|
+
} else {
|
82
|
+
return entry.has(runtime);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
64
86
|
/**
|
65
87
|
* @param {Module} module the module
|
66
88
|
* @param {RuntimeSpec} runtime runtime(s)
|
@@ -91,6 +113,25 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
91
113
|
return data === undefined ? undefined : data.get(key);
|
92
114
|
}
|
93
115
|
|
116
|
+
/**
|
117
|
+
* @param {Module} module the module
|
118
|
+
* @param {RuntimeSpec} runtime runtime(s)
|
119
|
+
* @returns {any} hash of the code generation
|
120
|
+
*/
|
121
|
+
getHash(module, runtime) {
|
122
|
+
const info = this.get(module, runtime);
|
123
|
+
if (info.hash !== undefined) return info.hash;
|
124
|
+
const hash = createHash("md4");
|
125
|
+
for (const [type, source] of info.sources) {
|
126
|
+
hash.update(type);
|
127
|
+
source.updateHash(hash);
|
128
|
+
}
|
129
|
+
if (info.runtimeRequirements) {
|
130
|
+
for (const rr of info.runtimeRequirements) hash.update(rr);
|
131
|
+
}
|
132
|
+
return (info.hash = /** @type {string} */ (hash.digest("hex")));
|
133
|
+
}
|
134
|
+
|
94
135
|
/**
|
95
136
|
* @param {Module} module the module
|
96
137
|
* @param {RuntimeSpec} runtime runtime(s)
|
@@ -98,14 +139,8 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
98
139
|
* @returns {void}
|
99
140
|
*/
|
100
141
|
add(module, runtime, result) {
|
101
|
-
const map = this.map
|
102
|
-
|
103
|
-
map.set(runtime, result);
|
104
|
-
} else {
|
105
|
-
const newMap = new RuntimeSpecMap();
|
106
|
-
newMap.set(runtime, result);
|
107
|
-
this.map.set(module, newMap);
|
108
|
-
}
|
142
|
+
const map = provide(this.map, module, () => new RuntimeSpecMap());
|
143
|
+
map.set(runtime, result);
|
109
144
|
}
|
110
145
|
}
|
111
146
|
|