CompatRuntimeModule.js
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
/** @typedef {import("../MainTemplate")} MainTemplate */
class CompatRuntimeModule extends RuntimeModule {
constructor() {
super("compat", RuntimeModule.STAGE_ATTACH);
this.fullHash = true;
}
/**
* @returns {string} runtime code
*/
generate() {
const { chunkGraph, chunk, compilation } = this;
const {
runtimeTemplate,
mainTemplate,
moduleTemplates,
dependencyTemplates
} = compilation;
const bootstrap = mainTemplate.hooks.bootstrap.call(
"",
chunk,
compilation.hash || "XXXX",
moduleTemplates.javascript,
dependencyTemplates
);
const localVars = mainTemplate.hooks.localVars.call(
"",
chunk,
compilation.hash || "XXXX"
);
const requireExtensions = mainTemplate.hooks.requireExtensions.call(
"",
chunk,
compilation.hash || "XXXX"
);
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
let requireEnsure = "";
if (runtimeRequirements.has(RuntimeGlobals.ensureChunk)) {
const requireEnsureHandler = mainTemplate.hooks.requireEnsure.call(
"",
chunk,
compilation.hash || "XXXX",
"chunkId"
);
if (requireEnsureHandler) {
requireEnsure = `${
RuntimeGlobals.ensureChunkHandlers
}.compat = ${runtimeTemplate.basicFunction(
"chunkId, promises",
requireEnsureHandler
)};`;
}
}
return [bootstrap, localVars, requireEnsure, requireExtensions]
.filter(Boolean)
.join("\n");
}
/**
* @returns {boolean} true, if the runtime module should get it's own scope
*/
shouldIsolate() {
// We avoid isolating this to have better backward-compat
return false;
}
}
module.exports = CompatRuntimeModule;