Add JS-CATCH-FALLBACK-01 rule and update npm packages

Add PHP-ALIAS-01 rule: prohibit field aliasing in serialization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-23 07:36:18 +00:00
parent 3cc590186a
commit 3ce82a924a
1256 changed files with 6491 additions and 3989 deletions

0
node_modules/webpack/lib/util/ArrayHelpers.js generated vendored Executable file → Normal file
View File

0
node_modules/webpack/lib/util/ArrayQueue.js generated vendored Executable file → Normal file
View File

0
node_modules/webpack/lib/util/AsyncQueue.js generated vendored Executable file → Normal file
View File

View File

@@ -36,7 +36,7 @@
*/
class StringXor {
constructor() {
/** @type {Buffer|undefined} */
/** @type {Buffer | undefined} */
this._value = undefined;
}

View File

@@ -5,7 +5,7 @@
"use strict";
/** @typedef {(error: Error|null, result?: Buffer) => void} ErrorFirstCallback */
/** @typedef {(error: Error | null, result?: Buffer) => void} ErrorFirstCallback */
const backSlashCharCode = "\\".charCodeAt(0);
const slashCharCode = "/".charCodeAt(0);
@@ -25,7 +25,7 @@ const queryCharCode = "?".charCodeAt(0);
* e.g. Absolute specifiers like 'file:///user/webpack/index.js'
* https://tools.ietf.org/html/rfc3986#section-3.1
* @param {string} specifier specifier
* @returns {string|undefined} scheme if absolute URL specifier provided
* @returns {string | undefined} scheme if absolute URL specifier provided
*/
function getScheme(specifier) {
const start = specifier.charCodeAt(0);

4
node_modules/webpack/lib/util/binarySearchBounds.js generated vendored Executable file → Normal file
View File

@@ -8,8 +8,8 @@
/* cspell:disable-next-line */
// Refactor: Peter Somogyvari @petermetz
/** @typedef {">=" | "<=" | "<" | ">" | "-" } BinarySearchPredicate */
/** @typedef {"GE" | "GT" | "LT" | "LE" | "EQ" } SearchPredicateSuffix */
/** @typedef {">=" | "<=" | "<" | ">" | "-"} BinarySearchPredicate */
/** @typedef {"GE" | "GT" | "LT" | "LE" | "EQ"} SearchPredicateSuffix */
/**
* Helper function for compiling binary search functions.

0
node_modules/webpack/lib/util/chainedImports.js generated vendored Executable file → Normal file
View File

0
node_modules/webpack/lib/util/cleverMerge.js generated vendored Executable file → Normal file
View File

127
node_modules/webpack/lib/util/comparators.js generated vendored Executable file → Normal file
View File

@@ -57,7 +57,7 @@ const createCachedParameterizedComparator = (fn) => {
/**
* @param {T} a first item
* @param {T} b second item
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const result = fn.bind(null, arg);
map.set(/** @type {EXPECTED_OBJECT} */ (arg), result);
@@ -90,7 +90,7 @@ const compareIterables = (elementComparator) => {
/**
* @param {Iterable<T>} a first value
* @param {Iterable<T>} b second value
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const result = (a, b) => {
const aI = a[Symbol.iterator]();
@@ -115,7 +115,7 @@ const compareIterables = (elementComparator) => {
* Compare two locations
* @param {DependencyLocation} a A location node
* @param {DependencyLocation} b A location node
* @returns {-1|0|1} sorting comparator value
* @returns {-1 | 0 | 1} sorting comparator value
*/
const compareLocations = (a, b) => {
const isObjectA = typeof a === "object" && a !== null;
@@ -178,7 +178,7 @@ const compareLocations = (a, b) => {
* @param {ChunkGraph} chunkGraph the chunk graph
* @param {Module} a module
* @param {Module} b module
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareModulesById = (chunkGraph, a, b) =>
compareIds(
@@ -189,7 +189,7 @@ const compareModulesById = (chunkGraph, a, b) =>
/**
* @param {number} a number
* @param {number} b number
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareNumbers = (a, b) => {
if (typeof a !== typeof b) {
@@ -203,7 +203,7 @@ const compareNumbers = (a, b) => {
/**
* @param {string} a string
* @param {string} b string
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareStringsNumeric = (a, b) => {
const aLength = a.length;
@@ -275,7 +275,7 @@ const compareStringsNumeric = (a, b) => {
* @param {ModuleGraph} moduleGraph the module graph
* @param {Module} a module
* @param {Module} b module
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
const cmp = compareNumbers(
@@ -290,7 +290,7 @@ const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
* @param {ModuleGraph} moduleGraph the module graph
* @param {Module} a module
* @param {Module} b module
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
const cmp = compareNumbers(
@@ -305,7 +305,7 @@ const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
* @param {ChunkGraph} chunkGraph the chunk graph
* @param {Module} a module
* @param {Module} b module
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareModulesByIdOrIdentifier = (chunkGraph, a, b) => {
const cmp = compareIds(
@@ -327,7 +327,7 @@ const compareChunks = (chunkGraph, a, b) => chunkGraph.compareChunks(a, b);
/**
* @param {string} a first string
* @param {string} b second string
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const compareStrings = (a, b) => {
if (a < b) return -1;
@@ -408,7 +408,7 @@ const concatComparators = (c1, c2, ...cRest) => {
/**
* @param {T} a first value
* @param {T} b second value
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const result = (a, b) => {
const res = c1(a, b);
@@ -440,7 +440,7 @@ const compareSelect = (getter, comparator) => {
/**
* @param {T} a first value
* @param {T} b second value
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
const result = (a, b) => {
const aValue = getter(a);
@@ -511,47 +511,42 @@ const compareChunksNatural = (chunkGraph) => {
* https://github.com/webpack/webpack/pull/19686
* @param {Dependency[]} dependencies dependencies
* @param {WeakMap<Dependency, DependencySourceOrder>} dependencySourceOrderMap dependency source order map
* @param {((dep: Dependency, index: number) => void)=} onDependencyReSort optional callback to set index for each dependency
* @returns {void}
*/
const sortWithSourceOrder = (dependencies, dependencySourceOrderMap) => {
/**
* @param {Dependency} dep dependency
* @returns {number} source order
*/
const getSourceOrder = (dep) => {
if (dependencySourceOrderMap.has(dep)) {
const { main } = /** @type {DependencySourceOrder} */ (
dependencySourceOrderMap.get(dep)
);
return main;
}
return /** @type {number} */ (
/** @type {ModuleDependency} */ (dep).sourceOrder
);
};
/**
* If the sourceOrder is a number, it means the dependency needs to be sorted.
* @param {number | undefined} sourceOrder sourceOrder
* @returns {boolean} needReSort
*/
const needReSort = (sourceOrder) => {
if (typeof sourceOrder === "number") {
return true;
}
return false;
};
// Extract dependencies with sourceOrder and sort them
const sortWithSourceOrder = (
dependencies,
dependencySourceOrderMap,
onDependencyReSort
) => {
/** @type {{dep: Dependency, main: number, sub: number}[]} */
const withSourceOrder = [];
/** @type {number[]} */
const positions = [];
// First pass: collect dependencies with sourceOrder
for (let i = 0; i < dependencies.length; i++) {
const dep = dependencies[i];
const sourceOrder = getSourceOrder(dep);
const cached = dependencySourceOrderMap.get(dep);
if (needReSort(sourceOrder)) {
withSourceOrder.push({ dep, sourceOrder, originalIndex: i });
if (cached) {
positions.push(i);
withSourceOrder.push({
dep,
main: cached.main,
sub: cached.sub
});
} else {
const sourceOrder = /** @type {number | undefined} */ (
/** @type {ModuleDependency} */ (dep).sourceOrder
);
if (typeof sourceOrder === "number") {
positions.push(i);
withSourceOrder.push({
dep,
main: sourceOrder,
sub: 0
});
}
}
}
@@ -559,37 +554,19 @@ const sortWithSourceOrder = (dependencies, dependencySourceOrderMap) => {
return;
}
// Sort dependencies with sourceOrder
withSourceOrder.sort((a, b) => {
// Handle both dependencies in map case
if (
dependencySourceOrderMap.has(a.dep) &&
dependencySourceOrderMap.has(b.dep)
) {
const { main: mainA, sub: subA } = /** @type {DependencySourceOrder} */ (
dependencySourceOrderMap.get(a.dep)
);
const { main: mainB, sub: subB } = /** @type {DependencySourceOrder} */ (
dependencySourceOrderMap.get(b.dep)
);
if (mainA === mainB) {
return compareNumbers(subA, subB);
}
return compareNumbers(mainA, mainB);
if (a.main !== b.main) {
return compareNumbers(a.main, b.main);
}
return compareNumbers(a.sourceOrder, b.sourceOrder);
return compareNumbers(a.sub, b.sub);
});
// Second pass: build result array
let sortedIndex = 0;
for (let i = 0; i < dependencies.length; i++) {
const dep = dependencies[i];
const sourceOrder = getSourceOrder(dep);
if (needReSort(sourceOrder)) {
dependencies[i] = withSourceOrder[sortedIndex].dep;
sortedIndex++;
// Second pass: place sorted deps back to original positions
for (let i = 0; i < positions.length; i++) {
const depIndex = positions[i];
dependencies[depIndex] = withSourceOrder[i].dep;
if (onDependencyReSort) {
onDependencyReSort(dependencies[depIndex], depIndex);
}
}
};
@@ -601,7 +578,7 @@ module.exports.compareChunks =
/**
* @param {Chunk} a chunk
* @param {Chunk} b chunk
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
module.exports.compareChunksById = (a, b) =>
compareIds(/** @type {ChunkId} */ (a.id), /** @type {ChunkId} */ (b.id));
@@ -622,7 +599,7 @@ module.exports.compareModulesByIdOrIdentifier =
/**
* @param {Module} a module
* @param {Module} b module
* @returns {-1|0|1} compare result
* @returns {-1 | 0 | 1} compare result
*/
module.exports.compareModulesByIdentifier = (a, b) =>
compareIds(a.identifier(), b.identifier());

84
node_modules/webpack/lib/util/compileBooleanMatcher.js generated vendored Executable file → Normal file
View File

@@ -11,6 +11,79 @@
*/
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
/**
* @param {string} char character to escape for use in character class
* @returns {string} escaped character
*/
const quoteMetaInCharClass = (char) => {
// In character class, only these need escaping: ] \ ^ -
if (char === "]" || char === "\\" || char === "^" || char === "-") {
return `\\${char}`;
}
return char;
};
/**
* Converts an array of single characters into an optimized character class string
* using ranges where possible. E.g., ["1","2","3","4","a"] => "1-4a"
* @param {string[]} chars array of single characters (should be sorted)
* @returns {string} optimized character class content (without the brackets)
*/
const charsToCharClassContent = (chars) => {
if (chars.length === 0) return "";
if (chars.length === 1) return quoteMetaInCharClass(chars[0]);
// Sort by char code
const sorted = [...chars].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0));
/** @type {string[]} */
const parts = [];
let rangeStart = sorted[0];
let rangeEnd = sorted[0];
for (let i = 1; i < sorted.length; i++) {
const char = sorted[i];
const prevCode = rangeEnd.charCodeAt(0);
const currCode = char.charCodeAt(0);
if (currCode === prevCode + 1) {
// Extend the range
rangeEnd = char;
} else {
// Flush the current range
parts.push(formatRange(rangeStart, rangeEnd));
rangeStart = char;
rangeEnd = char;
}
}
// Flush the last range
parts.push(formatRange(rangeStart, rangeEnd));
return parts.join("");
};
/**
* Formats a range of characters for use in a character class
* @param {string} start start character
* @param {string} end end character
* @returns {string} formatted range
*/
const formatRange = (start, end) => {
const startCode = start.charCodeAt(0);
const endCode = end.charCodeAt(0);
const length = endCode - startCode + 1;
if (length === 1) {
return quoteMetaInCharClass(start);
}
if (length === 2) {
// For 2 chars, just list them (e.g., "ab" instead of "a-b")
return quoteMetaInCharClass(start) + quoteMetaInCharClass(end);
}
// For 3+ chars, use range notation
return `${quoteMetaInCharClass(start)}-${quoteMetaInCharClass(end)}`;
};
/**
* @param {string} str string
* @returns {string} string
@@ -148,19 +221,20 @@ const itemsToRegexp = (itemsArr) => {
}
// special case for only single char items
if (countOfSingleCharItems === itemsArr.length) {
return `[${quoteMeta(itemsArr.sort().join(""))}]`;
return `[${charsToCharClassContent(itemsArr)}]`;
}
/** @type {Set<string>} */
const items = new Set(itemsArr.sort());
if (countOfSingleCharItems > 2) {
let singleCharItems = "";
/** @type {string[]} */
const singleCharItems = [];
for (const item of items) {
if (item.length === 1) {
singleCharItems += item;
singleCharItems.push(item);
items.delete(item);
}
}
finishedItems.push(`[${quoteMeta(singleCharItems)}]`);
finishedItems.push(`[${charsToCharClassContent(singleCharItems)}]`);
}
// special case for 2 items with common prefix/suffix
@@ -227,8 +301,6 @@ const itemsToRegexp = (itemsArr) => {
);
}
// TODO further optimize regexp, i. e.
// use ranges: (1|2|3|4|a) => [1-4a]
/** @type {string[]} */
const conditional = [...finishedItems, ...Array.from(items, quoteMeta)];
if (conditional.length === 1) return conditional[0];

0
node_modules/webpack/lib/util/concatenate.js generated vendored Executable file → Normal file
View File

View File

@@ -5,212 +5,21 @@
"use strict";
const Hash = require("./Hash");
/** @typedef {import("../../declarations/WebpackOptions").HashDigest} Encoding */
/** @typedef {import("./Hash")} Hash */
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
const BULK_SIZE = 3;
// We are using an object instead of a Map as this will stay static during the runtime
// so access to it can be optimized by v8
/** @type {{[key: string]: Map<string, string>}} */
const digestCaches = {};
/** @typedef {() => Hash} HashFactory */
class BulkUpdateDecorator extends Hash {
/**
* @param {Hash | HashFactory} hashOrFactory function to create a hash
* @param {string=} hashKey key for caching
*/
constructor(hashOrFactory, hashKey) {
super();
this.hashKey = hashKey;
if (typeof hashOrFactory === "function") {
this.hashFactory = hashOrFactory;
this.hash = undefined;
} else {
this.hashFactory = undefined;
this.hash = hashOrFactory;
}
this.buffer = "";
}
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string | Buffer} data data
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string} data data
* @param {Encoding} inputEncoding data encoding
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string | Buffer} data data
* @param {Encoding=} inputEncoding data encoding
* @returns {Hash} updated hash
*/
update(data, inputEncoding) {
if (
inputEncoding !== undefined ||
typeof data !== "string" ||
data.length > BULK_SIZE
) {
if (this.hash === undefined) {
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
if (this.buffer.length > 0) {
this.hash.update(this.buffer);
this.buffer = "";
}
if (typeof data === "string" && inputEncoding) {
this.hash.update(data, inputEncoding);
} else {
this.hash.update(data);
}
} else {
this.buffer += data;
if (this.buffer.length > BULK_SIZE) {
if (this.hash === undefined) {
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
this.hash.update(this.buffer);
this.buffer = "";
}
}
return this;
}
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @returns {Buffer} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @param {Encoding} encoding encoding of the return value
* @returns {string} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {Encoding=} encoding encoding of the return value
* @returns {string | Buffer} digest
*/
digest(encoding) {
let digestCache;
const buffer = this.buffer;
if (this.hash === undefined) {
// short data for hash, we can use caching
const cacheKey = `${this.hashKey}-${encoding}`;
digestCache = digestCaches[cacheKey];
if (digestCache === undefined) {
digestCache = digestCaches[cacheKey] = new Map();
}
const cacheEntry = digestCache.get(buffer);
if (cacheEntry !== undefined) return cacheEntry;
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
if (buffer.length > 0) {
this.hash.update(buffer);
}
if (!encoding) {
const result = this.hash.digest();
if (digestCache !== undefined) {
digestCache.set(buffer, result);
}
return result;
}
const digestResult = this.hash.digest(encoding);
// Compatibility with the old hash library
const result =
typeof digestResult === "string"
? digestResult
: /** @type {NodeJS.TypedArray} */ (digestResult).toString();
if (digestCache !== undefined) {
digestCache.set(buffer, result);
}
return result;
}
}
/* istanbul ignore next */
class DebugHash extends Hash {
constructor() {
super();
this.string = "";
}
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string | Buffer} data data
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string} data data
* @param {Encoding} inputEncoding data encoding
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string | Buffer} data data
* @param {Encoding=} inputEncoding data encoding
* @returns {Hash} updated hash
*/
update(data, inputEncoding) {
if (typeof data !== "string") data = data.toString("utf8");
const prefix = Buffer.from("@webpack-debug-digest@").toString("hex");
if (data.startsWith(prefix)) {
data = Buffer.from(data.slice(prefix.length), "hex").toString();
}
this.string += `[${data}](${
/** @type {string} */
(
// eslint-disable-next-line unicorn/error-message
new Error().stack
).split("\n", 3)[2]
})\n`;
return this;
}
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @returns {Buffer} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @param {Encoding} encoding encoding of the return value
* @returns {string} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {Encoding=} encoding encoding of the return value
* @returns {string | Buffer} digest
*/
digest(encoding) {
return Buffer.from(`@webpack-debug-digest@${this.string}`).toString("hex");
}
}
/** @type {typeof import("crypto") | undefined} */
let crypto;
/** @type {typeof import("./hash/xxhash64") | undefined} */
let createXXHash64;
/** @type {typeof import("./hash/md4") | undefined} */
let createMd4;
/** @type {typeof import("./hash/DebugHash") | undefined} */
let DebugHash;
/** @type {typeof import("./hash/BatchedHash") | undefined} */
let BatchedHash;
/** @type {typeof import("./hash/BulkUpdateHash") | undefined} */
let BulkUpdateHash;
/**
* Creates a hash by name or function
@@ -219,12 +28,18 @@ let BatchedHash;
*/
module.exports = (algorithm) => {
if (typeof algorithm === "function") {
if (BulkUpdateHash === undefined) {
BulkUpdateHash = require("./hash/BulkUpdateHash");
}
// eslint-disable-next-line new-cap
return new BulkUpdateDecorator(() => new algorithm());
return new BulkUpdateHash(() => new algorithm());
}
switch (algorithm) {
// TODO add non-cryptographic algorithm here
case "debug":
if (DebugHash === undefined) {
DebugHash = require("./hash/DebugHash");
}
return new DebugHash();
case "xxhash64":
if (createXXHash64 === undefined) {
@@ -248,7 +63,10 @@ module.exports = (algorithm) => {
)(createMd4());
case "native-md4":
if (crypto === undefined) crypto = require("crypto");
return new BulkUpdateDecorator(
if (BulkUpdateHash === undefined) {
BulkUpdateHash = require("./hash/BulkUpdateHash");
}
return new BulkUpdateHash(
() =>
/** @type {Hash} */ (
/** @type {typeof import("crypto")} */
@@ -258,7 +76,10 @@ module.exports = (algorithm) => {
);
default:
if (crypto === undefined) crypto = require("crypto");
return new BulkUpdateDecorator(
if (BulkUpdateHash === undefined) {
BulkUpdateHash = require("./hash/BulkUpdateHash");
}
return new BulkUpdateHash(
() =>
/** @type {Hash} */ (
/** @type {typeof import("crypto")} */

View File

@@ -194,7 +194,7 @@ module.exports.arrayToSetDeprecation = (set, name) => {
/**
* @template T
* @param {string} name name
* @returns {{ new <T = any>(values?: ReadonlyArray<T> | null): SetDeprecatedArray<T> }} SetDeprecatedArray
* @returns {{ new <T = EXPECTED_ANY>(values?: ReadonlyArray<T> | null): SetDeprecatedArray<T> }} SetDeprecatedArray
*/
module.exports.createArrayToSetDeprecationSet = (name) => {
let initialized = false;

View File

@@ -137,12 +137,15 @@ const isTooSmall = (size, minSize) => {
return false;
};
/** @typedef {Set<string>} Types */
/**
* @param {Sizes} size size
* @param {Sizes} minSize minimum size
* @returns {Set<string>} set of types that are too small
* @returns {Types} set of types that are too small
*/
const getTooSmallTypes = (size, minSize) => {
/** @typedef {Types} */
const types = new Set();
for (const key of Object.keys(size)) {
const s = size[key];
@@ -156,7 +159,7 @@ const getTooSmallTypes = (size, minSize) => {
/**
* @template {object} T
* @param {T} size size
* @param {Set<string>} types types
* @param {Types} types types
* @returns {number} number of matching size types
*/
const getNumberOfMatchingSizeTypes = (size, types) => {
@@ -169,7 +172,7 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
/**
* @param {Sizes} size size
* @param {Set<string>} types types
* @param {Types} types types
* @returns {number} selective size sum
*/
const selectiveSizeSum = (size, types) => {

150
node_modules/webpack/lib/util/fs.js generated vendored
View File

@@ -45,7 +45,7 @@ const path = require("path");
*/
/**
* @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
* @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
*/
/**
@@ -137,18 +137,18 @@ const path = require("path");
/**
* @typedef {{
* (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void;
* (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void;
* (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void;
* (path: PathOrFileDescriptor, callback: BufferCallback): void;
* (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void,
* (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void,
* (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void,
* (path: PathOrFileDescriptor, callback: BufferCallback): void,
* }} ReadFile
*/
/**
* @typedef {{
* (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer;
* (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string;
* (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer;
* (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer,
* (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string,
* (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer,
* }} ReadFileSync
*/
@@ -157,7 +157,7 @@ const path = require("path");
*/
/**
* @typedef {'buffer'| { encoding: 'buffer' }} BufferEncodingOption
* @typedef {"buffer" | { encoding: "buffer" }} BufferEncodingOption
*/
/**
@@ -173,98 +173,98 @@ const path = require("path");
/**
* @typedef {{
* (path: PathLike, options: EncodingOption, callback: StringCallback): void;
* (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
* (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
* (path: PathLike, callback: StringCallback): void;
* (path: PathLike, options: EncodingOption, callback: StringCallback): void,
* (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
* (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
* (path: PathLike, callback: StringCallback): void,
* }} Readlink
*/
/**
* @typedef {{
* (path: PathLike, options?: EncodingOption): string;
* (path: PathLike, options: BufferEncodingOption): Buffer;
* (path: PathLike, options?: EncodingOption): string | Buffer;
* (path: PathLike, options?: EncodingOption): string,
* (path: PathLike, options: BufferEncodingOption): Buffer,
* (path: PathLike, options?: EncodingOption): string | Buffer,
* }} ReadlinkSync
*/
/**
* @typedef {{
* (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
* (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer', callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void;
* (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void;
* (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent<string>[]) => void): void;
* (path: PathLike, options: { encoding: 'buffer', withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent<Buffer>[]) => void): void;
* (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void,
* (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer", callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void,
* (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void,
* (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void,
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent<string>[]) => void): void,
* (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent<Buffer>[]) => void): void,
* }} Readdir
*/
/**
* @typedef {{
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[];
* (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer'): Buffer[];
* (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[];
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[];
* (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent<Buffer>[];
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[],
* (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer"): Buffer[],
* (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[],
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[],
* (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent<Buffer>[],
* }} ReaddirSync
*/
/**
* @typedef {{
* (path: PathLike, callback: StatsCallback): void;
* (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
* (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
* (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
* (path: PathLike, callback: StatsCallback): void,
* (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void,
* (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void,
* (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void,
* }} Stat
*/
/**
* @typedef {{
* (path: PathLike, options?: undefined): IStats;
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
* (path: PathLike, options?: undefined): IStats,
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined,
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
* }} StatSync
*/
/**
* @typedef {{
* (path: PathLike, callback: StatsCallback): void;
* (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
* (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
* (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
* (path: PathLike, callback: StatsCallback): void,
* (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void,
* (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void,
* (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void,
* }} LStat
*/
/**
* @typedef {{
* (path: PathLike, options?: undefined): IStats;
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
* (path: PathLike, options?: undefined): IStats,
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined,
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
* }} LStatSync
*/
/**
* @typedef {{
* (path: PathLike, options: EncodingOption, callback: StringCallback): void;
* (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
* (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
* (path: PathLike, options: EncodingOption, callback: StringCallback): void,
* (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
* (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
* (path: PathLike, callback: StringCallback): void;
* }} RealPath
*/
/**
* @typedef {{
* (path: PathLike, options?: EncodingOption): string;
* (path: PathLike, options: BufferEncodingOption): Buffer;
* (path: PathLike, options?: EncodingOption): string | Buffer;
* (path: PathLike, options?: EncodingOption): string,
* (path: PathLike, options: BufferEncodingOption): Buffer,
* (path: PathLike, options?: EncodingOption): string | Buffer,
* }} RealPathSync
*/
@@ -312,8 +312,8 @@ const path = require("path");
/**
* @typedef {{
* (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
* (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
* (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void,
* (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void,
* }} WriteFile
*/
@@ -323,10 +323,10 @@ const path = require("path");
/**
* @typedef {{
* (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void;
* (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null | undefined, callback: NoParamCallback): void;
* (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void;
* (file: PathLike, callback: NoParamCallback): void;
* (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void,
* (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null | undefined, callback: NoParamCallback): void,
* (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void,
* (file: PathLike, callback: NoParamCallback): void,
* }} Mkdir
*/
@@ -336,8 +336,8 @@ const path = require("path");
/**
* @typedef {{
* (file: PathLike, callback: NoParamCallback): void;
* (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
* (file: PathLike, callback: NoParamCallback): void,
* (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void,
* }} Rmdir
*/
@@ -380,9 +380,9 @@ const path = require("path");
/**
* @typedef {{
* (path: PathLike, options: MakeDirectoryOptions & { recursive: true }): string | undefined;
* (path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null): void;
* (path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
* (path: PathLike, options: MakeDirectoryOptions & { recursive: true }): string | undefined,
* (path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null): void,
* (path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined,
* }} MkdirSync
*/
@@ -422,9 +422,9 @@ const path = require("path");
/**
* @typedef {{
* (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void;
* (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void;
* (file: PathLike, callback: NumberCallback): void;
* (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void,
* (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void,
* (file: PathLike, callback: NumberCallback): void,
* }} Open
*/
@@ -451,9 +451,9 @@ const path = require("path");
/**
* @template {NodeJS.ArrayBufferView} [TBuffer=NodeJS.ArrayBufferView]
* @typedef {{
* (fd: number, buffer: TBuffer, offset: number, length: number, position: ReadPosition | null, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void;
* (fd: number, options: ReadAsyncOptions<TBuffer>, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void;
* (fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void;
* (fd: number, buffer: TBuffer, offset: number, length: number, position: ReadPosition | null, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void,
* (fd: number, options: ReadAsyncOptions<TBuffer>, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void,
* (fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void,
* }} Read
*/
@@ -474,7 +474,7 @@ const path = require("path");
/** @typedef {InputFileSystem & OutputFileSystem & IntermediateFileSystemExtras} IntermediateFileSystem */
/**
* @param {InputFileSystem | OutputFileSystem|undefined} fs a file system
* @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
* @param {string} rootPath the root path
* @param {string} targetPath the target path
* @returns {string} location of targetPath relative to rootPath
@@ -493,7 +493,7 @@ const relative = (fs, rootPath, targetPath) => {
};
/**
* @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
* @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
* @param {string} rootPath a path
* @param {string} filename a filename
* @returns {string} the joined path
@@ -512,7 +512,7 @@ const join = (fs, rootPath, filename) => {
};
/**
* @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
* @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
* @param {string} absPath an absolute path
* @returns {string} the parent directory of the absolute path
*/

19
node_modules/webpack/lib/util/hash/BatchedHash.js generated vendored Executable file → Normal file
View File

@@ -6,6 +6,7 @@
"use strict";
const Hash = require("../Hash");
const { digest, update } = require("./hash-digest");
const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
@@ -51,9 +52,9 @@ class BatchedHash extends Hash {
return this;
}
if (this.encoding) {
this.hash.update(this.string, this.encoding);
update(this.hash, this.string, this.encoding);
} else {
this.hash.update(this.string);
update(this.hash, this.string);
}
this.string = undefined;
}
@@ -66,12 +67,12 @@ class BatchedHash extends Hash {
this.string = data;
this.encoding = inputEncoding;
} else if (inputEncoding) {
this.hash.update(data, inputEncoding);
update(this.hash, data, inputEncoding);
} else {
this.hash.update(data);
update(this.hash, data);
}
} else {
this.hash.update(data);
update(this.hash, data);
}
return this;
}
@@ -95,15 +96,15 @@ class BatchedHash extends Hash {
digest(encoding) {
if (this.string !== undefined) {
if (this.encoding) {
this.hash.update(this.string, this.encoding);
update(this.hash, this.string, this.encoding);
} else {
this.hash.update(this.string);
update(this.hash, this.string);
}
}
if (!encoding) {
return this.hash.digest();
return digest(this.hash);
}
return this.hash.digest(encoding);
return digest(this.hash, encoding);
}
}

138
node_modules/webpack/lib/util/hash/BulkUpdateHash.js generated vendored Normal file
View File

@@ -0,0 +1,138 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Alexander Akait @alexander-akait
*/
"use strict";
const Hash = require("../Hash");
const { digest, update } = require("./hash-digest");
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
/** @typedef {() => Hash} HashFactory */
const BULK_SIZE = 3;
// We are using an object instead of a Map as this will stay static during the runtime
// so access to it can be optimized by v8
/** @type {{[key: string]: Map<string, string>}} */
const digestCaches = {};
class BulkUpdateHash extends Hash {
/**
* @param {Hash | HashFactory} hashOrFactory function to create a hash
* @param {string=} hashKey key for caching
*/
constructor(hashOrFactory, hashKey) {
super();
this.hashKey = hashKey;
if (typeof hashOrFactory === "function") {
this.hashFactory = hashOrFactory;
this.hash = undefined;
} else {
this.hashFactory = undefined;
this.hash = hashOrFactory;
}
this.buffer = "";
}
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string | Buffer} data data
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string} data data
* @param {Encoding} inputEncoding data encoding
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string | Buffer} data data
* @param {Encoding=} inputEncoding data encoding
* @returns {Hash} updated hash
*/
update(data, inputEncoding) {
if (
inputEncoding !== undefined ||
typeof data !== "string" ||
data.length > BULK_SIZE
) {
if (this.hash === undefined) {
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
if (this.buffer.length > 0) {
update(this.hash, this.buffer);
this.buffer = "";
}
if (typeof data === "string" && inputEncoding) {
update(this.hash, data, inputEncoding);
} else {
update(this.hash, data);
}
} else {
this.buffer += data;
if (this.buffer.length > BULK_SIZE) {
if (this.hash === undefined) {
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
update(this.hash, this.buffer);
this.buffer = "";
}
}
return this;
}
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @returns {Buffer} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @param {Encoding} encoding encoding of the return value
* @returns {string} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {Encoding=} encoding encoding of the return value
* @returns {string | Buffer} digest
*/
digest(encoding) {
let digestCache;
const buffer = this.buffer;
if (this.hash === undefined) {
// short data for hash, we can use caching
const cacheKey = `${this.hashKey}-${encoding}`;
digestCache = digestCaches[cacheKey];
if (digestCache === undefined) {
digestCache = digestCaches[cacheKey] = new Map();
}
const cacheEntry = digestCache.get(buffer);
if (cacheEntry !== undefined) return cacheEntry;
this.hash = /** @type {HashFactory} */ (this.hashFactory)();
}
if (buffer.length > 0) {
update(this.hash, buffer);
}
if (!encoding) {
const result = digest(this.hash, undefined, Boolean(this.hashKey));
if (digestCache !== undefined) {
digestCache.set(buffer, result);
}
return result;
}
const result = digest(this.hash, encoding, Boolean(this.hashKey));
if (digestCache !== undefined) {
digestCache.set(buffer, result);
}
return result;
}
}
module.exports = BulkUpdateHash;

75
node_modules/webpack/lib/util/hash/DebugHash.js generated vendored Executable file
View File

@@ -0,0 +1,75 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Alexander Akait @alexander-akait
*/
"use strict";
const Hash = require("../Hash");
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
/* istanbul ignore next */
class DebugHash extends Hash {
constructor() {
super();
this.string = "";
}
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string | Buffer} data data
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @overload
* @param {string} data data
* @param {Encoding} inputEncoding data encoding
* @returns {Hash} updated hash
*/
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string | Buffer} data data
* @param {Encoding=} inputEncoding data encoding
* @returns {Hash} updated hash
*/
update(data, inputEncoding) {
if (typeof data !== "string") data = data.toString("utf8");
const prefix = Buffer.from("@webpack-debug-digest@").toString("hex");
if (data.startsWith(prefix)) {
data = Buffer.from(data.slice(prefix.length), "hex").toString();
}
this.string += `[${data}](${
/** @type {string} */
(
// eslint-disable-next-line unicorn/error-message
new Error().stack
).split("\n", 3)[2]
})\n`;
return this;
}
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @returns {Buffer} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @overload
* @param {Encoding} encoding encoding of the return value
* @returns {string} digest
*/
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {Encoding=} encoding encoding of the return value
* @returns {string | Buffer} digest
*/
digest(encoding) {
return Buffer.from(`@webpack-debug-digest@${this.string}`).toString("hex");
}
}
module.exports = DebugHash;

216
node_modules/webpack/lib/util/hash/hash-digest.js generated vendored Executable file
View File

@@ -0,0 +1,216 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Alexander Akait @alexander-akait
*/
"use strict";
/** @typedef {import("../Hash")} Hash */
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
/** @typedef {"26" | "32" | "36" | "49" | "52" | "58" | "62"} Base */
/* cSpell:disable */
/** @type {Record<Base, string>} */
const ENCODE_TABLE = Object.freeze({
26: "abcdefghijklmnopqrstuvwxyz",
32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
36: "0123456789abcdefghijklmnopqrstuvwxyz",
49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",
52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
});
/* cSpell:enable */
const ZERO = BigInt("0");
const EIGHT = BigInt("8");
const FF = BigInt("0xff");
/**
* It encodes octet arrays by doing long divisions on all significant digits in the array, creating a representation of that number in the new base.
* Then for every leading zero in the input (not significant as a number) it will encode as a single leader character.
* This is the first in the alphabet and will decode as 8 bits. The other characters depend upon the base.
* For example, a base58 alphabet packs roughly 5.858 bits per character.
* This means the encoded string 000f (using a base16, 0-f alphabet) will actually decode to 4 bytes unlike a canonical hex encoding which uniformly packs 4 bits into each character.
* While unusual, this does mean that no padding is required, and it works for bases like 43.
* @param {Buffer} buffer buffer
* @param {Base} base base
* @returns {string} encoded buffer
*/
const encode = (buffer, base) => {
if (buffer.length === 0) return "";
const bigIntBase = BigInt(ENCODE_TABLE[base].length);
// Convert buffer to BigInt efficiently using bitwise operations
let value = ZERO;
for (let i = 0; i < buffer.length; i++) {
value = (value << EIGHT) | BigInt(buffer[i]);
}
// Convert to baseX string efficiently using array
const digits = [];
if (value === ZERO) return ENCODE_TABLE[base][0];
while (value > ZERO) {
const remainder = Number(value % bigIntBase);
digits.push(ENCODE_TABLE[base][remainder]);
value /= bigIntBase;
}
return digits.reverse().join("");
};
/**
* @param {string} data string
* @param {Base} base base
* @returns {Buffer} buffer
*/
const decode = (data, base) => {
if (data.length === 0) return Buffer.from("");
const bigIntBase = BigInt(ENCODE_TABLE[base].length);
// Convert the baseX string to a BigInt value
let value = ZERO;
for (let i = 0; i < data.length; i++) {
const digit = ENCODE_TABLE[base].indexOf(data[i]);
if (digit === -1) {
throw new Error(`Invalid character at position ${i}: ${data[i]}`);
}
value = value * bigIntBase + BigInt(digit);
}
// If value is 0, return a single-byte buffer with value 0
if (value === ZERO) {
return Buffer.alloc(1);
}
// Determine buffer size efficiently by counting bytes
let temp = value;
let byteLength = 0;
while (temp > ZERO) {
temp >>= EIGHT;
byteLength++;
}
// Create buffer and fill it from right to left
const buffer = Buffer.alloc(byteLength);
for (let i = byteLength - 1; i >= 0; i--) {
buffer[i] = Number(value & FF);
value >>= EIGHT;
}
return buffer;
};
// Compatibility with the old hash libraries, they can return different structures, so let's stringify them firstly
/**
* @param {string | { toString: (radix: number) => string }} value value
* @param {string} encoding encoding
* @returns {string} string
*/
const toString = (value, encoding) =>
typeof value === "string"
? value
: Buffer.from(value.toString(16), "hex").toString(
/** @type {NodeJS.BufferEncoding} */
(encoding)
);
/**
* @param {Buffer | { toString: (radix: number) => string }} value value
* @returns {Buffer} buffer
*/
const toBuffer = (value) =>
Buffer.isBuffer(value) ? value : Buffer.from(value.toString(16), "hex");
let isBase64URLSupported = false;
try {
isBase64URLSupported = Boolean(Buffer.from("", "base64url"));
} catch (_err) {
// Nothing
}
/**
* @param {Hash} hash hash
* @param {string | Buffer} data data
* @param {Encoding=} encoding encoding of the return value
* @returns {void}
*/
const update = (hash, data, encoding) => {
if (encoding === "base64url" && !isBase64URLSupported) {
const base64String = /** @type {string} */ (data)
.replace(/-/g, "+")
.replace(/_/g, "/");
const buf = Buffer.from(base64String, "base64");
hash.update(buf);
return;
} else if (
typeof data === "string" &&
encoding &&
typeof ENCODE_TABLE[/** @type {Base} */ (encoding.slice(4))] !== "undefined"
) {
const buf = decode(data, /** @type {Base} */ (encoding.slice(4)));
hash.update(buf);
return;
}
if (encoding) {
hash.update(/** @type {string} */ (data), encoding);
} else {
hash.update(data);
}
};
/**
* @overload
* @param {Hash} hash hash
* @returns {Buffer} digest
*/
/**
* @overload
* @param {Hash} hash hash
* @param {undefined} encoding encoding of the return value
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
* @returns {Buffer} digest
*/
/**
* @overload
* @param {Hash} hash hash
* @param {Encoding} encoding encoding of the return value
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
* @returns {string} digest
*/
/**
* @param {Hash} hash hash
* @param {Encoding=} encoding encoding of the return value
* @param {boolean=} isSafe true when we await right types from digest(), otherwise false
* @returns {string | Buffer} digest
*/
const digest = (hash, encoding, isSafe) => {
if (typeof encoding === "undefined") {
return isSafe ? hash.digest() : toBuffer(hash.digest());
}
if (encoding === "base64url" && !isBase64URLSupported) {
const digest = isSafe
? hash.digest("base64")
: toString(hash.digest("base64"), "base64");
return digest.replace(/\+/g, "-").replace(/\//g, "_").replace(/[=]+$/, "");
} else if (
typeof ENCODE_TABLE[/** @type {Base} */ (encoding.slice(4))] !== "undefined"
) {
const buf = isSafe ? hash.digest() : toBuffer(hash.digest());
return encode(
buf,
/** @type {Base} */
(encoding.slice(4))
);
}
return isSafe
? hash.digest(encoding)
: toString(hash.digest(encoding), encoding);
};
module.exports.decode = decode;
module.exports.digest = digest;
module.exports.encode = encode;
module.exports.update = update;

View File

@@ -321,6 +321,7 @@ const absolutify = makeCacheableWithContext(_absolutify);
const PATH_QUERY_FRAGMENT_REGEXP =
/^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
const ZERO_ESCAPE_REGEXP = /\0(.)/g;
/** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
/** @typedef {{ resource: string, path: string, query: string }} ParsedResourceWithoutFragment */
@@ -330,15 +331,56 @@ const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
* @returns {ParsedResource} parsed parts
*/
const _parseResource = (str) => {
const match =
/** @type {[string, string, string | undefined, string | undefined]} */
(/** @type {unknown} */ (PATH_QUERY_FRAGMENT_REGEXP.exec(str)));
return {
resource: str,
path: match[1].replace(/\0(.)/g, "$1"),
query: match[2] ? match[2].replace(/\0(.)/g, "$1") : "",
fragment: match[3] || ""
};
const firstEscape = str.indexOf("\0");
// Handle `\0`
if (firstEscape !== -1) {
const match =
/** @type {[string, string, string | undefined, string | undefined]} */
(/** @type {unknown} */ (PATH_QUERY_FRAGMENT_REGEXP.exec(str)));
return {
resource: str,
path: match[1].replace(ZERO_ESCAPE_REGEXP, "$1"),
query: match[2] ? match[2].replace(ZERO_ESCAPE_REGEXP, "$1") : "",
fragment: match[3] || ""
};
}
/** @type {ParsedResource} */
const result = { resource: str, path: "", query: "", fragment: "" };
const queryStart = str.indexOf("?");
const fragmentStart = str.indexOf("#");
if (fragmentStart < 0) {
if (queryStart < 0) {
result.path = result.resource;
// No fragment, no query
return result;
}
result.path = str.slice(0, queryStart);
result.query = str.slice(queryStart);
// Query, no fragment
return result;
}
if (queryStart < 0 || fragmentStart < queryStart) {
result.path = str.slice(0, fragmentStart);
result.fragment = str.slice(fragmentStart);
// Fragment, no query
return result;
}
result.path = str.slice(0, queryStart);
result.query = str.slice(queryStart, fragmentStart);
result.fragment = str.slice(fragmentStart);
// Query and fragment
return result;
};
/**
@@ -347,14 +389,37 @@ const _parseResource = (str) => {
* @returns {ParsedResourceWithoutFragment} parsed parts
*/
const _parseResourceWithoutFragment = (str) => {
const match =
/** @type {[string, string, string | undefined]} */
(/** @type {unknown} */ (PATH_QUERY_REGEXP.exec(str)));
return {
resource: str,
path: match[1].replace(/\0(.)/g, "$1"),
query: match[2] ? match[2].replace(/\0(.)/g, "$1") : ""
};
const firstEscape = str.indexOf("\0");
// Handle `\0`
if (firstEscape !== -1) {
const match =
/** @type {[string, string, string | undefined]} */
(/** @type {unknown} */ (PATH_QUERY_REGEXP.exec(str)));
return {
resource: str,
path: match[1].replace(ZERO_ESCAPE_REGEXP, "$1"),
query: match[2] ? match[2].replace(ZERO_ESCAPE_REGEXP, "$1") : ""
};
}
/** @type {ParsedResourceWithoutFragment} */
const result = { resource: str, path: "", query: "" };
const queryStart = str.indexOf("?");
if (queryStart < 0) {
result.path = result.resource;
// No query
return result;
}
result.path = str.slice(0, queryStart);
result.query = str.slice(queryStart);
// Query
return result;
};
/**

View File

@@ -73,16 +73,12 @@ module.exports = {
require("../dependencies/CriticalDependencyWarning"),
"dependencies/CssImportDependency": () =>
require("../dependencies/CssImportDependency"),
"dependencies/CssIcssLocalIdentifierDependency": () =>
require("../dependencies/CssIcssLocalIdentifierDependency"),
"dependencies/CssIcssSelfLocalIdentifierDependency": () =>
require("../dependencies/CssIcssSelfLocalIdentifierDependency"),
"dependencies/CssUrlDependency": () =>
require("../dependencies/CssUrlDependency"),
"dependencies/CssIcssImportDependency": () =>
require("../dependencies/CssIcssImportDependency"),
"dependencies/CssIcssExportDependency": () =>
require("../dependencies/CssIcssExportDependency"),
"dependencies/CssUrlDependency": () =>
require("../dependencies/CssUrlDependency"),
"dependencies/CssIcssSymbolDependency": () =>
require("../dependencies/CssIcssSymbolDependency"),
"dependencies/DelegatedSourceDependency": () =>

View File

@@ -1,10 +0,0 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Alexander Akait @alexander-akait
*/
"use strict";
//#region runtime code: json-parse-even-better-errors, parseJsonError
module.exports = "test";
//#endregion

View File

@@ -71,7 +71,7 @@ const forEachRuntime = (runtime, fn, deterministicOrder = false) => {
/**
* @template T
* @param {SortableSet<T>} set set
* @param {Exclude<RuntimeSpec, undefined | string>} set set
* @returns {string} runtime key
*/
const getRuntimesKey = (set) => {
@@ -102,7 +102,7 @@ const keyToRuntime = (key) => {
/**
* @template T
* @param {SortableSet<T>} set set
* @param {Exclude<RuntimeSpec, undefined | string>} set set
* @returns {string} runtime string
*/
const getRuntimesString = (set) => {
@@ -163,7 +163,7 @@ const runtimeEqual = (a, b) => {
/**
* @param {RuntimeSpec} a first
* @param {RuntimeSpec} b second
* @returns {-1|0|1} compare
* @returns {-1 | 0 | 1} compare
*/
const compareRuntime = (a, b) => {
if (a === b) {

View File

@@ -17,9 +17,9 @@ const equalityCache = new WeakMap();
*/
const _isSourceEqual = (a, b) => {
// prefer .buffer(), it's called anyway during emit
/** @type {Buffer|string} */
/** @type {Buffer | string} */
let aSource = typeof a.buffer === "function" ? a.buffer() : a.source();
/** @type {Buffer|string} */
/** @type {Buffer | string} */
let bSource = typeof b.buffer === "function" ? b.buffer() : b.source();
if (aSource === bSource) return true;
if (typeof aSource === "string" && typeof bSource === "string") return false;