@rspack/core 1.0.0-alpha.4 → 1.0.0-beta.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/compiled/zod/index.d.ts +138 -52
- package/compiled/zod/index.js +300 -103
- package/compiled/zod/package.json +1 -1
- package/compiled/zod-validation-error/index.js +6 -6
- package/dist/Compilation.d.ts +21 -3
- package/dist/Compilation.js +64 -49
- package/dist/Compiler.js +28 -28
- package/dist/ErrorHelpers.js +2 -4
- package/dist/FileSystem.js +6 -6
- package/dist/Module.js +2 -6
- package/dist/ModuleTypeConstants.d.ts +45 -69
- package/dist/ModuleTypeConstants.js +24 -77
- package/dist/NormalModule.js +6 -6
- package/dist/Stats.js +4 -6
- package/dist/Template.d.ts +31 -147
- package/dist/Template.js +40 -236
- package/dist/Watching.js +2 -2
- package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
- package/dist/builtin-loader/lightningcss/index.js +175 -0
- package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
- package/dist/builtin-plugin/DefinePlugin.js +9 -13
- package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
- package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
- package/dist/builtin-plugin/SplitChunksPlugin.js +7 -17
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
- package/dist/builtin-plugin/base.js +1 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
- package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
- package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
- package/dist/builtin-plugin/css-extract/loader.js +6 -6
- package/dist/builtin-plugin/css-extract/utils.js +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.d.ts +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.js +1 -1
- package/dist/config/adapter.d.ts +1 -1
- package/dist/config/adapter.js +31 -30
- package/dist/config/adapterRuleUse.d.ts +5 -5
- package/dist/config/adapterRuleUse.js +23 -1
- package/dist/config/browserslistTargetHandler.d.ts +17 -15
- package/dist/config/browserslistTargetHandler.js +27 -33
- package/dist/config/defaults.js +27 -28
- package/dist/config/normalization.d.ts +2 -0
- package/dist/config/normalization.js +5 -5
- package/dist/config/target.d.ts +48 -109
- package/dist/config/target.js +50 -86
- package/dist/config/zod.d.ts +2398 -2212
- package/dist/config/zod.js +29 -19
- package/dist/container/ContainerPlugin.d.ts +7 -7
- package/dist/container/options.js +1 -1
- package/dist/exports.d.ts +4 -4
- package/dist/exports.js +2 -2
- package/dist/lib/CacheFacade.js +1 -0
- package/dist/lib/EntryOptionPlugin.js +2 -2
- package/dist/lib/ModuleFilenameHelpers.js +1 -3
- package/dist/lib/WebpackError.js +1 -1
- package/dist/lib/cache/mergeEtags.js +5 -11
- package/dist/lib/formatLocation.js +3 -5
- package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
- package/dist/loader-runner/LoaderLoadingError.js +3 -5
- package/dist/loader-runner/index.js +23 -25
- package/dist/loader-runner/loadLoader.d.ts +11 -2
- package/dist/loader-runner/loadLoader.js +18 -20
- package/dist/logging/createConsoleLogger.js +2 -6
- package/dist/logging/truncateArgs.js +5 -9
- package/dist/node/NodeWatchFileSystem.js +5 -5
- package/dist/node/nodeConsole.js +2 -4
- package/dist/rspack.js +6 -6
- package/dist/rspackOptionsApply.js +3 -3
- package/dist/stats/DefaultStatsFactoryPlugin.js +65 -20
- package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
- package/dist/stats/DefaultStatsPrinterPlugin.js +12 -17
- package/dist/stats/StatsFactory.js +13 -17
- package/dist/stats/StatsPrinter.js +7 -9
- package/dist/stats/statsFactoryUtils.d.ts +9 -10
- package/dist/util/AssetInfo.js +11 -7
- package/dist/util/SplitChunkSize.js +1 -1
- package/dist/util/bindingVersionCheck.js +6 -6
- package/dist/util/cleverMerge.d.ts +33 -57
- package/dist/util/cleverMerge.js +89 -145
- package/dist/util/comparators.js +3 -5
- package/dist/util/createHash.d.ts +4 -3
- package/dist/util/createHash.js +31 -45
- package/dist/util/fs.js +16 -20
- package/dist/util/hash/BatchedHash.d.ts +24 -9
- package/dist/util/hash/BatchedHash.js +16 -13
- package/dist/util/hash/index.d.ts +9 -9
- package/dist/util/hash/index.js +14 -11
- package/dist/util/hash/md4.d.ts +29 -2
- package/dist/util/hash/md4.js +7 -3
- package/dist/util/hash/wasm-hash.d.ts +52 -5
- package/dist/util/hash/wasm-hash.js +19 -22
- package/dist/util/hash/xxhash64.d.ts +29 -2
- package/dist/util/hash/xxhash64.js +7 -3
- package/dist/util/identifier.js +13 -19
- package/dist/util/index.js +1 -1
- package/dist/util/memoize.js +7 -9
- package/package.json +9 -8
- package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
export type ObjectParsedPropertyEntry = {
|
|
2
|
-
/**
|
|
3
|
-
* base value
|
|
4
|
-
*/
|
|
5
|
-
base: any | undefined;
|
|
6
|
-
/**
|
|
7
|
-
* the name of the selector property
|
|
8
|
-
*/
|
|
9
|
-
byProperty: string | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* value depending on selector property, merged with base
|
|
12
|
-
*/
|
|
13
|
-
byValues: Map<string, any>;
|
|
14
|
-
};
|
|
15
|
-
export type ParsedObject = {
|
|
16
|
-
/**
|
|
17
|
-
* static properties (key is property name)
|
|
18
|
-
*/
|
|
19
|
-
static: Map<string, ObjectParsedPropertyEntry>;
|
|
20
|
-
/**
|
|
21
|
-
* dynamic part
|
|
22
|
-
*/
|
|
23
|
-
dynamic: {
|
|
24
|
-
byProperty: string;
|
|
25
|
-
fn: Function;
|
|
26
|
-
} | undefined;
|
|
27
|
-
};
|
|
28
1
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/cleverMerge.js
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
34
9
|
*/
|
|
35
|
-
|
|
10
|
+
type Obj = Record<PropertyKey, any>;
|
|
11
|
+
export declare const DELETE: unique symbol;
|
|
36
12
|
/**
|
|
37
13
|
* Merges two given objects and caches the result to avoid computation if same objects passed as arguments again.
|
|
38
|
-
* @template T
|
|
39
|
-
* @template O
|
|
40
14
|
* @example
|
|
41
15
|
* // performs cleverMerge(first, second), stores the result in WeakMap and returns result
|
|
42
16
|
* cachedCleverMerge({a: 1}, {a: 2})
|
|
@@ -44,35 +18,37 @@ export function cachedSetProperty<T>(obj: Partial<T>, property: string, value: s
|
|
|
44
18
|
* // when same arguments passed, gets the result from WeakMap and returns it.
|
|
45
19
|
* cachedCleverMerge({a: 1}, {a: 2})
|
|
46
20
|
* {a: 2}
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
49
|
-
* @returns
|
|
21
|
+
* @param first first object
|
|
22
|
+
* @param second second object
|
|
23
|
+
* @returns merged object of first and second object
|
|
50
24
|
*/
|
|
51
|
-
export
|
|
25
|
+
export declare const cachedCleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
|
|
26
|
+
/**
|
|
27
|
+
* @param obj object
|
|
28
|
+
* @param property property
|
|
29
|
+
* @param value assignment value
|
|
30
|
+
* @returns new object
|
|
31
|
+
*/
|
|
32
|
+
export declare const cachedSetProperty: (obj: Obj, property: string, value: string | number | boolean) => Obj;
|
|
52
33
|
/**
|
|
53
34
|
* Merges two objects. Objects are deeply clever merged.
|
|
54
35
|
* Arrays might reference the old value with "...".
|
|
55
36
|
* Non-object values take preference over object values.
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
58
|
-
* @
|
|
59
|
-
* @param {O} second second object
|
|
60
|
-
* @returns {T & O | T | O} merged object of first and second object
|
|
37
|
+
* @param first first object
|
|
38
|
+
* @param second second object
|
|
39
|
+
* @returns merged object of first and second object
|
|
61
40
|
*/
|
|
62
|
-
export
|
|
41
|
+
export declare const cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
|
|
63
42
|
/**
|
|
64
|
-
* @
|
|
65
|
-
* @
|
|
66
|
-
* @param {T} obj the object
|
|
67
|
-
* @param {P} byProperty the by description
|
|
68
|
-
* @param {...any} values values
|
|
69
|
-
* @returns {Omit<T, P>|undefined} object with merged byProperty
|
|
43
|
+
* @param obj the object
|
|
44
|
+
* @returns the object without operations like "..." or DELETE
|
|
70
45
|
*/
|
|
71
|
-
export
|
|
46
|
+
export declare const removeOperations: <O extends Obj>(obj: O) => O;
|
|
72
47
|
/**
|
|
73
|
-
* @
|
|
74
|
-
* @param
|
|
75
|
-
* @
|
|
48
|
+
* @param obj the object
|
|
49
|
+
* @param byProperty the by description
|
|
50
|
+
* @param values values
|
|
51
|
+
* @returns object with merged byProperty
|
|
76
52
|
*/
|
|
77
|
-
export
|
|
78
|
-
export
|
|
53
|
+
export declare const resolveByProperty: <O extends Obj | null, P extends PropertyKey>(obj: O, byProperty: P, ...values: any[]) => Omit<O, P> | undefined;
|
|
54
|
+
export {};
|
package/dist/util/cleverMerge.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The following code is modified based on
|
|
3
|
-
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/cleverMerge.js
|
|
4
|
-
*
|
|
5
|
-
* MIT Licensed
|
|
6
|
-
* Author Tobias Koppers @sokra
|
|
7
|
-
* Copyright (c) JS Foundation and other contributors
|
|
8
|
-
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
9
|
-
*/
|
|
10
1
|
"use strict";
|
|
11
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveByProperty = exports.removeOperations = exports.cleverMerge = exports.cachedSetProperty = exports.cachedCleverMerge = exports.DELETE = void 0;
|
|
12
4
|
const mergeCache = new WeakMap();
|
|
13
|
-
/** @type {WeakMap<object, Map<string, Map<string|number|boolean, object>>>} */
|
|
14
5
|
const setPropertyCache = new WeakMap();
|
|
15
|
-
|
|
6
|
+
exports.DELETE = Symbol("DELETE");
|
|
16
7
|
const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
|
|
17
8
|
/**
|
|
18
9
|
* Merges two given objects and caches the result to avoid computation if same objects passed as arguments again.
|
|
19
|
-
* @template T
|
|
20
|
-
* @template O
|
|
21
10
|
* @example
|
|
22
11
|
* // performs cleverMerge(first, second), stores the result in WeakMap and returns result
|
|
23
12
|
* cachedCleverMerge({a: 1}, {a: 2})
|
|
@@ -25,9 +14,9 @@ const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
|
|
|
25
14
|
* // when same arguments passed, gets the result from WeakMap and returns it.
|
|
26
15
|
* cachedCleverMerge({a: 1}, {a: 2})
|
|
27
16
|
* {a: 2}
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @returns
|
|
17
|
+
* @param first first object
|
|
18
|
+
* @param second second object
|
|
19
|
+
* @returns merged object of first and second object
|
|
31
20
|
*/
|
|
32
21
|
const cachedCleverMerge = (first, second) => {
|
|
33
22
|
if (second === undefined)
|
|
@@ -44,20 +33,18 @@ const cachedCleverMerge = (first, second) => {
|
|
|
44
33
|
mergeCache.set(first, innerCache);
|
|
45
34
|
}
|
|
46
35
|
const prevMerge = innerCache.get(second);
|
|
47
|
-
// @ts-expect-error
|
|
48
36
|
if (prevMerge !== undefined)
|
|
49
37
|
return prevMerge;
|
|
50
38
|
const newMerge = _cleverMerge(first, second, true);
|
|
51
39
|
innerCache.set(second, newMerge);
|
|
52
|
-
// @ts-expect-error
|
|
53
40
|
return newMerge;
|
|
54
41
|
};
|
|
42
|
+
exports.cachedCleverMerge = cachedCleverMerge;
|
|
55
43
|
/**
|
|
56
|
-
* @
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
* @
|
|
60
|
-
* @returns {T} new object
|
|
44
|
+
* @param obj object
|
|
45
|
+
* @param property property
|
|
46
|
+
* @param value assignment value
|
|
47
|
+
* @returns new object
|
|
61
48
|
*/
|
|
62
49
|
const cachedSetProperty = (obj, property, value) => {
|
|
63
50
|
let mapByProperty = setPropertyCache.get(obj);
|
|
@@ -71,7 +58,6 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
71
58
|
mapByProperty.set(property, mapByValue);
|
|
72
59
|
}
|
|
73
60
|
let result = mapByValue.get(value);
|
|
74
|
-
// @ts-expect-error
|
|
75
61
|
if (result)
|
|
76
62
|
return result;
|
|
77
63
|
result = {
|
|
@@ -79,27 +65,15 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
79
65
|
[property]: value
|
|
80
66
|
};
|
|
81
67
|
mapByValue.set(value, result);
|
|
82
|
-
// @ts-expect-error
|
|
83
68
|
return result;
|
|
84
69
|
};
|
|
85
|
-
|
|
86
|
-
* @typedef {Object} ObjectParsedPropertyEntry
|
|
87
|
-
* @property {any | undefined} base base value
|
|
88
|
-
* @property {string | undefined} byProperty the name of the selector property
|
|
89
|
-
* @property {Map<string, any>} byValues value depending on selector property, merged with base
|
|
90
|
-
*/
|
|
91
|
-
/**
|
|
92
|
-
* @typedef {Object} ParsedObject
|
|
93
|
-
* @property {Map<string, ObjectParsedPropertyEntry>} static static properties (key is property name)
|
|
94
|
-
* @property {{ byProperty: string, fn: Function } | undefined} dynamic dynamic part
|
|
95
|
-
*/
|
|
96
|
-
/** @type {WeakMap<object, ParsedObject>} */
|
|
70
|
+
exports.cachedSetProperty = cachedSetProperty;
|
|
97
71
|
const parseCache = new WeakMap();
|
|
98
72
|
/**
|
|
99
|
-
* @param
|
|
100
|
-
* @returns
|
|
73
|
+
* @param obj the object
|
|
74
|
+
* @returns parsed object
|
|
101
75
|
*/
|
|
102
|
-
const cachedParseObject = obj => {
|
|
76
|
+
const cachedParseObject = (obj) => {
|
|
103
77
|
const entry = parseCache.get(obj);
|
|
104
78
|
if (entry !== undefined)
|
|
105
79
|
return entry;
|
|
@@ -111,18 +85,17 @@ const cachedParseObject = obj => {
|
|
|
111
85
|
* @param {object} obj the object
|
|
112
86
|
* @returns {ParsedObject} parsed object
|
|
113
87
|
*/
|
|
114
|
-
const parseObject = obj => {
|
|
88
|
+
const parseObject = (obj) => {
|
|
115
89
|
const info = new Map();
|
|
116
90
|
let dynamicInfo;
|
|
117
|
-
|
|
118
|
-
const getInfo = p => {
|
|
91
|
+
const getInfo = (p) => {
|
|
119
92
|
const entry = info.get(p);
|
|
120
93
|
if (entry !== undefined)
|
|
121
94
|
return entry;
|
|
122
95
|
const newEntry = {
|
|
123
96
|
base: undefined,
|
|
124
97
|
byProperty: undefined,
|
|
125
|
-
byValues:
|
|
98
|
+
byValues: new Map()
|
|
126
99
|
};
|
|
127
100
|
info.set(p, newEntry);
|
|
128
101
|
return newEntry;
|
|
@@ -130,7 +103,6 @@ const parseObject = obj => {
|
|
|
130
103
|
for (const key of Object.keys(obj)) {
|
|
131
104
|
if (key.startsWith("by")) {
|
|
132
105
|
const byProperty = key;
|
|
133
|
-
// @ts-expect-error
|
|
134
106
|
const byObj = obj[byProperty];
|
|
135
107
|
if (typeof byObj === "object") {
|
|
136
108
|
for (const byValue of Object.keys(byObj)) {
|
|
@@ -139,7 +111,6 @@ const parseObject = obj => {
|
|
|
139
111
|
const entry = getInfo(key);
|
|
140
112
|
if (entry.byProperty === undefined) {
|
|
141
113
|
entry.byProperty = byProperty;
|
|
142
|
-
entry.byValues = new Map();
|
|
143
114
|
}
|
|
144
115
|
else if (entry.byProperty !== byProperty) {
|
|
145
116
|
throw new Error(`${byProperty} and ${entry.byProperty} for a single property is not supported`);
|
|
@@ -167,13 +138,11 @@ const parseObject = obj => {
|
|
|
167
138
|
}
|
|
168
139
|
else {
|
|
169
140
|
const entry = getInfo(key);
|
|
170
|
-
// @ts-expect-error
|
|
171
141
|
entry.base = obj[key];
|
|
172
142
|
}
|
|
173
143
|
}
|
|
174
144
|
else {
|
|
175
145
|
const entry = getInfo(key);
|
|
176
|
-
// @ts-expect-error
|
|
177
146
|
entry.base = obj[key];
|
|
178
147
|
}
|
|
179
148
|
}
|
|
@@ -183,16 +152,15 @@ const parseObject = obj => {
|
|
|
183
152
|
};
|
|
184
153
|
};
|
|
185
154
|
/**
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
188
|
-
* @returns
|
|
155
|
+
* @param info static properties (key is property name)
|
|
156
|
+
* @param dynamicInfo dynamic part
|
|
157
|
+
* @returns the object
|
|
189
158
|
*/
|
|
190
159
|
const serializeObject = (info, dynamicInfo) => {
|
|
191
160
|
const obj = {};
|
|
192
161
|
// Setup byProperty structure
|
|
193
162
|
for (const entry of info.values()) {
|
|
194
163
|
if (entry.byProperty !== undefined) {
|
|
195
|
-
// @ts-expect-error
|
|
196
164
|
const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {});
|
|
197
165
|
for (const byValue of entry.byValues.keys()) {
|
|
198
166
|
byObj[byValue] = byObj[byValue] || {};
|
|
@@ -201,12 +169,10 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
201
169
|
}
|
|
202
170
|
for (const [key, entry] of info) {
|
|
203
171
|
if (entry.base !== undefined) {
|
|
204
|
-
// @ts-expect-error
|
|
205
172
|
obj[key] = entry.base;
|
|
206
173
|
}
|
|
207
174
|
// Fill byProperty structure
|
|
208
175
|
if (entry.byProperty !== undefined) {
|
|
209
|
-
// @ts-expect-error
|
|
210
176
|
const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {});
|
|
211
177
|
for (const byValue of Object.keys(byObj)) {
|
|
212
178
|
const value = getFromByValues(entry.byValues, byValue);
|
|
@@ -216,7 +182,6 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
216
182
|
}
|
|
217
183
|
}
|
|
218
184
|
if (dynamicInfo !== undefined) {
|
|
219
|
-
// @ts-expect-error
|
|
220
185
|
obj[dynamicInfo.byProperty] = dynamicInfo.fn;
|
|
221
186
|
}
|
|
222
187
|
return obj;
|
|
@@ -227,22 +192,22 @@ const VALUE_TYPE_ARRAY_EXTEND = 2;
|
|
|
227
192
|
const VALUE_TYPE_OBJECT = 3;
|
|
228
193
|
const VALUE_TYPE_DELETE = 4;
|
|
229
194
|
/**
|
|
230
|
-
* @param
|
|
195
|
+
* @param value a single value
|
|
231
196
|
* @returns {VALUE_TYPE_UNDEFINED | VALUE_TYPE_ATOM | VALUE_TYPE_ARRAY_EXTEND | VALUE_TYPE_OBJECT | VALUE_TYPE_DELETE} value type
|
|
232
197
|
*/
|
|
233
|
-
const getValueType = value => {
|
|
198
|
+
const getValueType = (value) => {
|
|
234
199
|
if (value === undefined) {
|
|
235
200
|
return VALUE_TYPE_UNDEFINED;
|
|
236
201
|
}
|
|
237
|
-
|
|
202
|
+
if (value === exports.DELETE) {
|
|
238
203
|
return VALUE_TYPE_DELETE;
|
|
239
204
|
}
|
|
240
|
-
|
|
205
|
+
if (Array.isArray(value)) {
|
|
241
206
|
if (value.lastIndexOf("...") !== -1)
|
|
242
207
|
return VALUE_TYPE_ARRAY_EXTEND;
|
|
243
208
|
return VALUE_TYPE_ATOM;
|
|
244
209
|
}
|
|
245
|
-
|
|
210
|
+
if (typeof value === "object" &&
|
|
246
211
|
value !== null &&
|
|
247
212
|
(!value.constructor || value.constructor === Object)) {
|
|
248
213
|
return VALUE_TYPE_OBJECT;
|
|
@@ -253,11 +218,9 @@ const getValueType = value => {
|
|
|
253
218
|
* Merges two objects. Objects are deeply clever merged.
|
|
254
219
|
* Arrays might reference the old value with "...".
|
|
255
220
|
* Non-object values take preference over object values.
|
|
256
|
-
* @
|
|
257
|
-
* @
|
|
258
|
-
* @
|
|
259
|
-
* @param {O} second second object
|
|
260
|
-
* @returns {T & O | T | O} merged object of first and second object
|
|
221
|
+
* @param first first object
|
|
222
|
+
* @param second second object
|
|
223
|
+
* @returns merged object of first and second object
|
|
261
224
|
*/
|
|
262
225
|
const cleverMerge = (first, second) => {
|
|
263
226
|
if (second === undefined)
|
|
@@ -268,15 +231,15 @@ const cleverMerge = (first, second) => {
|
|
|
268
231
|
return second;
|
|
269
232
|
if (typeof first !== "object" || first === null)
|
|
270
233
|
return first;
|
|
271
|
-
// @ts-expect-error
|
|
272
234
|
return _cleverMerge(first, second, false);
|
|
273
235
|
};
|
|
236
|
+
exports.cleverMerge = cleverMerge;
|
|
274
237
|
/**
|
|
275
238
|
* Merges two objects. Objects are deeply clever merged.
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
279
|
-
* @returns
|
|
239
|
+
* @param first first object
|
|
240
|
+
* @param second second object
|
|
241
|
+
* @param internalCaching should parsing of objects and nested merges be cached
|
|
242
|
+
* @returns merged object of first and second object
|
|
280
243
|
*/
|
|
281
244
|
const _cleverMerge = (first, second, internalCaching = false) => {
|
|
282
245
|
const firstObject = internalCaching
|
|
@@ -286,22 +249,19 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
286
249
|
// If the first argument has a dynamic part we modify the dynamic part to merge the second argument
|
|
287
250
|
if (firstDynamicInfo !== undefined) {
|
|
288
251
|
let { byProperty, fn } = firstDynamicInfo;
|
|
289
|
-
// @ts-expect-error
|
|
290
252
|
const fnInfo = fn[DYNAMIC_INFO];
|
|
291
253
|
if (fnInfo) {
|
|
292
254
|
second = internalCaching
|
|
293
|
-
? cachedCleverMerge(fnInfo[1], second)
|
|
294
|
-
: cleverMerge(fnInfo[1], second);
|
|
255
|
+
? (0, exports.cachedCleverMerge)(fnInfo[1], second)
|
|
256
|
+
: (0, exports.cleverMerge)(fnInfo[1], second);
|
|
295
257
|
fn = fnInfo[0];
|
|
296
258
|
}
|
|
297
|
-
// @ts-expect-error
|
|
298
259
|
const newFn = (...args) => {
|
|
299
260
|
const fnResult = fn(...args);
|
|
300
261
|
return internalCaching
|
|
301
|
-
? cachedCleverMerge(fnResult, second)
|
|
302
|
-
: cleverMerge(fnResult, second);
|
|
262
|
+
? (0, exports.cachedCleverMerge)(fnResult, second)
|
|
263
|
+
: (0, exports.cleverMerge)(fnResult, second);
|
|
303
264
|
};
|
|
304
|
-
// @ts-expect-error
|
|
305
265
|
newFn[DYNAMIC_INFO] = [fn, second];
|
|
306
266
|
return serializeObject(firstObject.static, { byProperty, fn: newFn });
|
|
307
267
|
}
|
|
@@ -310,7 +270,6 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
310
270
|
? cachedParseObject(second)
|
|
311
271
|
: parseObject(second);
|
|
312
272
|
const { static: secondInfo, dynamic: secondDynamicInfo } = secondObject;
|
|
313
|
-
/** @type {Map<string, ObjectParsedPropertyEntry>} */
|
|
314
273
|
const resultInfo = new Map();
|
|
315
274
|
for (const [key, firstEntry] of firstInfo) {
|
|
316
275
|
const secondEntry = secondInfo.get(key);
|
|
@@ -327,10 +286,10 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
327
286
|
return serializeObject(resultInfo, secondDynamicInfo);
|
|
328
287
|
};
|
|
329
288
|
/**
|
|
330
|
-
* @param
|
|
331
|
-
* @param
|
|
332
|
-
* @param
|
|
333
|
-
* @returns
|
|
289
|
+
* @param firstEntry a
|
|
290
|
+
* @param secondEntry b
|
|
291
|
+
* @param internalCaching should parsing of objects and nested merges be cached
|
|
292
|
+
* @returns new entry
|
|
334
293
|
*/
|
|
335
294
|
const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
336
295
|
switch (getValueType(secondEntry.base)) {
|
|
@@ -349,23 +308,21 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
349
308
|
byValues: secondEntry.byValues
|
|
350
309
|
};
|
|
351
310
|
}
|
|
352
|
-
|
|
311
|
+
if (firstEntry.byProperty !== secondEntry.byProperty) {
|
|
353
312
|
throw new Error(`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`);
|
|
354
313
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
newByValues.set(key, mergeSingleValue(firstValue, value, internalCaching));
|
|
362
|
-
}
|
|
363
|
-
return {
|
|
364
|
-
base: firstEntry.base,
|
|
365
|
-
byProperty: firstEntry.byProperty,
|
|
366
|
-
byValues: newByValues
|
|
367
|
-
};
|
|
314
|
+
// = first.base + (first.byProperty + second.byProperty)
|
|
315
|
+
// need to merge first and second byValues
|
|
316
|
+
const newByValues = new Map(firstEntry.byValues);
|
|
317
|
+
for (const [key, value] of secondEntry.byValues) {
|
|
318
|
+
const firstValue = getFromByValues(firstEntry.byValues, key);
|
|
319
|
+
newByValues.set(key, mergeSingleValue(firstValue, value, internalCaching));
|
|
368
320
|
}
|
|
321
|
+
return {
|
|
322
|
+
base: firstEntry.base,
|
|
323
|
+
byProperty: firstEntry.byProperty,
|
|
324
|
+
byValues: newByValues
|
|
325
|
+
};
|
|
369
326
|
default: {
|
|
370
327
|
if (!firstEntry.byProperty) {
|
|
371
328
|
// The simple case
|
|
@@ -402,7 +359,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
402
359
|
byValues: intermediateByValues
|
|
403
360
|
};
|
|
404
361
|
}
|
|
405
|
-
|
|
362
|
+
if (firstEntry.byProperty !== secondEntry.byProperty) {
|
|
406
363
|
throw new Error(`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`);
|
|
407
364
|
}
|
|
408
365
|
const newByValues = new Map(intermediateByValues);
|
|
@@ -419,9 +376,9 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
419
376
|
}
|
|
420
377
|
};
|
|
421
378
|
/**
|
|
422
|
-
* @param
|
|
423
|
-
* @param
|
|
424
|
-
* @returns
|
|
379
|
+
* @param byValues all values
|
|
380
|
+
* @param key value of the selector
|
|
381
|
+
* @returns value
|
|
425
382
|
*/
|
|
426
383
|
const getFromByValues = (byValues, key) => {
|
|
427
384
|
if (key !== "default" && byValues.has(key)) {
|
|
@@ -430,10 +387,10 @@ const getFromByValues = (byValues, key) => {
|
|
|
430
387
|
return byValues.get("default");
|
|
431
388
|
};
|
|
432
389
|
/**
|
|
433
|
-
* @param
|
|
434
|
-
* @param
|
|
435
|
-
* @param
|
|
436
|
-
* @returns
|
|
390
|
+
* @param a value
|
|
391
|
+
* @param b value
|
|
392
|
+
* @param internalCaching should parsing of objects and nested merges be cached
|
|
393
|
+
* @returns value
|
|
437
394
|
*/
|
|
438
395
|
const mergeSingleValue = (a, b, internalCaching) => {
|
|
439
396
|
const bType = getValueType(b);
|
|
@@ -446,8 +403,8 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
|
446
403
|
return aType !== VALUE_TYPE_OBJECT
|
|
447
404
|
? b
|
|
448
405
|
: internalCaching
|
|
449
|
-
? cachedCleverMerge(a, b)
|
|
450
|
-
: cleverMerge(a, b);
|
|
406
|
+
? (0, exports.cachedCleverMerge)(a, b)
|
|
407
|
+
: (0, exports.cleverMerge)(a, b);
|
|
451
408
|
}
|
|
452
409
|
case VALUE_TYPE_UNDEFINED:
|
|
453
410
|
return a;
|
|
@@ -460,8 +417,7 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
|
460
417
|
case VALUE_TYPE_UNDEFINED:
|
|
461
418
|
return b;
|
|
462
419
|
case VALUE_TYPE_DELETE:
|
|
463
|
-
|
|
464
|
-
return b.filter(item => item !== "...");
|
|
420
|
+
return b.filter((item) => item !== "...");
|
|
465
421
|
case VALUE_TYPE_ARRAY_EXTEND: {
|
|
466
422
|
const newArray = [];
|
|
467
423
|
for (const item of b) {
|
|
@@ -477,8 +433,7 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
|
477
433
|
return newArray;
|
|
478
434
|
}
|
|
479
435
|
case VALUE_TYPE_OBJECT:
|
|
480
|
-
|
|
481
|
-
return b.map(item => (item === "..." ? a : item));
|
|
436
|
+
return b.map((item) => (item === "..." ? a : item));
|
|
482
437
|
default:
|
|
483
438
|
throw new Error("Not implemented");
|
|
484
439
|
}
|
|
@@ -487,15 +442,12 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
|
487
442
|
}
|
|
488
443
|
};
|
|
489
444
|
/**
|
|
490
|
-
* @
|
|
491
|
-
* @
|
|
492
|
-
* @returns {T} the object without operations like "..." or DELETE
|
|
445
|
+
* @param obj the object
|
|
446
|
+
* @returns the object without operations like "..." or DELETE
|
|
493
447
|
*/
|
|
494
|
-
const removeOperations = obj => {
|
|
495
|
-
const newObj =
|
|
496
|
-
// @ts-expect-error
|
|
448
|
+
const removeOperations = (obj) => {
|
|
449
|
+
const newObj = {};
|
|
497
450
|
for (const key of Object.keys(obj)) {
|
|
498
|
-
// @ts-expect-error
|
|
499
451
|
const value = obj[key];
|
|
500
452
|
const type = getValueType(value);
|
|
501
453
|
switch (type) {
|
|
@@ -503,56 +455,48 @@ const removeOperations = obj => {
|
|
|
503
455
|
case VALUE_TYPE_DELETE:
|
|
504
456
|
break;
|
|
505
457
|
case VALUE_TYPE_OBJECT:
|
|
506
|
-
|
|
507
|
-
newObj[key] = removeOperations(value);
|
|
458
|
+
newObj[key] = (0, exports.removeOperations)(value);
|
|
508
459
|
break;
|
|
509
460
|
case VALUE_TYPE_ARRAY_EXTEND:
|
|
510
|
-
// @ts-expect-error
|
|
511
461
|
newObj[key] = value.filter(i => i !== "...");
|
|
512
462
|
break;
|
|
513
463
|
default:
|
|
514
|
-
// @ts-expect-error
|
|
515
464
|
newObj[key] = value;
|
|
516
465
|
break;
|
|
517
466
|
}
|
|
518
467
|
}
|
|
519
468
|
return newObj;
|
|
520
469
|
};
|
|
470
|
+
exports.removeOperations = removeOperations;
|
|
521
471
|
/**
|
|
522
|
-
* @
|
|
523
|
-
* @
|
|
524
|
-
* @param
|
|
525
|
-
* @
|
|
526
|
-
* @param {...any} values values
|
|
527
|
-
* @returns {Omit<T, P>|undefined} object with merged byProperty
|
|
472
|
+
* @param obj the object
|
|
473
|
+
* @param byProperty the by description
|
|
474
|
+
* @param values values
|
|
475
|
+
* @returns object with merged byProperty
|
|
528
476
|
*/
|
|
529
477
|
const resolveByProperty = (obj, byProperty, ...values) => {
|
|
530
|
-
if (
|
|
478
|
+
if (!isPropertyInObject(obj, byProperty)) {
|
|
531
479
|
return obj;
|
|
532
480
|
}
|
|
533
|
-
const { [byProperty]: _byValue, ..._remaining } =
|
|
534
|
-
const remaining =
|
|
535
|
-
const byValue =
|
|
481
|
+
const { [byProperty]: _byValue, ..._remaining } = obj;
|
|
482
|
+
const remaining = _remaining;
|
|
483
|
+
const byValue = _byValue;
|
|
536
484
|
if (typeof byValue === "object") {
|
|
537
485
|
const key = values[0];
|
|
538
486
|
if (key in byValue) {
|
|
539
|
-
return cachedCleverMerge(remaining, byValue[key]);
|
|
540
|
-
}
|
|
541
|
-
else if ("default" in byValue) {
|
|
542
|
-
return cachedCleverMerge(remaining, byValue.default);
|
|
487
|
+
return (0, exports.cachedCleverMerge)(remaining, byValue[key]);
|
|
543
488
|
}
|
|
544
|
-
|
|
545
|
-
return
|
|
489
|
+
if ("default" in byValue) {
|
|
490
|
+
return (0, exports.cachedCleverMerge)(remaining, byValue.default);
|
|
546
491
|
}
|
|
492
|
+
return remaining;
|
|
547
493
|
}
|
|
548
|
-
|
|
494
|
+
if (typeof byValue === "function") {
|
|
549
495
|
const result = byValue.apply(null, values);
|
|
550
|
-
return cachedCleverMerge(remaining, resolveByProperty(result, byProperty, ...values));
|
|
496
|
+
return (0, exports.cachedCleverMerge)(remaining, (0, exports.resolveByProperty)(result, byProperty, ...values));
|
|
551
497
|
}
|
|
552
498
|
};
|
|
553
|
-
exports.cachedSetProperty = cachedSetProperty;
|
|
554
|
-
exports.cachedCleverMerge = cachedCleverMerge;
|
|
555
|
-
exports.cleverMerge = cleverMerge;
|
|
556
499
|
exports.resolveByProperty = resolveByProperty;
|
|
557
|
-
|
|
558
|
-
|
|
500
|
+
function isPropertyInObject(obj, property) {
|
|
501
|
+
return typeof obj === "object" && obj !== null && property in obj;
|
|
502
|
+
}
|
package/dist/util/comparators.js
CHANGED
|
@@ -86,12 +86,10 @@ const compareSelect = (getter, comparator) => {
|
|
|
86
86
|
}
|
|
87
87
|
return -1;
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return 1;
|
|
92
|
-
}
|
|
93
|
-
return 0;
|
|
89
|
+
if (bValue !== undefined && bValue !== null) {
|
|
90
|
+
return 1;
|
|
94
91
|
}
|
|
92
|
+
return 0;
|
|
95
93
|
};
|
|
96
94
|
compareSelectCache.set(getter, comparator, result);
|
|
97
95
|
return result;
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* Copyright (c) JS Foundation and other contributors
|
|
8
8
|
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
9
9
|
*/
|
|
10
|
+
import Hash from "./hash";
|
|
10
11
|
/**
|
|
11
12
|
* Creates a hash by name or function
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
13
|
+
* @param algorithm the algorithm name or a constructor creating a hash
|
|
14
|
+
* @returns the hash
|
|
14
15
|
*/
|
|
15
|
-
export declare const createHash: (algorithm:
|
|
16
|
+
export declare const createHash: (algorithm: "debug" | "xxhash64" | "md4" | "native-md4" | (string & {}) | (new () => Hash)) => Hash;
|