feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -19,7 +19,7 @@ const SortableSet = require("./SortableSet");
* @param {EntryOptions=} options optionally already received entry options
* @returns {RuntimeSpec} runtime
*/
exports.getEntryRuntime = (compilation, name, options) => {
module.exports.getEntryRuntime = (compilation, name, options) => {
let dependOn;
let runtime;
if (options) {
@@ -31,7 +31,7 @@ exports.getEntryRuntime = (compilation, name, options) => {
}
if (dependOn) {
/** @type {RuntimeSpec} */
let result = undefined;
let result;
const queue = new Set(dependOn);
for (const name of queue) {
const dep = compilation.entries.get(name);
@@ -46,9 +46,8 @@ exports.getEntryRuntime = (compilation, name, options) => {
}
}
return result || name;
} else {
return runtime || name;
}
return runtime || name;
};
/**
@@ -69,7 +68,7 @@ const forEachRuntime = (runtime, fn, deterministicOrder = false) => {
}
}
};
exports.forEachRuntime = forEachRuntime;
module.exports.forEachRuntime = forEachRuntime;
/**
* @template T
@@ -90,19 +89,19 @@ const getRuntimeKey = runtime => {
if (typeof runtime === "string") return runtime;
return runtime.getFromUnorderedCache(getRuntimesKey);
};
exports.getRuntimeKey = getRuntimeKey;
module.exports.getRuntimeKey = getRuntimeKey;
/**
* @param {string} key key of runtimes
* @returns {RuntimeSpec} runtime(s)
*/
const keyToRuntime = key => {
if (key === "*") return undefined;
if (key === "*") return;
const items = key.split("\n");
if (items.length === 1) return items[0];
return new SortableSet(items);
};
exports.keyToRuntime = keyToRuntime;
module.exports.keyToRuntime = keyToRuntime;
/**
* @template T
@@ -123,13 +122,13 @@ const runtimeToString = runtime => {
if (typeof runtime === "string") return runtime;
return runtime.getFromUnorderedCache(getRuntimesString);
};
exports.runtimeToString = runtimeToString;
module.exports.runtimeToString = runtimeToString;
/**
* @param {RuntimeCondition} runtimeCondition runtime condition
* @returns {string} readable version
*/
exports.runtimeConditionToString = runtimeCondition => {
module.exports.runtimeConditionToString = runtimeCondition => {
if (runtimeCondition === true) return "true";
if (runtimeCondition === false) return "false";
return runtimeToString(runtimeCondition);
@@ -152,40 +151,38 @@ const runtimeEqual = (a, b) => {
return false;
} else if (a.size !== b.size) {
return false;
} else {
a.sort();
b.sort();
const aIt = a[Symbol.iterator]();
const bIt = b[Symbol.iterator]();
for (;;) {
const aV = aIt.next();
if (aV.done) return true;
const bV = bIt.next();
if (aV.value !== bV.value) return false;
}
}
a.sort();
b.sort();
const aIt = a[Symbol.iterator]();
const bIt = b[Symbol.iterator]();
for (;;) {
const aV = aIt.next();
if (aV.done) return true;
const bV = bIt.next();
if (aV.value !== bV.value) return false;
}
};
exports.runtimeEqual = runtimeEqual;
module.exports.runtimeEqual = runtimeEqual;
/**
* @param {RuntimeSpec} a first
* @param {RuntimeSpec} b second
* @returns {-1|0|1} compare
*/
exports.compareRuntime = (a, b) => {
module.exports.compareRuntime = (a, b) => {
if (a === b) {
return 0;
} else if (a === undefined) {
return -1;
} else if (b === undefined) {
return 1;
} else {
const aKey = getRuntimeKey(a);
const bKey = getRuntimeKey(b);
if (aKey < bKey) return -1;
if (aKey > bKey) return 1;
return 0;
}
const aKey = getRuntimeKey(a);
const bKey = getRuntimeKey(b);
if (aKey < bKey) return -1;
if (aKey > bKey) return 1;
return 0;
};
/**
@@ -208,26 +205,23 @@ const mergeRuntime = (a, b) => {
return set;
} else if (b.has(a)) {
return b;
} else {
const set = new SortableSet(b);
set.add(a);
return set;
}
} else {
if (typeof b === "string") {
if (a.has(b)) return a;
const set = new SortableSet(a);
set.add(b);
return set;
} else {
const set = new SortableSet(a);
for (const item of b) set.add(item);
if (set.size === a.size) return a;
return set;
}
const set = new SortableSet(b);
set.add(a);
return set;
}
if (typeof b === "string") {
if (a.has(b)) return a;
const set = new SortableSet(a);
set.add(b);
return set;
}
const set = new SortableSet(a);
for (const item of b) set.add(item);
if (set.size === a.size) return a;
return set;
};
exports.mergeRuntime = mergeRuntime;
module.exports.mergeRuntime = mergeRuntime;
/**
* @param {RuntimeCondition} a first
@@ -235,12 +229,12 @@ exports.mergeRuntime = mergeRuntime;
* @param {RuntimeSpec} runtime full runtime
* @returns {RuntimeCondition} result
*/
exports.mergeRuntimeCondition = (a, b, runtime) => {
module.exports.mergeRuntimeCondition = (a, b, runtime) => {
if (a === false) return b;
if (b === false) return a;
if (a === true || b === true) return true;
const merged = mergeRuntime(a, b);
if (merged === undefined) return undefined;
if (merged === undefined) return;
if (typeof merged === "string") {
if (typeof runtime === "string" && merged === runtime) return true;
return merged;
@@ -256,10 +250,10 @@ exports.mergeRuntimeCondition = (a, b, runtime) => {
* @param {RuntimeSpec} runtime full runtime
* @returns {RuntimeSpec | true} result
*/
exports.mergeRuntimeConditionNonFalse = (a, b, runtime) => {
module.exports.mergeRuntimeConditionNonFalse = (a, b, runtime) => {
if (a === true || b === true) return true;
const merged = mergeRuntime(a, b);
if (merged === undefined) return undefined;
if (merged === undefined) return;
if (typeof merged === "string") {
if (typeof runtime === "string" && merged === runtime) return true;
return merged;
@@ -282,38 +276,34 @@ const mergeRuntimeOwned = (a, b) => {
} else if (a === undefined) {
if (typeof b === "string") {
return b;
} else {
return new SortableSet(b);
}
return new SortableSet(b);
} else if (typeof a === "string") {
if (typeof b === "string") {
const set = new SortableSet();
set.add(a);
set.add(b);
return set;
} else {
const set = new SortableSet(b);
set.add(a);
return set;
}
} else {
if (typeof b === "string") {
a.add(b);
return a;
} else {
for (const item of b) a.add(item);
return a;
}
const set = new SortableSet(b);
set.add(a);
return set;
}
if (typeof b === "string") {
a.add(b);
return a;
}
for (const item of b) a.add(item);
return a;
};
exports.mergeRuntimeOwned = mergeRuntimeOwned;
module.exports.mergeRuntimeOwned = mergeRuntimeOwned;
/**
* @param {RuntimeSpec} a first
* @param {RuntimeSpec} b second
* @returns {RuntimeSpec} merged
*/
exports.intersectRuntime = (a, b) => {
module.exports.intersectRuntime = (a, b) => {
if (a === undefined) {
return b;
} else if (b === undefined) {
@@ -322,26 +312,26 @@ exports.intersectRuntime = (a, b) => {
return a;
} else if (typeof a === "string") {
if (typeof b === "string") {
return undefined;
return;
} else if (b.has(a)) {
return a;
} else {
return undefined;
}
} else {
if (typeof b === "string") {
if (a.has(b)) return b;
return undefined;
} else {
const set = new SortableSet();
for (const item of b) {
if (a.has(item)) set.add(item);
}
if (set.size === 0) return undefined;
if (set.size === 1) for (const item of set) return item;
return set;
}
return;
}
if (typeof b === "string") {
if (a.has(b)) return b;
return;
}
const set = new SortableSet();
for (const item of b) {
if (a.has(item)) set.add(item);
}
if (set.size === 0) return;
if (set.size === 1) {
const [item] = set;
return item;
}
return set;
};
/**
@@ -351,42 +341,42 @@ exports.intersectRuntime = (a, b) => {
*/
const subtractRuntime = (a, b) => {
if (a === undefined) {
return undefined;
return;
} else if (b === undefined) {
return a;
} else if (a === b) {
return undefined;
return;
} else if (typeof a === "string") {
if (typeof b === "string") {
return a;
} else if (b.has(a)) {
return undefined;
} else {
return a;
}
} else {
if (typeof b === "string") {
if (!a.has(b)) return a;
if (a.size === 2) {
for (const item of a) {
if (item !== b) return item;
}
}
const set = new SortableSet(a);
set.delete(b);
return set;
} else {
const set = new SortableSet();
for (const item of a) {
if (!b.has(item)) set.add(item);
}
if (set.size === 0) return undefined;
if (set.size === 1) for (const item of set) return item;
return set;
return;
}
return a;
}
if (typeof b === "string") {
if (!a.has(b)) return a;
if (a.size === 2) {
for (const item of a) {
if (item !== b) return item;
}
}
const set = new SortableSet(a);
set.delete(b);
return set;
}
const set = new SortableSet();
for (const item of a) {
if (!b.has(item)) set.add(item);
}
if (set.size === 0) return;
if (set.size === 1) {
const [item] = set;
return item;
}
return set;
};
exports.subtractRuntime = subtractRuntime;
module.exports.subtractRuntime = subtractRuntime;
/**
* @param {RuntimeCondition} a first
@@ -394,7 +384,7 @@ exports.subtractRuntime = subtractRuntime;
* @param {RuntimeSpec} runtime runtime
* @returns {RuntimeCondition} result
*/
exports.subtractRuntimeCondition = (a, b, runtime) => {
module.exports.subtractRuntimeCondition = (a, b, runtime) => {
if (b === true) return false;
if (b === false) return a;
if (a === false) return false;
@@ -404,15 +394,15 @@ exports.subtractRuntimeCondition = (a, b, runtime) => {
/**
* @param {RuntimeSpec} runtime runtime
* @param {function(RuntimeSpec): boolean} filter filter function
* @param {function(RuntimeSpec=): boolean} filter filter function
* @returns {boolean | RuntimeSpec} true/false if filter is constant for all runtimes, otherwise runtimes that are active
*/
exports.filterRuntime = (runtime, filter) => {
if (runtime === undefined) return filter(undefined);
module.exports.filterRuntime = (runtime, filter) => {
if (runtime === undefined) return filter();
if (typeof runtime === "string") return filter(runtime);
let some = false;
let every = true;
let result = undefined;
let result;
for (const r of runtime) {
const v = filter(r);
if (v) {
@@ -456,7 +446,7 @@ class RuntimeSpecMap {
get(runtime) {
switch (this._mode) {
case 0:
return undefined;
return;
case 1:
return runtimeEqual(this._singleRuntime, runtime)
? this._singleValue
@@ -628,6 +618,9 @@ class RuntimeSpecMap {
}
}
/**
* @returns {IterableIterator<T>} values
*/
values() {
switch (this._mode) {
case 0:
@@ -640,12 +633,15 @@ class RuntimeSpecMap {
}
get size() {
if (/** @type {number} */ (this._mode) <= 1) return this._mode;
if (/** @type {number} */ (this._mode) <= 1) {
return /** @type {number} */ (this._mode);
}
return /** @type {Map<string, T>} */ (this._map).size;
}
}
exports.RuntimeSpecMap = RuntimeSpecMap;
module.exports.RuntimeSpecMap = RuntimeSpecMap;
class RuntimeSpecSet {
/**
@@ -676,6 +672,9 @@ class RuntimeSpecSet {
return this._map.has(getRuntimeKey(runtime));
}
/**
* @returns {IterableIterator<RuntimeSpec>} iterable iterator
*/
[Symbol.iterator]() {
return this._map.values();
}
@@ -685,4 +684,4 @@ class RuntimeSpecSet {
}
}
exports.RuntimeSpecSet = RuntimeSpecSet;
module.exports.RuntimeSpecSet = RuntimeSpecSet;