webpack 5.94.0 → 5.96.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.
- package/README.md +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EnvironmentPlugin.js +3 -2
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +118 -99
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -13
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/TemplatedPathPlugin.js +9 -3
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +79 -62
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +135 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/ContextDependency.js +6 -1
- package/lib/dependencies/ContextElementDependency.js +33 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +35 -6
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +166 -88
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +44 -148
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazySet.js +12 -0
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +10 -10
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +10 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +19 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -2
- package/types.d.ts +817 -269
- package/lib/util/mergeScope.js +0 -76
package/lib/util/LazySet.js
CHANGED
@@ -138,6 +138,9 @@ class LazySet {
|
|
138
138
|
return this._set.delete(value);
|
139
139
|
}
|
140
140
|
|
141
|
+
/**
|
142
|
+
* @returns {IterableIterator<[T, T]>} entries
|
143
|
+
*/
|
141
144
|
entries() {
|
142
145
|
this._deopt = true;
|
143
146
|
if (this._needMerge) this._merge();
|
@@ -165,18 +168,27 @@ class LazySet {
|
|
165
168
|
return this._set.has(item);
|
166
169
|
}
|
167
170
|
|
171
|
+
/**
|
172
|
+
* @returns {IterableIterator<T>} keys
|
173
|
+
*/
|
168
174
|
keys() {
|
169
175
|
this._deopt = true;
|
170
176
|
if (this._needMerge) this._merge();
|
171
177
|
return this._set.keys();
|
172
178
|
}
|
173
179
|
|
180
|
+
/**
|
181
|
+
* @returns {IterableIterator<T>} values
|
182
|
+
*/
|
174
183
|
values() {
|
175
184
|
this._deopt = true;
|
176
185
|
if (this._needMerge) this._merge();
|
177
186
|
return this._set.values();
|
178
187
|
}
|
179
188
|
|
189
|
+
/**
|
190
|
+
* @returns {IterableIterator<T>} iterable iterator
|
191
|
+
*/
|
180
192
|
[Symbol.iterator]() {
|
181
193
|
this._deopt = true;
|
182
194
|
if (this._needMerge) this._merge();
|
package/lib/util/SetHelpers.js
CHANGED
package/lib/util/cleverMerge.js
CHANGED
@@ -82,11 +82,13 @@ const cachedSetProperty = (obj, property, value) => {
|
|
82
82
|
return /** @type {T} */ (result);
|
83
83
|
};
|
84
84
|
|
85
|
+
/** @typedef {Map<string, any>} ByValues */
|
86
|
+
|
85
87
|
/**
|
86
88
|
* @typedef {object} ObjectParsedPropertyEntry
|
87
89
|
* @property {any | undefined} base base value
|
88
90
|
* @property {string | undefined} byProperty the name of the selector property
|
89
|
-
* @property {
|
91
|
+
* @property {ByValues} byValues value depending on selector property, merged with base
|
90
92
|
*/
|
91
93
|
|
92
94
|
/**
|
@@ -111,12 +113,17 @@ const cachedParseObject = obj => {
|
|
111
113
|
};
|
112
114
|
|
113
115
|
/**
|
114
|
-
* @
|
116
|
+
* @template {object} T
|
117
|
+
* @param {T} obj the object
|
115
118
|
* @returns {ParsedObject} parsed object
|
116
119
|
*/
|
117
120
|
const parseObject = obj => {
|
118
121
|
const info = new Map();
|
119
122
|
let dynamicInfo;
|
123
|
+
/**
|
124
|
+
* @param {string} p path
|
125
|
+
* @returns {Partial<ObjectParsedPropertyEntry>} object parsed property entry
|
126
|
+
*/
|
120
127
|
const getInfo = p => {
|
121
128
|
const entry = info.get(p);
|
122
129
|
if (entry !== undefined) return entry;
|
@@ -130,26 +137,33 @@ const parseObject = obj => {
|
|
130
137
|
};
|
131
138
|
for (const key of Object.keys(obj)) {
|
132
139
|
if (key.startsWith("by")) {
|
133
|
-
const byProperty = key;
|
134
|
-
const byObj = obj[byProperty];
|
140
|
+
const byProperty = /** @type {keyof T} */ (key);
|
141
|
+
const byObj = /** @type {object} */ (obj[byProperty]);
|
135
142
|
if (typeof byObj === "object") {
|
136
143
|
for (const byValue of Object.keys(byObj)) {
|
137
|
-
const obj = byObj[byValue];
|
144
|
+
const obj = byObj[/** @type {keyof (keyof T)} */ (byValue)];
|
138
145
|
for (const key of Object.keys(obj)) {
|
139
146
|
const entry = getInfo(key);
|
140
147
|
if (entry.byProperty === undefined) {
|
141
|
-
entry.byProperty = byProperty;
|
148
|
+
entry.byProperty = /** @type {string} */ (byProperty);
|
142
149
|
entry.byValues = new Map();
|
143
150
|
} else if (entry.byProperty !== byProperty) {
|
144
151
|
throw new Error(
|
145
|
-
`${byProperty} and ${entry.byProperty} for a single property is not supported`
|
152
|
+
`${/** @type {string} */ (byProperty)} and ${entry.byProperty} for a single property is not supported`
|
146
153
|
);
|
147
154
|
}
|
148
|
-
|
155
|
+
/** @type {ByValues} */
|
156
|
+
(entry.byValues).set(
|
157
|
+
byValue,
|
158
|
+
obj[/** @type {keyof (keyof T)} */ (key)]
|
159
|
+
);
|
149
160
|
if (byValue === "default") {
|
150
161
|
for (const otherByValue of Object.keys(byObj)) {
|
151
|
-
if (
|
152
|
-
entry.byValues.
|
162
|
+
if (
|
163
|
+
!(/** @type {ByValues} */ (entry.byValues).has(otherByValue))
|
164
|
+
)
|
165
|
+
/** @type {ByValues} */
|
166
|
+
(entry.byValues).set(otherByValue, undefined);
|
153
167
|
}
|
154
168
|
}
|
155
169
|
}
|
@@ -167,11 +181,11 @@ const parseObject = obj => {
|
|
167
181
|
}
|
168
182
|
} else {
|
169
183
|
const entry = getInfo(key);
|
170
|
-
entry.base = obj[key];
|
184
|
+
entry.base = obj[/** @type {keyof T} */ (key)];
|
171
185
|
}
|
172
186
|
} else {
|
173
187
|
const entry = getInfo(key);
|
174
|
-
entry.base = obj[key];
|
188
|
+
entry.base = obj[/** @type {keyof T} */ (key)];
|
175
189
|
}
|
176
190
|
}
|
177
191
|
return {
|
@@ -181,12 +195,13 @@ const parseObject = obj => {
|
|
181
195
|
};
|
182
196
|
|
183
197
|
/**
|
198
|
+
* @template {object} T
|
184
199
|
* @param {Map<string, ObjectParsedPropertyEntry>} info static properties (key is property name)
|
185
200
|
* @param {{ byProperty: string, fn: Function } | undefined} dynamicInfo dynamic part
|
186
|
-
* @returns {
|
201
|
+
* @returns {T} the object
|
187
202
|
*/
|
188
203
|
const serializeObject = (info, dynamicInfo) => {
|
189
|
-
const obj = {};
|
204
|
+
const obj = /** @type {T} */ ({});
|
190
205
|
// Setup byProperty structure
|
191
206
|
for (const entry of info.values()) {
|
192
207
|
if (entry.byProperty !== undefined) {
|
@@ -198,7 +213,7 @@ const serializeObject = (info, dynamicInfo) => {
|
|
198
213
|
}
|
199
214
|
for (const [key, entry] of info) {
|
200
215
|
if (entry.base !== undefined) {
|
201
|
-
obj[key] = entry.base;
|
216
|
+
obj[/** @type {keyof T} */ (key)] = entry.base;
|
202
217
|
}
|
203
218
|
// Fill byProperty structure
|
204
219
|
if (entry.byProperty !== undefined) {
|
@@ -475,7 +490,7 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
475
490
|
case VALUE_TYPE_UNDEFINED:
|
476
491
|
return b;
|
477
492
|
case VALUE_TYPE_DELETE:
|
478
|
-
return b.filter(item => item !== "...");
|
493
|
+
return /** @type {any[]} */ (b).filter(item => item !== "...");
|
479
494
|
case VALUE_TYPE_ARRAY_EXTEND: {
|
480
495
|
const newArray = [];
|
481
496
|
for (const item of b) {
|
@@ -490,7 +505,9 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
490
505
|
return newArray;
|
491
506
|
}
|
492
507
|
case VALUE_TYPE_OBJECT:
|
493
|
-
return b.map(item =>
|
508
|
+
return /** @type {any[]} */ (b).map(item =>
|
509
|
+
item === "..." ? a : item
|
510
|
+
);
|
494
511
|
default:
|
495
512
|
throw new Error("Not implemented");
|
496
513
|
}
|
@@ -522,15 +539,22 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
|
|
522
539
|
case VALUE_TYPE_DELETE:
|
523
540
|
break;
|
524
541
|
case VALUE_TYPE_OBJECT:
|
525
|
-
newObj[key] =
|
526
|
-
/** @type {
|
527
|
-
|
528
|
-
|
542
|
+
newObj[/** @type {keyof T} */ (key)] =
|
543
|
+
/** @type {T[keyof T]} */
|
544
|
+
(
|
545
|
+
removeOperations(
|
546
|
+
/** @type {TODO} */ (value),
|
547
|
+
keysToKeepOriginalValue
|
548
|
+
)
|
549
|
+
);
|
529
550
|
break;
|
530
551
|
case VALUE_TYPE_ARRAY_EXTEND:
|
531
|
-
newObj[key] =
|
532
|
-
/** @type {
|
533
|
-
(
|
552
|
+
newObj[/** @type {keyof T} */ (key)] =
|
553
|
+
/** @type {T[keyof T]} */
|
554
|
+
(
|
555
|
+
/** @type {any[]} */
|
556
|
+
(value).filter(i => i !== "...")
|
557
|
+
);
|
534
558
|
break;
|
535
559
|
default:
|
536
560
|
newObj[/** @type {keyof T} */ (key)] = value;
|
@@ -0,0 +1,227 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const Template = require("../Template");
|
9
|
+
|
10
|
+
/** @typedef {import("eslint-scope").Scope} Scope */
|
11
|
+
/** @typedef {import("eslint-scope").Reference} Reference */
|
12
|
+
/** @typedef {import("eslint-scope").Variable} Variable */
|
13
|
+
/** @typedef {import("estree").Node} Node */
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
15
|
+
/** @typedef {import("../javascript/JavascriptParser").Program} Program */
|
16
|
+
/** @typedef {Set<string>} UsedNames */
|
17
|
+
|
18
|
+
const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
|
19
|
+
const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @param {Variable} variable variable
|
23
|
+
* @returns {Reference[]} references
|
24
|
+
*/
|
25
|
+
const getAllReferences = variable => {
|
26
|
+
let set = variable.references;
|
27
|
+
// Look for inner scope variables too (like in class Foo { t() { Foo } })
|
28
|
+
const identifiers = new Set(variable.identifiers);
|
29
|
+
for (const scope of variable.scope.childScopes) {
|
30
|
+
for (const innerVar of scope.variables) {
|
31
|
+
if (innerVar.identifiers.some(id => identifiers.has(id))) {
|
32
|
+
set = set.concat(innerVar.references);
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return set;
|
38
|
+
};
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @param {Node | Node[]} ast ast
|
42
|
+
* @param {Node} node node
|
43
|
+
* @returns {undefined | Node[]} result
|
44
|
+
*/
|
45
|
+
const getPathInAst = (ast, node) => {
|
46
|
+
if (ast === node) {
|
47
|
+
return [];
|
48
|
+
}
|
49
|
+
|
50
|
+
const nr = /** @type {Range} */ (node.range);
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @param {Node} n node
|
54
|
+
* @returns {Node[] | undefined} result
|
55
|
+
*/
|
56
|
+
const enterNode = n => {
|
57
|
+
if (!n) return;
|
58
|
+
const r = n.range;
|
59
|
+
if (r && r[0] <= nr[0] && r[1] >= nr[1]) {
|
60
|
+
const path = getPathInAst(n, node);
|
61
|
+
if (path) {
|
62
|
+
path.push(n);
|
63
|
+
return path;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
};
|
67
|
+
|
68
|
+
if (Array.isArray(ast)) {
|
69
|
+
for (let i = 0; i < ast.length; i++) {
|
70
|
+
const enterResult = enterNode(ast[i]);
|
71
|
+
if (enterResult !== undefined) return enterResult;
|
72
|
+
}
|
73
|
+
} else if (ast && typeof ast === "object") {
|
74
|
+
const keys =
|
75
|
+
/** @type {Array<keyof Node>} */
|
76
|
+
(Object.keys(ast));
|
77
|
+
for (let i = 0; i < keys.length; i++) {
|
78
|
+
// We are making the faster check in `enterNode` using `n.range`
|
79
|
+
const value =
|
80
|
+
ast[
|
81
|
+
/** @type {Exclude<keyof Node, "range" | "loc" | "leadingComments" | "trailingComments">} */
|
82
|
+
(keys[i])
|
83
|
+
];
|
84
|
+
if (Array.isArray(value)) {
|
85
|
+
const pathResult = getPathInAst(value, node);
|
86
|
+
if (pathResult !== undefined) return pathResult;
|
87
|
+
} else if (value && typeof value === "object") {
|
88
|
+
const enterResult = enterNode(value);
|
89
|
+
if (enterResult !== undefined) return enterResult;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
/**
|
96
|
+
* @param {string} oldName old name
|
97
|
+
* @param {UsedNames} usedNamed1 used named 1
|
98
|
+
* @param {UsedNames} usedNamed2 used named 2
|
99
|
+
* @param {string} extraInfo extra info
|
100
|
+
* @returns {string} found new name
|
101
|
+
*/
|
102
|
+
function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
|
103
|
+
let name = oldName;
|
104
|
+
|
105
|
+
if (name === DEFAULT_EXPORT) {
|
106
|
+
name = "";
|
107
|
+
}
|
108
|
+
if (name === NAMESPACE_OBJECT_EXPORT) {
|
109
|
+
name = "namespaceObject";
|
110
|
+
}
|
111
|
+
|
112
|
+
// Remove uncool stuff
|
113
|
+
extraInfo = extraInfo.replace(
|
114
|
+
/\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
|
115
|
+
""
|
116
|
+
);
|
117
|
+
|
118
|
+
const splittedInfo = extraInfo.split("/");
|
119
|
+
while (splittedInfo.length) {
|
120
|
+
name = splittedInfo.pop() + (name ? `_${name}` : "");
|
121
|
+
const nameIdent = Template.toIdentifier(name);
|
122
|
+
if (
|
123
|
+
!usedNamed1.has(nameIdent) &&
|
124
|
+
(!usedNamed2 || !usedNamed2.has(nameIdent))
|
125
|
+
)
|
126
|
+
return nameIdent;
|
127
|
+
}
|
128
|
+
|
129
|
+
let i = 0;
|
130
|
+
let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
131
|
+
while (
|
132
|
+
usedNamed1.has(nameWithNumber) ||
|
133
|
+
// eslint-disable-next-line no-unmodified-loop-condition
|
134
|
+
(usedNamed2 && usedNamed2.has(nameWithNumber))
|
135
|
+
) {
|
136
|
+
i++;
|
137
|
+
nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
138
|
+
}
|
139
|
+
return nameWithNumber;
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @param {Scope | null} s scope
|
144
|
+
* @param {UsedNames} nameSet name set
|
145
|
+
* @param {TODO} scopeSet1 scope set 1
|
146
|
+
* @param {TODO} scopeSet2 scope set 2
|
147
|
+
*/
|
148
|
+
const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
|
149
|
+
let scope = s;
|
150
|
+
while (scope) {
|
151
|
+
if (scopeSet1.has(scope)) break;
|
152
|
+
if (scopeSet2.has(scope)) break;
|
153
|
+
scopeSet1.add(scope);
|
154
|
+
for (const variable of scope.variables) {
|
155
|
+
nameSet.add(variable.name);
|
156
|
+
}
|
157
|
+
scope = scope.upper;
|
158
|
+
}
|
159
|
+
};
|
160
|
+
|
161
|
+
const RESERVED_NAMES = new Set(
|
162
|
+
[
|
163
|
+
// internal names (should always be renamed)
|
164
|
+
DEFAULT_EXPORT,
|
165
|
+
NAMESPACE_OBJECT_EXPORT,
|
166
|
+
|
167
|
+
// keywords
|
168
|
+
"abstract,arguments,async,await,boolean,break,byte,case,catch,char,class,const,continue",
|
169
|
+
"debugger,default,delete,do,double,else,enum,eval,export,extends,false,final,finally,float",
|
170
|
+
"for,function,goto,if,implements,import,in,instanceof,int,interface,let,long,native,new,null",
|
171
|
+
"package,private,protected,public,return,short,static,super,switch,synchronized,this,throw",
|
172
|
+
"throws,transient,true,try,typeof,var,void,volatile,while,with,yield",
|
173
|
+
|
174
|
+
// commonjs/amd
|
175
|
+
"module,__dirname,__filename,exports,require,define",
|
176
|
+
|
177
|
+
// js globals
|
178
|
+
"Array,Date,eval,function,hasOwnProperty,Infinity,isFinite,isNaN,isPrototypeOf,length,Math",
|
179
|
+
"NaN,name,Number,Object,prototype,String,Symbol,toString,undefined,valueOf",
|
180
|
+
|
181
|
+
// browser globals
|
182
|
+
"alert,all,anchor,anchors,area,assign,blur,button,checkbox,clearInterval,clearTimeout",
|
183
|
+
"clientInformation,close,closed,confirm,constructor,crypto,decodeURI,decodeURIComponent",
|
184
|
+
"defaultStatus,document,element,elements,embed,embeds,encodeURI,encodeURIComponent,escape",
|
185
|
+
"event,fileUpload,focus,form,forms,frame,innerHeight,innerWidth,layer,layers,link,location",
|
186
|
+
"mimeTypes,navigate,navigator,frames,frameRate,hidden,history,image,images,offscreenBuffering",
|
187
|
+
"open,opener,option,outerHeight,outerWidth,packages,pageXOffset,pageYOffset,parent,parseFloat",
|
188
|
+
"parseInt,password,pkcs11,plugin,prompt,propertyIsEnum,radio,reset,screenX,screenY,scroll",
|
189
|
+
"secure,select,self,setInterval,setTimeout,status,submit,taint,text,textarea,top,unescape",
|
190
|
+
"untaint,window",
|
191
|
+
|
192
|
+
// window events
|
193
|
+
"onblur,onclick,onerror,onfocus,onkeydown,onkeypress,onkeyup,onmouseover,onload,onmouseup,onmousedown,onsubmit"
|
194
|
+
]
|
195
|
+
.join(",")
|
196
|
+
.split(",")
|
197
|
+
);
|
198
|
+
|
199
|
+
/**
|
200
|
+
* @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} usedNamesInScopeInfo used names in scope info
|
201
|
+
* @param {string} module module identifier
|
202
|
+
* @param {string} id export id
|
203
|
+
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
|
204
|
+
*/
|
205
|
+
const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
|
206
|
+
const key = `${module}-${id}`;
|
207
|
+
let info = usedNamesInScopeInfo.get(key);
|
208
|
+
if (info === undefined) {
|
209
|
+
info = {
|
210
|
+
usedNames: new Set(),
|
211
|
+
alreadyCheckedScopes: new Set()
|
212
|
+
};
|
213
|
+
usedNamesInScopeInfo.set(key, info);
|
214
|
+
}
|
215
|
+
return info;
|
216
|
+
};
|
217
|
+
|
218
|
+
module.exports = {
|
219
|
+
getUsedNamesInScopeInfo,
|
220
|
+
findNewName,
|
221
|
+
getAllReferences,
|
222
|
+
getPathInAst,
|
223
|
+
NAMESPACE_OBJECT_EXPORT,
|
224
|
+
DEFAULT_EXPORT,
|
225
|
+
RESERVED_NAMES,
|
226
|
+
addScopeSymbols
|
227
|
+
};
|
@@ -7,20 +7,33 @@
|
|
7
7
|
|
8
8
|
const memoize = require("./memoize");
|
9
9
|
|
10
|
+
/** @typedef {import("schema-utils/declarations/validate").ValidationErrorConfiguration} ValidationErrorConfiguration */
|
11
|
+
/** @typedef {import("./fs").JsonObject} JsonObject */
|
12
|
+
|
10
13
|
const getValidate = memoize(() => require("schema-utils").validate);
|
11
14
|
|
15
|
+
/**
|
16
|
+
* @template {object | object[]} T
|
17
|
+
* @param {(function(T): boolean) | undefined} check check
|
18
|
+
* @param {() => JsonObject} getSchema get schema fn
|
19
|
+
* @param {ValidationErrorConfiguration} options options
|
20
|
+
* @returns {function(T=): void} validate
|
21
|
+
*/
|
12
22
|
const createSchemaValidation = (check, getSchema, options) => {
|
13
23
|
getSchema = memoize(getSchema);
|
14
24
|
return value => {
|
15
|
-
if (check && !check(value)) {
|
16
|
-
getValidate()(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
if (check && !check(/** @type {T} */ (value))) {
|
26
|
+
getValidate()(
|
27
|
+
getSchema(),
|
28
|
+
/** @type {object | object[]} */
|
29
|
+
(value),
|
30
|
+
options
|
31
|
+
);
|
32
|
+
require("util").deprecate(
|
33
|
+
() => {},
|
34
|
+
"webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
|
35
|
+
"DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
|
36
|
+
)();
|
24
37
|
}
|
25
38
|
};
|
26
39
|
};
|
package/lib/util/deprecation.js
CHANGED
@@ -179,9 +179,21 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|
179
179
|
set[Symbol.isConcatSpreadable] = true;
|
180
180
|
};
|
181
181
|
|
182
|
+
/**
|
183
|
+
* @template T
|
184
|
+
* @param {string} name name
|
185
|
+
* @returns {{ new <T = any>(values?: readonly T[] | null): SetDeprecatedArray<T> }} SetDeprecatedArray
|
186
|
+
*/
|
182
187
|
module.exports.createArrayToSetDeprecationSet = name => {
|
183
188
|
let initialized = false;
|
189
|
+
|
190
|
+
/**
|
191
|
+
* @template T
|
192
|
+
*/
|
184
193
|
class SetDeprecatedArray extends Set {
|
194
|
+
/**
|
195
|
+
* @param {readonly T[] | null=} items items
|
196
|
+
*/
|
185
197
|
constructor(items) {
|
186
198
|
super(items);
|
187
199
|
if (!initialized) {
|
@@ -197,40 +209,77 @@ module.exports.createArrayToSetDeprecationSet = name => {
|
|
197
209
|
};
|
198
210
|
|
199
211
|
/**
|
200
|
-
* @
|
212
|
+
* @template {object} T
|
213
|
+
* @param {T} obj object
|
201
214
|
* @param {string} name property name
|
202
215
|
* @param {string} code deprecation code
|
203
216
|
* @param {string} note additional note
|
204
|
-
* @returns {Proxy<
|
217
|
+
* @returns {Proxy<T>} frozen object with deprecation when modifying
|
205
218
|
*/
|
206
219
|
module.exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => {
|
207
220
|
const message = `${name} will be frozen in future, all modifications are deprecated.${
|
208
221
|
note && `\n${note}`
|
209
222
|
}`;
|
210
|
-
return
|
211
|
-
|
212
|
-
(
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
223
|
+
return /** @type {Proxy<T>} */ (
|
224
|
+
new Proxy(/** @type {object} */ (obj), {
|
225
|
+
set: util.deprecate(
|
226
|
+
/**
|
227
|
+
* @param {T} target target
|
228
|
+
* @param {string | symbol} property property
|
229
|
+
* @param {any} value value
|
230
|
+
* @param {any} receiver receiver
|
231
|
+
* @returns {boolean} result
|
232
|
+
*/
|
233
|
+
(target, property, value, receiver) =>
|
234
|
+
Reflect.set(
|
235
|
+
/** @type {object} */ (target),
|
236
|
+
property,
|
237
|
+
value,
|
238
|
+
receiver
|
239
|
+
),
|
240
|
+
message,
|
241
|
+
code
|
242
|
+
),
|
243
|
+
defineProperty: util.deprecate(
|
244
|
+
/**
|
245
|
+
* @param {T} target target
|
246
|
+
* @param {string | symbol} property property
|
247
|
+
* @param {PropertyDescriptor} descriptor descriptor
|
248
|
+
* @returns {boolean} result
|
249
|
+
*/
|
250
|
+
(target, property, descriptor) =>
|
251
|
+
Reflect.defineProperty(
|
252
|
+
/** @type {object} */ (target),
|
253
|
+
property,
|
254
|
+
descriptor
|
255
|
+
),
|
256
|
+
message,
|
257
|
+
code
|
258
|
+
),
|
259
|
+
deleteProperty: util.deprecate(
|
260
|
+
/**
|
261
|
+
* @param {T} target target
|
262
|
+
* @param {string | symbol} property property
|
263
|
+
* @returns {boolean} result
|
264
|
+
*/
|
265
|
+
(target, property) =>
|
266
|
+
Reflect.deleteProperty(/** @type {object} */ (target), property),
|
267
|
+
message,
|
268
|
+
code
|
269
|
+
),
|
270
|
+
setPrototypeOf: util.deprecate(
|
271
|
+
/**
|
272
|
+
* @param {T} target target
|
273
|
+
* @param {object | null} proto proto
|
274
|
+
* @returns {boolean} result
|
275
|
+
*/
|
276
|
+
(target, proto) =>
|
277
|
+
Reflect.setPrototypeOf(/** @type {object} */ (target), proto),
|
278
|
+
message,
|
279
|
+
code
|
280
|
+
)
|
281
|
+
})
|
282
|
+
);
|
234
283
|
};
|
235
284
|
|
236
285
|
/**
|
@@ -263,7 +312,16 @@ const deprecateAllProperties = (obj, message, code) => {
|
|
263
312
|
enumerable: descriptor.enumerable,
|
264
313
|
get: util.deprecate(() => value, message, code),
|
265
314
|
set: descriptor.writable
|
266
|
-
? util.deprecate(
|
315
|
+
? util.deprecate(
|
316
|
+
/**
|
317
|
+
* @template T
|
318
|
+
* @param {T} v value
|
319
|
+
* @returns {T} result
|
320
|
+
*/
|
321
|
+
v => (value = v),
|
322
|
+
message,
|
323
|
+
code
|
324
|
+
)
|
267
325
|
: undefined
|
268
326
|
});
|
269
327
|
}
|
@@ -273,7 +331,7 @@ const deprecateAllProperties = (obj, message, code) => {
|
|
273
331
|
module.exports.deprecateAllProperties = deprecateAllProperties;
|
274
332
|
|
275
333
|
/**
|
276
|
-
* @template T
|
334
|
+
* @template {object} T
|
277
335
|
* @param {T} fakeHook fake hook implementation
|
278
336
|
* @param {string=} message deprecation message (not deprecated when unset)
|
279
337
|
* @param {string=} code deprecation code (not deprecated when unset)
|
package/lib/util/fs.js
CHANGED
@@ -84,8 +84,8 @@ const path = require("path");
|
|
84
84
|
|
85
85
|
/**
|
86
86
|
* @typedef {object} WatcherInfo
|
87
|
-
* @property {Set<string>} changes get current aggregated changes that have not yet send to callback
|
88
|
-
* @property {Set<string>} removals get current aggregated removals that have not yet send to callback
|
87
|
+
* @property {Set<string> | null} changes get current aggregated changes that have not yet send to callback
|
88
|
+
* @property {Set<string> | null} removals get current aggregated removals that have not yet send to callback
|
89
89
|
* @property {TimeInfoEntries} fileTimeInfoEntries get info about files
|
90
90
|
* @property {TimeInfoEntries} contextTimeInfoEntries get info about directories
|
91
91
|
*/
|
@@ -98,8 +98,8 @@ const path = require("path");
|
|
98
98
|
* @typedef {object} Watcher
|
99
99
|
* @property {function(): void} close closes the watcher and all underlying file watchers
|
100
100
|
* @property {function(): void} pause closes the watcher, but keeps underlying file watchers alive until the next watch call
|
101
|
-
* @property {function(): Changes=} getAggregatedChanges get current aggregated changes that have not yet send to callback
|
102
|
-
* @property {function(): Removals=} getAggregatedRemovals get current aggregated removals that have not yet send to callback
|
101
|
+
* @property {(function(): Changes | null)=} getAggregatedChanges get current aggregated changes that have not yet send to callback
|
102
|
+
* @property {(function(): Removals | null)=} getAggregatedRemovals get current aggregated removals that have not yet send to callback
|
103
103
|
* @property {function(): TimeInfoEntries} getFileTimeInfoEntries get info about files
|
104
104
|
* @property {function(): TimeInfoEntries} getContextTimeInfoEntries get info about directories
|
105
105
|
* @property {function(): WatcherInfo=} getInfo get info about timestamps and changes
|
@@ -372,7 +372,7 @@ const path = require("path");
|
|
372
372
|
* @typedef {object} StreamOptions
|
373
373
|
* @property {(string | undefined)=} flags
|
374
374
|
* @property {(BufferEncoding | undefined)} encoding
|
375
|
-
* @property {(number |
|
375
|
+
* @property {(number | EXPECTED_ANY | undefined)=} fd
|
376
376
|
* @property {(number | undefined)=} mode
|
377
377
|
* @property {(boolean | undefined)=} autoClose
|
378
378
|
* @property {(boolean | undefined)=} emitClose
|
@@ -382,12 +382,12 @@ const path = require("path");
|
|
382
382
|
|
383
383
|
/**
|
384
384
|
* @typedef {object} FSImplementation
|
385
|
-
* @property {((...args:
|
386
|
-
* @property {((...args:
|
385
|
+
* @property {((...args: EXPECTED_ANY[]) => EXPECTED_ANY)=} open
|
386
|
+
* @property {((...args: EXPECTED_ANY[]) => EXPECTED_ANY)=} close
|
387
387
|
*/
|
388
388
|
|
389
389
|
/**
|
390
|
-
* @typedef {FSImplementation & { write: (...args:
|
390
|
+
* @typedef {FSImplementation & { write: (...args: EXPECTED_ANY[]) => EXPECTED_ANY; close?: (...args: EXPECTED_ANY[]) => EXPECTED_ANY }} CreateWriteStreamFSImplementation
|
391
391
|
*/
|
392
392
|
|
393
393
|
/**
|
@@ -625,8 +625,8 @@ const lstatReadlinkAbsolute = (fs, p, callback) => {
|
|
625
625
|
// we retry 2 times to catch this case before throwing the error
|
626
626
|
return doStat();
|
627
627
|
}
|
628
|
-
if (err
|
629
|
-
const value = target.toString();
|
628
|
+
if (err) return callback(err);
|
629
|
+
const value = /** @type {string} */ (target).toString();
|
630
630
|
callback(null, join(fs, dirname(fs, p), value));
|
631
631
|
});
|
632
632
|
};
|