webpack 5.91.0 → 5.92.1
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 +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +15 -15
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +213 -81
package/lib/ExternalModule.js
CHANGED
@@ -45,7 +45,7 @@ const { register } = require("./util/serialization");
|
|
45
45
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
46
46
|
/** @typedef {import("./WebpackError")} WebpackError */
|
47
47
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
48
|
-
/** @typedef {import("./javascript/JavascriptParser").
|
48
|
+
/** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
49
49
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
50
50
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
51
51
|
/** @typedef {import("./util/Hash")} Hash */
|
@@ -53,13 +53,13 @@ const { register } = require("./util/serialization");
|
|
53
53
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
54
54
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
55
55
|
|
56
|
-
/** @typedef {{ attributes?:
|
56
|
+
/** @typedef {{ attributes?: ImportAttributes }} ImportDependencyMeta */
|
57
57
|
/** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
|
58
58
|
|
59
59
|
/** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
|
60
60
|
|
61
61
|
/**
|
62
|
-
* @typedef {
|
62
|
+
* @typedef {object} SourceData
|
63
63
|
* @property {boolean=} iife
|
64
64
|
* @property {string=} init
|
65
65
|
* @property {string} expression
|
@@ -117,15 +117,19 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
117
117
|
/**
|
118
118
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
119
119
|
* @param {string} importMetaName import.meta name
|
120
|
+
* @param {boolean} needPrefix need to use `node:` prefix for `module` import
|
120
121
|
* @returns {SourceData} the generated source
|
121
122
|
*/
|
122
123
|
const getSourceForCommonJsExternalInNodeModule = (
|
123
124
|
moduleAndSpecifiers,
|
124
|
-
importMetaName
|
125
|
+
importMetaName,
|
126
|
+
needPrefix
|
125
127
|
) => {
|
126
128
|
const chunkInitFragments = [
|
127
129
|
new InitFragment(
|
128
|
-
|
130
|
+
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "${
|
131
|
+
needPrefix ? "node:" : ""
|
132
|
+
}module";\n`,
|
129
133
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
130
134
|
0,
|
131
135
|
"external module node-commonjs"
|
@@ -167,7 +171,12 @@ const getSourceForImportExternal = (
|
|
167
171
|
}
|
168
172
|
const attributes =
|
169
173
|
dependencyMeta && dependencyMeta.attributes
|
170
|
-
?
|
174
|
+
? dependencyMeta.attributes._isLegacyAssert
|
175
|
+
? `, { assert: ${JSON.stringify(
|
176
|
+
dependencyMeta.attributes,
|
177
|
+
importAssertionReplacer
|
178
|
+
)} }`
|
179
|
+
: `, { with: ${JSON.stringify(dependencyMeta.attributes)} }`
|
171
180
|
: "";
|
172
181
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
173
182
|
return {
|
@@ -194,6 +203,19 @@ const getSourceForImportExternal = (
|
|
194
203
|
};
|
195
204
|
};
|
196
205
|
|
206
|
+
/**
|
207
|
+
* @param {string} key key
|
208
|
+
* @param {any | undefined} value value
|
209
|
+
* @returns {undefined | string} replaced value
|
210
|
+
*/
|
211
|
+
const importAssertionReplacer = (key, value) => {
|
212
|
+
if (key === "_isLegacyAssert") {
|
213
|
+
return undefined;
|
214
|
+
}
|
215
|
+
|
216
|
+
return value;
|
217
|
+
};
|
218
|
+
|
197
219
|
/**
|
198
220
|
* @extends {InitFragment<ChunkRenderContext>}
|
199
221
|
*/
|
@@ -218,7 +240,12 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
218
240
|
super(
|
219
241
|
`import * as ${identifier} from ${JSON.stringify(request)}${
|
220
242
|
dependencyMeta && dependencyMeta.attributes
|
221
|
-
?
|
243
|
+
? dependencyMeta.attributes._isLegacyAssert
|
244
|
+
? ` assert ${JSON.stringify(
|
245
|
+
dependencyMeta.attributes,
|
246
|
+
importAssertionReplacer
|
247
|
+
)}`
|
248
|
+
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
|
222
249
|
: ""
|
223
250
|
};\n`,
|
224
251
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
@@ -329,13 +356,15 @@ const getSourceForModuleExternal = (
|
|
329
356
|
let expression = moduleRemapping || baseAccess;
|
330
357
|
return {
|
331
358
|
expression,
|
332
|
-
init:
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
359
|
+
init: moduleRemapping
|
360
|
+
? `var x = ${runtimeTemplate.basicFunction(
|
361
|
+
"y",
|
362
|
+
`var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x`
|
363
|
+
)} \nvar y = ${runtimeTemplate.returningFunction(
|
364
|
+
runtimeTemplate.returningFunction("x"),
|
365
|
+
"x"
|
366
|
+
)}`
|
367
|
+
: undefined,
|
339
368
|
runtimeRequirements: moduleRemapping
|
340
369
|
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
341
370
|
: undefined,
|
@@ -442,9 +471,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
442
471
|
};
|
443
472
|
};
|
444
473
|
|
474
|
+
/** @typedef {Record<string, string | string[]>} RequestRecord */
|
475
|
+
|
445
476
|
class ExternalModule extends Module {
|
446
477
|
/**
|
447
|
-
* @param {string | string[] |
|
478
|
+
* @param {string | string[] | RequestRecord} request request
|
448
479
|
* @param {string} type type
|
449
480
|
* @param {string} userRequest user request
|
450
481
|
* @param {DependencyMeta=} dependencyMeta dependency meta
|
@@ -669,9 +700,9 @@ class ExternalModule extends Module {
|
|
669
700
|
return /** @type {BuildInfo} */ (this.buildInfo).module
|
670
701
|
? getSourceForCommonJsExternalInNodeModule(
|
671
702
|
request,
|
672
|
-
/** @type {string} */
|
673
|
-
|
674
|
-
)
|
703
|
+
/** @type {string} */
|
704
|
+
(runtimeTemplate.outputOptions.importMetaName),
|
705
|
+
runtimeTemplate.supportNodePrefixForCoreModules()
|
675
706
|
)
|
676
707
|
: getSourceForCommonJsExternal(request);
|
677
708
|
case "amd":
|
package/lib/FileSystemInfo.js
CHANGED
@@ -46,19 +46,19 @@ const RBDT_FILE_DEPENDENCIES = 9;
|
|
46
46
|
const INVALID = Symbol("invalid");
|
47
47
|
|
48
48
|
/**
|
49
|
-
* @typedef {
|
49
|
+
* @typedef {object} FileSystemInfoEntry
|
50
50
|
* @property {number} safeTime
|
51
51
|
* @property {number=} timestamp
|
52
52
|
*/
|
53
53
|
|
54
54
|
/**
|
55
|
-
* @typedef {
|
55
|
+
* @typedef {object} ResolvedContextFileSystemInfoEntry
|
56
56
|
* @property {number} safeTime
|
57
57
|
* @property {string=} timestampHash
|
58
58
|
*/
|
59
59
|
|
60
60
|
/**
|
61
|
-
* @typedef {
|
61
|
+
* @typedef {object} ContextFileSystemInfoEntry
|
62
62
|
* @property {number} safeTime
|
63
63
|
* @property {string=} timestampHash
|
64
64
|
* @property {ResolvedContextFileSystemInfoEntry=} resolved
|
@@ -66,21 +66,21 @@ const INVALID = Symbol("invalid");
|
|
66
66
|
*/
|
67
67
|
|
68
68
|
/**
|
69
|
-
* @typedef {
|
69
|
+
* @typedef {object} TimestampAndHash
|
70
70
|
* @property {number} safeTime
|
71
71
|
* @property {number=} timestamp
|
72
72
|
* @property {string} hash
|
73
73
|
*/
|
74
74
|
|
75
75
|
/**
|
76
|
-
* @typedef {
|
76
|
+
* @typedef {object} ResolvedContextTimestampAndHash
|
77
77
|
* @property {number} safeTime
|
78
78
|
* @property {string=} timestampHash
|
79
79
|
* @property {string} hash
|
80
80
|
*/
|
81
81
|
|
82
82
|
/**
|
83
|
-
* @typedef {
|
83
|
+
* @typedef {object} ContextTimestampAndHash
|
84
84
|
* @property {number} safeTime
|
85
85
|
* @property {string=} timestampHash
|
86
86
|
* @property {string} hash
|
@@ -89,14 +89,14 @@ const INVALID = Symbol("invalid");
|
|
89
89
|
*/
|
90
90
|
|
91
91
|
/**
|
92
|
-
* @typedef {
|
92
|
+
* @typedef {object} ContextHash
|
93
93
|
* @property {string} hash
|
94
94
|
* @property {string=} resolved
|
95
95
|
* @property {Set<string>=} symlinks
|
96
96
|
*/
|
97
97
|
|
98
98
|
/**
|
99
|
-
* @typedef {
|
99
|
+
* @typedef {object} SnapshotOptimizationEntry
|
100
100
|
* @property {Snapshot} snapshot
|
101
101
|
* @property {number} shared
|
102
102
|
* @property {Set<string> | undefined} snapshotContent
|
@@ -104,19 +104,19 @@ const INVALID = Symbol("invalid");
|
|
104
104
|
*/
|
105
105
|
|
106
106
|
/**
|
107
|
-
* @typedef {
|
107
|
+
* @typedef {object} ResolveBuildDependenciesResult
|
108
108
|
* @property {Set<string>} files list of files
|
109
109
|
* @property {Set<string>} directories list of directories
|
110
110
|
* @property {Set<string>} missing list of missing entries
|
111
111
|
* @property {Map<string, string | false>} resolveResults stored resolve results
|
112
|
-
* @property {
|
112
|
+
* @property {object} resolveDependencies dependencies of the resolving
|
113
113
|
* @property {Set<string>} resolveDependencies.files list of files
|
114
114
|
* @property {Set<string>} resolveDependencies.directories list of directories
|
115
115
|
* @property {Set<string>} resolveDependencies.missing list of missing entries
|
116
116
|
*/
|
117
117
|
|
118
118
|
/**
|
119
|
-
* @typedef {
|
119
|
+
* @typedef {object} SnapshotOptions
|
120
120
|
* @property {boolean=} hash should use hash to snapshot
|
121
121
|
* @property {boolean=} timestamp should use timestamp to snapshot
|
122
122
|
*/
|
@@ -133,7 +133,13 @@ class SnapshotIterator {
|
|
133
133
|
}
|
134
134
|
}
|
135
135
|
|
136
|
+
/** @typedef {(snapshot: Snapshot) => (Map<string, any> | Set<string>)[]} GetMapsFunction */
|
137
|
+
|
136
138
|
class SnapshotIterable {
|
139
|
+
/**
|
140
|
+
* @param {Snapshot} snapshot snapshot
|
141
|
+
* @param {GetMapsFunction} getMaps get maps function
|
142
|
+
*/
|
137
143
|
constructor(snapshot, getMaps) {
|
138
144
|
this.snapshot = snapshot;
|
139
145
|
this.getMaps = getMaps;
|
@@ -213,6 +219,13 @@ class SnapshotIterable {
|
|
213
219
|
}
|
214
220
|
}
|
215
221
|
|
222
|
+
/** @typedef {Map<string, FileSystemInfoEntry | null>} FileTimestamps */
|
223
|
+
/** @typedef {Map<string, string | null>} FileHashes */
|
224
|
+
/** @typedef {Map<string, TimestampAndHash | string | null>} FileTshs */
|
225
|
+
/** @typedef {Map<string, ResolvedContextFileSystemInfoEntry | null>} ContextTimestamps */
|
226
|
+
/** @typedef {Map<string, string | null>} ContextHashes */
|
227
|
+
/** @typedef {Map<string, ResolvedContextTimestampAndHash | null>} ContextTshs */
|
228
|
+
|
216
229
|
class Snapshot {
|
217
230
|
constructor() {
|
218
231
|
this._flags = 0;
|
@@ -224,17 +237,17 @@ class Snapshot {
|
|
224
237
|
this._cachedMissingIterable = undefined;
|
225
238
|
/** @type {number | undefined} */
|
226
239
|
this.startTime = undefined;
|
227
|
-
/** @type {
|
240
|
+
/** @type {FileTimestamps | undefined} */
|
228
241
|
this.fileTimestamps = undefined;
|
229
|
-
/** @type {
|
242
|
+
/** @type {FileHashes | undefined} */
|
230
243
|
this.fileHashes = undefined;
|
231
|
-
/** @type {
|
244
|
+
/** @type {FileTshs | undefined} */
|
232
245
|
this.fileTshs = undefined;
|
233
|
-
/** @type {
|
246
|
+
/** @type {ContextTimestamps | undefined} */
|
234
247
|
this.contextTimestamps = undefined;
|
235
|
-
/** @type {
|
248
|
+
/** @type {ContextHashes | undefined} */
|
236
249
|
this.contextHashes = undefined;
|
237
|
-
/** @type {
|
250
|
+
/** @type {ContextTshs | undefined} */
|
238
251
|
this.contextTshs = undefined;
|
239
252
|
/** @type {Map<string, boolean> | undefined} */
|
240
253
|
this.missingExistence = undefined;
|
@@ -254,6 +267,9 @@ class Snapshot {
|
|
254
267
|
return (this._flags & 1) !== 0;
|
255
268
|
}
|
256
269
|
|
270
|
+
/**
|
271
|
+
* @param {number} value start value
|
272
|
+
*/
|
257
273
|
setStartTime(value) {
|
258
274
|
this._flags = this._flags | 1;
|
259
275
|
this.startTime = value;
|
@@ -427,7 +443,7 @@ class Snapshot {
|
|
427
443
|
}
|
428
444
|
|
429
445
|
/**
|
430
|
-
* @param {
|
446
|
+
* @param {GetMapsFunction} getMaps first
|
431
447
|
* @returns {Iterable<string>} iterable
|
432
448
|
*/
|
433
449
|
_createIterable(getMaps) {
|
@@ -728,6 +744,10 @@ class SnapshotOptimization {
|
|
728
744
|
}
|
729
745
|
}
|
730
746
|
|
747
|
+
/**
|
748
|
+
* @param {string} str input
|
749
|
+
* @returns {TODO} result
|
750
|
+
*/
|
731
751
|
const parseString = str => {
|
732
752
|
if (str[0] === "'" || str[0] === "`")
|
733
753
|
str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
|
@@ -898,7 +918,7 @@ const addAll = (source, target) => {
|
|
898
918
|
class FileSystemInfo {
|
899
919
|
/**
|
900
920
|
* @param {InputFileSystem} fs file system
|
901
|
-
* @param {
|
921
|
+
* @param {object} options options
|
902
922
|
* @param {Iterable<string | RegExp>=} options.unmanagedPaths paths that are not managed by a package manager and the contents are subject to change
|
903
923
|
* @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
|
904
924
|
* @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
|
@@ -989,7 +1009,7 @@ class FileSystemInfo {
|
|
989
1009
|
);
|
990
1010
|
/** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
991
1011
|
this._fileTimestamps = new StackedCacheMap();
|
992
|
-
/** @type {Map<string, string>} */
|
1012
|
+
/** @type {Map<string, string | null>} */
|
993
1013
|
this._fileHashes = new Map();
|
994
1014
|
/** @type {Map<string, TimestampAndHash | string>} */
|
995
1015
|
this._fileTshs = new Map();
|
@@ -1081,13 +1101,18 @@ class FileSystemInfo {
|
|
1081
1101
|
}
|
1082
1102
|
|
1083
1103
|
logStatistics() {
|
1104
|
+
const logger = /** @type {Logger} */ (this.logger);
|
1105
|
+
/**
|
1106
|
+
* @param {string} header header
|
1107
|
+
* @param {string | undefined} message message
|
1108
|
+
*/
|
1084
1109
|
const logWhenMessage = (header, message) => {
|
1085
1110
|
if (message) {
|
1086
|
-
|
1111
|
+
logger.log(`${header}: ${message}`);
|
1087
1112
|
}
|
1088
1113
|
};
|
1089
|
-
|
1090
|
-
|
1114
|
+
logger.log(`${this._statCreatedSnapshots} new snapshots created`);
|
1115
|
+
logger.log(
|
1091
1116
|
`${
|
1092
1117
|
this._statTestedSnapshotsNotCached &&
|
1093
1118
|
Math.round(
|
@@ -1099,7 +1124,7 @@ class FileSystemInfo {
|
|
1099
1124
|
this._statTestedSnapshotsCached + this._statTestedSnapshotsNotCached
|
1100
1125
|
})`
|
1101
1126
|
);
|
1102
|
-
|
1127
|
+
logger.log(
|
1103
1128
|
`${
|
1104
1129
|
this._statTestedChildrenNotCached &&
|
1105
1130
|
Math.round(
|
@@ -1110,8 +1135,8 @@ class FileSystemInfo {
|
|
1110
1135
|
this._statTestedChildrenCached + this._statTestedChildrenNotCached
|
1111
1136
|
})`
|
1112
1137
|
);
|
1113
|
-
|
1114
|
-
|
1138
|
+
logger.log(`${this._statTestedEntries} entries tested`);
|
1139
|
+
logger.log(
|
1115
1140
|
`File info in cache: ${this._fileTimestamps.size} timestamps ${this._fileHashes.size} hashes ${this._fileTshs.size} timestamp hash combinations`
|
1116
1141
|
);
|
1117
1142
|
logWhenMessage(
|
@@ -1126,7 +1151,7 @@ class FileSystemInfo {
|
|
1126
1151
|
`File timestamp hash combination snapshot optimization`,
|
1127
1152
|
this._fileTshsOptimization.getStatisticMessage()
|
1128
1153
|
);
|
1129
|
-
|
1154
|
+
logger.log(
|
1130
1155
|
`Directory info in cache: ${this._contextTimestamps.size} timestamps ${this._contextHashes.size} hashes ${this._contextTshs.size} timestamp hash combinations`
|
1131
1156
|
);
|
1132
1157
|
logWhenMessage(
|
@@ -1145,9 +1170,7 @@ class FileSystemInfo {
|
|
1145
1170
|
`Missing items snapshot optimization`,
|
1146
1171
|
this._missingExistenceOptimization.getStatisticMessage()
|
1147
1172
|
);
|
1148
|
-
|
1149
|
-
`Managed items info in cache: ${this._managedItems.size} items`
|
1150
|
-
);
|
1173
|
+
logger.log(`Managed items info in cache: ${this._managedItems.size} items`);
|
1151
1174
|
logWhenMessage(
|
1152
1175
|
`Managed items snapshot optimization`,
|
1153
1176
|
this._managedItemInfoOptimization.getStatisticMessage()
|
@@ -1302,13 +1325,15 @@ class FileSystemInfo {
|
|
1302
1325
|
const cache = this._contextHashes.get(path);
|
1303
1326
|
if (cache !== undefined) {
|
1304
1327
|
const resolved = getResolvedHash(cache);
|
1305
|
-
if (resolved !== undefined)
|
1328
|
+
if (resolved !== undefined)
|
1329
|
+
return callback(null, /** @type {string} */ (resolved));
|
1306
1330
|
return this._resolveContextHash(cache, callback);
|
1307
1331
|
}
|
1308
1332
|
this.contextHashQueue.add(path, (err, entry) => {
|
1309
1333
|
if (err) return callback(err);
|
1310
1334
|
const resolved = getResolvedHash(entry);
|
1311
|
-
if (resolved !== undefined)
|
1335
|
+
if (resolved !== undefined)
|
1336
|
+
return callback(null, /** @type {string} */ (resolved));
|
1312
1337
|
this._resolveContextHash(entry, callback);
|
1313
1338
|
});
|
1314
1339
|
}
|
@@ -1513,7 +1538,8 @@ class FileSystemInfo {
|
|
1513
1538
|
resolveResults.set(key, result.path);
|
1514
1539
|
} else {
|
1515
1540
|
invalidResolveResults.add(key);
|
1516
|
-
|
1541
|
+
/** @type {Logger} */
|
1542
|
+
(this.logger).warn(
|
1517
1543
|
`Resolving '${path}' in ${context} for build dependencies doesn't lead to expected result '${expected}', but to '${
|
1518
1544
|
err || (result && result.path)
|
1519
1545
|
}' instead. Resolving dependencies are ignored for this path.\n${pathToString(
|
@@ -1941,9 +1967,9 @@ class FileSystemInfo {
|
|
1941
1967
|
/**
|
1942
1968
|
*
|
1943
1969
|
* @param {number | null | undefined} startTime when processing the files has started
|
1944
|
-
* @param {Iterable<string>} files all files
|
1945
|
-
* @param {Iterable<string>} directories all directories
|
1946
|
-
* @param {Iterable<string>} missing all missing files or directories
|
1970
|
+
* @param {Iterable<string> | null} files all files
|
1971
|
+
* @param {Iterable<string> | null} directories all directories
|
1972
|
+
* @param {Iterable<string> | null} missing all missing files or directories
|
1947
1973
|
* @param {SnapshotOptions | null | undefined} options options object (for future extensions)
|
1948
1974
|
* @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
|
1949
1975
|
* @returns {void}
|
@@ -3018,7 +3044,7 @@ class FileSystemInfo {
|
|
3018
3044
|
/**
|
3019
3045
|
* @template T
|
3020
3046
|
* @template ItemType
|
3021
|
-
* @param {
|
3047
|
+
* @param {object} options options
|
3022
3048
|
* @param {string} options.path path
|
3023
3049
|
* @param {function(string): ItemType} options.fromImmutablePath called when context item is an immutable path
|
3024
3050
|
* @param {function(string): ItemType} options.fromManagedItem called when context item is a managed path
|
@@ -3318,7 +3344,7 @@ class FileSystemInfo {
|
|
3318
3344
|
|
3319
3345
|
/**
|
3320
3346
|
* @param {ContextHash} entry context hash
|
3321
|
-
* @param {function((
|
3347
|
+
* @param {function((WebpackError | null)=, string=): void} callback callback
|
3322
3348
|
* @returns {void}
|
3323
3349
|
*/
|
3324
3350
|
_resolveContextHash(entry, callback) {
|
@@ -3340,7 +3366,7 @@ class FileSystemInfo {
|
|
3340
3366
|
});
|
3341
3367
|
},
|
3342
3368
|
err => {
|
3343
|
-
if (err) return callback(err);
|
3369
|
+
if (err) return callback(/** @type {WebpackError} */ (err));
|
3344
3370
|
const hash = createHash(this._hashFunction);
|
3345
3371
|
hash.update(entry.hash);
|
3346
3372
|
hashes.sort();
|
@@ -3583,7 +3609,7 @@ class FileSystemInfo {
|
|
3583
3609
|
elements.length === 1 &&
|
3584
3610
|
elements[0] === "node_modules"
|
3585
3611
|
) {
|
3586
|
-
// This is only a grouping folder e.
|
3612
|
+
// This is only a grouping folder e.g. used by yarn
|
3587
3613
|
// we are only interested in existence of this special directory
|
3588
3614
|
this._managedItems.set(path, "*nested");
|
3589
3615
|
return callback(null, "*nested");
|
@@ -3604,7 +3630,8 @@ class FileSystemInfo {
|
|
3604
3630
|
return callback(e);
|
3605
3631
|
}
|
3606
3632
|
if (!data.name) {
|
3607
|
-
|
3633
|
+
/** @type {Logger} */
|
3634
|
+
(this.logger).warn(
|
3608
3635
|
`${packageJsonPath} doesn't contain a "name" property (see snapshot.managedPaths option)`
|
3609
3636
|
);
|
3610
3637
|
return callback();
|
@@ -15,6 +15,7 @@ const Queue = require("./util/Queue");
|
|
15
15
|
/** @typedef {import("./Dependency").ExportsSpec} ExportsSpec */
|
16
16
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
17
17
|
/** @typedef {import("./Module")} Module */
|
18
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
18
19
|
|
19
20
|
const PLUGIN_NAME = "FlagDependencyExportsPlugin";
|
20
21
|
const PLUGIN_LOGGER_NAME = `webpack.${PLUGIN_NAME}`;
|
@@ -63,7 +64,10 @@ class FlagDependencyExportsPlugin {
|
|
63
64
|
}
|
64
65
|
}
|
65
66
|
// If the module has no hash, it's uncacheable
|
66
|
-
if (
|
67
|
+
if (
|
68
|
+
typeof (/** @type {BuildInfo} */ (module.buildInfo).hash) !==
|
69
|
+
"string"
|
70
|
+
) {
|
67
71
|
statFlaggedUncached++;
|
68
72
|
// Enqueue uncacheable module for determining the exports
|
69
73
|
queue.enqueue(module);
|
@@ -79,7 +83,8 @@ class FlagDependencyExportsPlugin {
|
|
79
83
|
}
|
80
84
|
cache.get(
|
81
85
|
module.identifier(),
|
82
|
-
|
86
|
+
/** @type {BuildInfo} */
|
87
|
+
(module.buildInfo).hash,
|
83
88
|
(err, result) => {
|
84
89
|
if (err) return callback(err);
|
85
90
|
|
@@ -234,7 +239,10 @@ class FlagDependencyExportsPlugin {
|
|
234
239
|
if (exports) {
|
235
240
|
const nestedExportsInfo =
|
236
241
|
exportInfo.createNestedExportsInfo();
|
237
|
-
mergeExports(
|
242
|
+
mergeExports(
|
243
|
+
/** @type {ExportsInfo} */ (nestedExportsInfo),
|
244
|
+
exports
|
245
|
+
);
|
238
246
|
}
|
239
247
|
|
240
248
|
if (
|
@@ -272,7 +280,8 @@ class FlagDependencyExportsPlugin {
|
|
272
280
|
|
273
281
|
if (exportInfo.exportsInfoOwned) {
|
274
282
|
if (
|
275
|
-
|
283
|
+
/** @type {ExportsInfo} */
|
284
|
+
(exportInfo.exportsInfo).setRedirectNamedTo(
|
276
285
|
targetExportsInfo
|
277
286
|
)
|
278
287
|
) {
|
@@ -312,7 +321,7 @@ class FlagDependencyExportsPlugin {
|
|
312
321
|
|
313
322
|
logger.time("figure out provided exports");
|
314
323
|
while (queue.length > 0) {
|
315
|
-
module = queue.dequeue();
|
324
|
+
module = /** @type {Module} */ (queue.dequeue());
|
316
325
|
|
317
326
|
statQueueItemsProcessed++;
|
318
327
|
|
@@ -356,7 +365,11 @@ class FlagDependencyExportsPlugin {
|
|
356
365
|
asyncLib.each(
|
357
366
|
modulesToStore,
|
358
367
|
(module, callback) => {
|
359
|
-
if (
|
368
|
+
if (
|
369
|
+
typeof (
|
370
|
+
/** @type {BuildInfo} */ (module.buildInfo).hash
|
371
|
+
) !== "string"
|
372
|
+
) {
|
360
373
|
// not cacheable
|
361
374
|
return callback();
|
362
375
|
}
|
@@ -370,7 +383,8 @@ class FlagDependencyExportsPlugin {
|
|
370
383
|
}
|
371
384
|
cache.store(
|
372
385
|
module.identifier(),
|
373
|
-
|
386
|
+
/** @type {BuildInfo} */
|
387
|
+
(module.buildInfo).hash,
|
374
388
|
cachedData,
|
375
389
|
callback
|
376
390
|
);
|
package/lib/Generator.js
CHANGED
@@ -21,14 +21,13 @@
|
|
21
21
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
22
22
|
|
23
23
|
/**
|
24
|
-
* @typedef {
|
24
|
+
* @typedef {object} GenerateContext
|
25
25
|
* @property {DependencyTemplates} dependencyTemplates mapping from dependencies to templates
|
26
26
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
27
27
|
* @property {ModuleGraph} moduleGraph the module graph
|
28
28
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
29
29
|
* @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
|
30
30
|
* @property {RuntimeSpec} runtime the runtime
|
31
|
-
* @property {RuntimeSpec[]} [runtimes] the runtimes
|
32
31
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
33
32
|
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
34
33
|
* @property {string} type which kind of code should be generated
|
@@ -36,7 +35,7 @@
|
|
36
35
|
*/
|
37
36
|
|
38
37
|
/**
|
39
|
-
* @typedef {
|
38
|
+
* @typedef {object} UpdateHashContext
|
40
39
|
* @property {NormalModule} module the module
|
41
40
|
* @property {ChunkGraph} chunkGraph
|
42
41
|
* @property {RuntimeSpec} runtime
|