webpack 5.65.0 → 5.68.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/README.md +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +2 -0
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +91 -47
- package/lib/Compiler.js +57 -3
- package/lib/ContextModule.js +21 -17
- package/lib/DelegatedModule.js +1 -1
- package/lib/Dependency.js +10 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExternalModule.js +93 -53
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +29 -25
- package/lib/Generator.js +2 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/Module.js +25 -4
- package/lib/ModuleFilenameHelpers.js +5 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +9 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +50 -0
- package/lib/RuntimeTemplate.js +21 -0
- package/lib/Template.js +2 -1
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +43 -2
- package/lib/asset/AssetGenerator.js +64 -24
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/cache/ResolverCachePlugin.js +1 -1
- package/lib/cli.js +44 -3
- package/lib/config/defaults.js +79 -5
- package/lib/config/normalization.js +5 -0
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +447 -0
- package/lib/css/CssModulesPlugin.js +461 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +12 -10
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +45 -21
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +9 -12
- package/lib/ids/IdHelpers.js +24 -10
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +5 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/StartupHelpers.js +3 -3
- package/lib/library/AssignLibraryPlugin.js +26 -3
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -5
- package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +8 -8
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
- package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
- package/lib/util/ArrayHelpers.js +18 -4
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/internalSerializables.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -2
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +4 -11
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +96 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/types.d.ts +249 -39
@@ -9,7 +9,6 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const Template = require("../Template");
|
10
10
|
const { isSubset } = require("../util/SetHelpers");
|
11
11
|
const { getAllChunks } = require("./ChunkHelpers");
|
12
|
-
const { chunkHasJs } = require("./JavascriptModulesPlugin");
|
13
12
|
|
14
13
|
/** @typedef {import("../util/Hash")} Hash */
|
15
14
|
/** @typedef {import("../Chunk")} Chunk */
|
@@ -119,12 +118,13 @@ exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
|
|
119
118
|
/**
|
120
119
|
* @param {Chunk} chunk the chunk
|
121
120
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
121
|
+
* @param {function(Chunk, ChunkGraph): boolean} filterFn filter function
|
122
122
|
* @returns {Set<number | string>} initially fulfilled chunk ids
|
123
123
|
*/
|
124
|
-
exports.getInitialChunkIds = (chunk, chunkGraph) => {
|
124
|
+
exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
|
125
125
|
const initialChunkIds = new Set(chunk.ids);
|
126
126
|
for (const c of chunk.getAllInitialChunks()) {
|
127
|
-
if (c === chunk ||
|
127
|
+
if (c === chunk || filterFn(c, chunkGraph)) continue;
|
128
128
|
for (const id of c.ids) initialChunkIds.add(id);
|
129
129
|
}
|
130
130
|
return initialChunkIds;
|
@@ -92,7 +92,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
92
92
|
* @property {LibraryType} type
|
93
93
|
* @property {string[] | "global"} prefix name prefix
|
94
94
|
* @property {string | false} declare declare name as variable
|
95
|
-
* @property {"error"|"copy"|"assign"} unnamed behavior for unnamed library name
|
95
|
+
* @property {"error"|"static"|"copy"|"assign"} unnamed behavior for unnamed library name
|
96
96
|
* @property {"copy"|"assign"=} named behavior for named library name
|
97
97
|
*/
|
98
98
|
|
@@ -261,19 +261,42 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
261
261
|
* @param {LibraryContext<T>} libraryContext context
|
262
262
|
* @returns {Source} source with library export
|
263
263
|
*/
|
264
|
-
renderStartup(
|
264
|
+
renderStartup(
|
265
|
+
source,
|
266
|
+
module,
|
267
|
+
{ moduleGraph, chunk },
|
268
|
+
{ options, compilation }
|
269
|
+
) {
|
265
270
|
const fullNameResolved = this._getResolvedFullName(
|
266
271
|
options,
|
267
272
|
chunk,
|
268
273
|
compilation
|
269
274
|
);
|
275
|
+
const staticExports = this.unnamed === "static";
|
270
276
|
const exportAccess = options.export
|
271
277
|
? propertyAccess(
|
272
278
|
Array.isArray(options.export) ? options.export : [options.export]
|
273
279
|
)
|
274
280
|
: "";
|
275
281
|
const result = new ConcatSource(source);
|
276
|
-
if (
|
282
|
+
if (staticExports) {
|
283
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
284
|
+
const exportTarget = accessWithInit(
|
285
|
+
fullNameResolved,
|
286
|
+
this._getPrefix(compilation).length,
|
287
|
+
true
|
288
|
+
);
|
289
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
290
|
+
if (!exportInfo.provided) continue;
|
291
|
+
const nameAccess = propertyAccess([exportInfo.name]);
|
292
|
+
result.add(
|
293
|
+
`${exportTarget}${nameAccess} = __webpack_exports__${exportAccess}${nameAccess};\n`
|
294
|
+
);
|
295
|
+
}
|
296
|
+
result.add(
|
297
|
+
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
|
298
|
+
);
|
299
|
+
} else if (options.name ? this.named === "copy" : this.unnamed === "copy") {
|
277
300
|
result.add(
|
278
301
|
`var __webpack_export_target__ = ${accessWithInit(
|
279
302
|
fullNameResolved,
|
@@ -167,6 +167,17 @@ class EnableLibraryPlugin {
|
|
167
167
|
}).apply(compiler);
|
168
168
|
break;
|
169
169
|
}
|
170
|
+
case "commonjs-static": {
|
171
|
+
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
172
|
+
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
173
|
+
new AssignLibraryPlugin({
|
174
|
+
type,
|
175
|
+
prefix: ["exports"],
|
176
|
+
declare: false,
|
177
|
+
unnamed: "static"
|
178
|
+
}).apply(compiler);
|
179
|
+
break;
|
180
|
+
}
|
170
181
|
case "commonjs2":
|
171
182
|
case "commonjs-module": {
|
172
183
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
@@ -46,7 +46,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
46
46
|
);
|
47
47
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
48
48
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
49
|
-
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
49
|
+
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
50
50
|
|
51
51
|
const outputName = this.compilation.getPath(
|
52
52
|
getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
|
@@ -46,7 +46,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
46
46
|
);
|
47
47
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
48
48
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
49
|
-
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
49
|
+
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
50
50
|
|
51
51
|
const outputName = this.compilation.getPath(
|
52
52
|
getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
|
@@ -39,6 +39,7 @@ const {
|
|
39
39
|
/** @typedef {import("webpack-sources").Source} Source */
|
40
40
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
41
41
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
42
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
42
43
|
/** @typedef {import("../Compilation")} Compilation */
|
43
44
|
/** @typedef {import("../Dependency")} Dependency */
|
44
45
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
@@ -1077,7 +1078,8 @@ class ConcatenatedModule extends Module {
|
|
1077
1078
|
runtimeTemplate,
|
1078
1079
|
moduleGraph,
|
1079
1080
|
chunkGraph,
|
1080
|
-
runtime: generationRuntime
|
1081
|
+
runtime: generationRuntime,
|
1082
|
+
codeGenerationResults
|
1081
1083
|
}) {
|
1082
1084
|
/** @type {Set<string>} */
|
1083
1085
|
const runtimeRequirements = new Set();
|
@@ -1104,7 +1106,8 @@ class ConcatenatedModule extends Module {
|
|
1104
1106
|
runtimeTemplate,
|
1105
1107
|
moduleGraph,
|
1106
1108
|
chunkGraph,
|
1107
|
-
runtime
|
1109
|
+
runtime,
|
1110
|
+
codeGenerationResults
|
1108
1111
|
);
|
1109
1112
|
}
|
1110
1113
|
|
@@ -1634,6 +1637,7 @@ ${defineGetters}`
|
|
1634
1637
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
1635
1638
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
1636
1639
|
* @param {RuntimeSpec} runtime runtime
|
1640
|
+
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
1637
1641
|
*/
|
1638
1642
|
_analyseModule(
|
1639
1643
|
modulesMap,
|
@@ -1642,7 +1646,8 @@ ${defineGetters}`
|
|
1642
1646
|
runtimeTemplate,
|
1643
1647
|
moduleGraph,
|
1644
1648
|
chunkGraph,
|
1645
|
-
runtime
|
1649
|
+
runtime,
|
1650
|
+
codeGenerationResults
|
1646
1651
|
) {
|
1647
1652
|
if (info.type === "concatenated") {
|
1648
1653
|
const m = info.module;
|
@@ -1657,7 +1662,8 @@ ${defineGetters}`
|
|
1657
1662
|
moduleGraph,
|
1658
1663
|
chunkGraph,
|
1659
1664
|
runtime,
|
1660
|
-
concatenationScope
|
1665
|
+
concatenationScope,
|
1666
|
+
codeGenerationResults
|
1661
1667
|
});
|
1662
1668
|
const source = codeGenResult.sources.get("javascript");
|
1663
1669
|
const data = codeGenResult.data;
|
@@ -1702,7 +1708,7 @@ ${defineGetters}`
|
|
1702
1708
|
info.globalScope = globalScope;
|
1703
1709
|
info.moduleScope = moduleScope;
|
1704
1710
|
} catch (err) {
|
1705
|
-
err.message += `\nwhile
|
1711
|
+
err.message += `\nwhile analyzing module ${m.identifier()} for concatenation`;
|
1706
1712
|
throw err;
|
1707
1713
|
}
|
1708
1714
|
}
|
@@ -22,6 +22,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
return Template.asString([
|
23
23
|
'var webpackThen = typeof Symbol === "function" ? Symbol("webpack then") : "__webpack_then__";',
|
24
24
|
'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";',
|
25
|
+
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
|
25
26
|
`var completeQueue = ${runtimeTemplate.basicFunction("queue", [
|
26
27
|
"if(queue) {",
|
27
28
|
Template.indent([
|
@@ -56,9 +57,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
56
57
|
"obj[webpackExports] = r;",
|
57
58
|
"completeQueue(queue);",
|
58
59
|
"queue = 0;"
|
60
|
+
])}, ${runtimeTemplate.basicFunction("e", [
|
61
|
+
"obj[webpackError] = e;",
|
62
|
+
"completeQueue(queue);",
|
63
|
+
"queue = 0;"
|
59
64
|
])});`,
|
60
|
-
|
61
|
-
obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
65
|
+
"var obj = {};",
|
66
|
+
`obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
62
67
|
"queueFunction(queue, fn), dep['catch'](reject)",
|
63
68
|
"fn, reject"
|
64
69
|
)};`,
|
@@ -67,13 +72,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
67
72
|
"}"
|
68
73
|
]),
|
69
74
|
"}",
|
70
|
-
|
71
|
-
ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
75
|
+
"var ret = {};",
|
76
|
+
`ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
72
77
|
"completeFunction(fn)",
|
73
78
|
"fn"
|
74
|
-
)}
|
75
|
-
ret[webpackExports] = dep;
|
76
|
-
return ret
|
79
|
+
)};`,
|
80
|
+
"ret[webpackExports] = dep;",
|
81
|
+
"return ret;"
|
77
82
|
])})`,
|
78
83
|
"deps"
|
79
84
|
)};`,
|
@@ -119,24 +124,29 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
119
124
|
)};`,
|
120
125
|
"module.exports = promise;",
|
121
126
|
`body(${runtimeTemplate.basicFunction("deps", [
|
122
|
-
"if(!deps) return outerResolve();",
|
123
127
|
"currentDeps = wrapDeps(deps);",
|
124
|
-
"var fn
|
128
|
+
"var fn;",
|
129
|
+
`var getResult = ${runtimeTemplate.returningFunction(
|
130
|
+
`currentDeps.map(${runtimeTemplate.basicFunction("d", [
|
131
|
+
"if(d[webpackError]) throw d[webpackError];",
|
132
|
+
"return d[webpackExports];"
|
133
|
+
])})`
|
134
|
+
)}`,
|
125
135
|
`var promise = new Promise(${runtimeTemplate.basicFunction(
|
126
136
|
"resolve, reject",
|
127
137
|
[
|
128
138
|
`fn = ${runtimeTemplate.expressionFunction(
|
129
|
-
|
130
|
-
"d[webpackExports]",
|
131
|
-
"d"
|
132
|
-
)}))`
|
139
|
+
"resolve(getResult)"
|
133
140
|
)};`,
|
134
141
|
"fn.r = 0;",
|
135
142
|
"whenAll(currentDeps, fn, reject);"
|
136
143
|
]
|
137
144
|
)});`,
|
138
|
-
"return fn.r ? promise :
|
139
|
-
])}
|
145
|
+
"return fn.r ? promise : getResult();"
|
146
|
+
])}, ${runtimeTemplate.expressionFunction(
|
147
|
+
"err && reject(promise[webpackError] = err), outerResolve()",
|
148
|
+
"err"
|
149
|
+
)});`,
|
140
150
|
"isEvaluating = false;"
|
141
151
|
])};`
|
142
152
|
]);
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class CreateScriptRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("trusted types script");
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { compilation } = this;
|
21
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
22
|
+
const { trustedTypes } = outputOptions;
|
23
|
+
const fn = RuntimeGlobals.createScript;
|
24
|
+
|
25
|
+
return Template.asString(
|
26
|
+
`${fn} = ${runtimeTemplate.returningFunction(
|
27
|
+
trustedTypes
|
28
|
+
? `${RuntimeGlobals.getTrustedTypesPolicy}().createScript(script)`
|
29
|
+
: "script",
|
30
|
+
"script"
|
31
|
+
)};`
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
module.exports = CreateScriptRuntimeModule;
|
@@ -10,7 +10,7 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
10
10
|
|
11
11
|
class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
12
12
|
constructor() {
|
13
|
-
super("trusted types");
|
13
|
+
super("trusted types script url");
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
@@ -22,39 +22,14 @@ class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
const { trustedTypes } = outputOptions;
|
23
23
|
const fn = RuntimeGlobals.createScriptUrl;
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"var policy;",
|
34
|
-
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
35
|
-
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
|
36
|
-
"if (policy === undefined) {",
|
37
|
-
Template.indent([
|
38
|
-
"policy = {",
|
39
|
-
Template.indent([
|
40
|
-
`createScriptURL: ${runtimeTemplate.returningFunction(
|
41
|
-
"url",
|
42
|
-
"url"
|
43
|
-
)}`
|
44
|
-
]),
|
45
|
-
"};",
|
46
|
-
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
|
47
|
-
Template.indent([
|
48
|
-
`policy = trustedTypes.createPolicy(${JSON.stringify(
|
49
|
-
trustedTypes.policyName
|
50
|
-
)}, policy);`
|
51
|
-
]),
|
52
|
-
"}"
|
53
|
-
]),
|
54
|
-
"}",
|
55
|
-
"return policy.createScriptURL(url);"
|
56
|
-
])};`
|
57
|
-
]);
|
25
|
+
return Template.asString(
|
26
|
+
`${fn} = ${runtimeTemplate.returningFunction(
|
27
|
+
trustedTypes
|
28
|
+
? `${RuntimeGlobals.getTrustedTypesPolicy}().createScriptURL(url)`
|
29
|
+
: "url",
|
30
|
+
"url"
|
31
|
+
)};`
|
32
|
+
);
|
58
33
|
}
|
59
34
|
}
|
60
35
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
12
|
+
/**
|
13
|
+
* @param {Set<string>} runtimeRequirements runtime requirements
|
14
|
+
*/
|
15
|
+
constructor(runtimeRequirements) {
|
16
|
+
super("trusted types policy");
|
17
|
+
this.runtimeRequirements = runtimeRequirements;
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @returns {string} runtime code
|
22
|
+
*/
|
23
|
+
generate() {
|
24
|
+
const { compilation } = this;
|
25
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
26
|
+
const { trustedTypes } = outputOptions;
|
27
|
+
const fn = RuntimeGlobals.getTrustedTypesPolicy;
|
28
|
+
|
29
|
+
return Template.asString([
|
30
|
+
"var policy;",
|
31
|
+
`${fn} = ${runtimeTemplate.basicFunction("", [
|
32
|
+
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
|
33
|
+
"if (policy === undefined) {",
|
34
|
+
Template.indent([
|
35
|
+
"policy = {",
|
36
|
+
Template.indent(
|
37
|
+
[
|
38
|
+
...(this.runtimeRequirements.has(RuntimeGlobals.createScript)
|
39
|
+
? [
|
40
|
+
`createScript: ${runtimeTemplate.returningFunction(
|
41
|
+
"script",
|
42
|
+
"script"
|
43
|
+
)}`
|
44
|
+
]
|
45
|
+
: []),
|
46
|
+
...(this.runtimeRequirements.has(RuntimeGlobals.createScriptUrl)
|
47
|
+
? [
|
48
|
+
`createScriptURL: ${runtimeTemplate.returningFunction(
|
49
|
+
"url",
|
50
|
+
"url"
|
51
|
+
)}`
|
52
|
+
]
|
53
|
+
: [])
|
54
|
+
].join(",\n")
|
55
|
+
),
|
56
|
+
"};",
|
57
|
+
...(trustedTypes
|
58
|
+
? [
|
59
|
+
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
|
60
|
+
Template.indent([
|
61
|
+
`policy = trustedTypes.createPolicy(${JSON.stringify(
|
62
|
+
trustedTypes.policyName
|
63
|
+
)}, policy);`
|
64
|
+
]),
|
65
|
+
"}"
|
66
|
+
]
|
67
|
+
: [])
|
68
|
+
]),
|
69
|
+
"}",
|
70
|
+
"return policy;"
|
71
|
+
])};`
|
72
|
+
]);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
module.exports = GetTrustedTypesPolicyRuntimeModule;
|
@@ -166,7 +166,7 @@ class Lockfile {
|
|
166
166
|
/**
|
167
167
|
* @template R
|
168
168
|
* @param {function(function(Error=, R=): void): void} fn function
|
169
|
-
* @returns {function(function(Error=, R=): void): void} cached function
|
169
|
+
* @returns {function(function((Error | null)=, R=): void): void} cached function
|
170
170
|
*/
|
171
171
|
const cachedWithoutKey = fn => {
|
172
172
|
let inFlight = false;
|
@@ -201,10 +201,10 @@ const cachedWithoutKey = fn => {
|
|
201
201
|
* @template R
|
202
202
|
* @param {function(T, function(Error=, R=): void): void} fn function
|
203
203
|
* @param {function(T, function(Error=, R=): void): void=} forceFn function for the second try
|
204
|
-
* @returns {(function(T, function(Error=, R=): void): void) & { force: function(T, function(Error=, R=): void): void }} cached function
|
204
|
+
* @returns {(function(T, function((Error | null)=, R=): void): void) & { force: function(T, function((Error | null)=, R=): void): void }} cached function
|
205
205
|
*/
|
206
206
|
const cachedWithKey = (fn, forceFn = fn) => {
|
207
|
-
/** @typedef {{ result?: R, error?: Error, callbacks?: (function(Error=, R=): void)[], force?: true }} CacheEntry */
|
207
|
+
/** @typedef {{ result?: R, error?: Error, callbacks?: (function((Error | null)=, R=): void)[], force?: true }} CacheEntry */
|
208
208
|
/** @type {Map<T, CacheEntry>} */
|
209
209
|
const cache = new Map();
|
210
210
|
const resultFn = (arg, callback) => {
|
@@ -358,7 +358,7 @@ class HttpUriPlugin {
|
|
358
358
|
|
359
359
|
const getLockfile = cachedWithoutKey(
|
360
360
|
/**
|
361
|
-
* @param {function(Error=, Lockfile=): void} callback callback
|
361
|
+
* @param {function((Error | null)=, Lockfile=): void} callback callback
|
362
362
|
* @returns {void}
|
363
363
|
*/
|
364
364
|
callback => {
|
@@ -465,7 +465,7 @@ class HttpUriPlugin {
|
|
465
465
|
*
|
466
466
|
* @param {string} url URL
|
467
467
|
* @param {string} integrity integrity
|
468
|
-
* @param {function(Error=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback
|
468
|
+
* @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback
|
469
469
|
*/
|
470
470
|
const resolveContent = (url, integrity, callback) => {
|
471
471
|
const handleResult = (err, result) => {
|
@@ -510,7 +510,7 @@ class HttpUriPlugin {
|
|
510
510
|
/**
|
511
511
|
* @param {string} url URL
|
512
512
|
* @param {FetchResult} cachedResult result from cache
|
513
|
-
* @param {function(Error=, FetchResult=): void} callback callback
|
513
|
+
* @param {function((Error | null)=, FetchResult=): void} callback callback
|
514
514
|
* @returns {void}
|
515
515
|
*/
|
516
516
|
const fetchContentRaw = (url, cachedResult, callback) => {
|
@@ -662,7 +662,7 @@ class HttpUriPlugin {
|
|
662
662
|
const fetchContent = cachedWithKey(
|
663
663
|
/**
|
664
664
|
* @param {string} url URL
|
665
|
-
* @param {function(Error=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback
|
665
|
+
* @param {function((Error | null)=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback
|
666
666
|
* @returns {void}
|
667
667
|
*/ (url, callback) => {
|
668
668
|
cache.get(url, null, (err, cachedResult) => {
|
@@ -693,7 +693,7 @@ class HttpUriPlugin {
|
|
693
693
|
const getInfo = cachedWithKey(
|
694
694
|
/**
|
695
695
|
* @param {string} url the url
|
696
|
-
* @param {function(Error=, { entry: LockfileEntry, content: Buffer }=): void} callback callback
|
696
|
+
* @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer }=): void} callback callback
|
697
697
|
* @returns {void}
|
698
698
|
*/
|
699
699
|
(url, callback) => {
|
@@ -101,14 +101,16 @@ class ConsumeSharedModule extends Module {
|
|
101
101
|
*/
|
102
102
|
libIdent(options) {
|
103
103
|
const { shareKey, shareScope, import: request } = this.options;
|
104
|
-
return
|
104
|
+
return `${
|
105
|
+
this.layer ? `(${this.layer})/` : ""
|
106
|
+
}webpack/sharing/consume/${shareScope}/${shareKey}${
|
105
107
|
request ? `/${request}` : ""
|
106
108
|
}`;
|
107
109
|
}
|
108
110
|
|
109
111
|
/**
|
110
112
|
* @param {NeedBuildContext} context context info
|
111
|
-
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
113
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
112
114
|
* @returns {void}
|
113
115
|
*/
|
114
116
|
needBuild(context, callback) {
|
@@ -67,12 +67,14 @@ class ProvideSharedModule extends Module {
|
|
67
67
|
* @returns {string | null} an identifier for library inclusion
|
68
68
|
*/
|
69
69
|
libIdent(options) {
|
70
|
-
return `webpack/sharing/provide/${
|
70
|
+
return `${this.layer ? `(${this.layer})/` : ""}webpack/sharing/provide/${
|
71
|
+
this._shareScope
|
72
|
+
}/${this._name}`;
|
71
73
|
}
|
72
74
|
|
73
75
|
/**
|
74
76
|
* @param {NeedBuildContext} context context info
|
75
|
-
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
77
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
76
78
|
* @returns {void}
|
77
79
|
*/
|
78
80
|
needBuild(context, callback) {
|
package/lib/sharing/utils.js
CHANGED
@@ -22,7 +22,7 @@ exports.isRequiredVersion = str => {
|
|
22
22
|
* @param {InputFileSystem} fs file system
|
23
23
|
* @param {string} directory directory to start looking into
|
24
24
|
* @param {string[]} descriptionFiles possible description filenames
|
25
|
-
* @param {function(Error=, {data: object, path: string}=): void} callback callback
|
25
|
+
* @param {function((Error | null)=, {data: object, path: string}=): void} callback callback
|
26
26
|
*/
|
27
27
|
const getDescriptionFile = (fs, directory, descriptionFiles, callback) => {
|
28
28
|
let i = 0;
|