feat: refactoring project
This commit is contained in:
4
node_modules/webpack/lib/ids/ChunkModuleIdRangePlugin.js
generated
vendored
4
node_modules/webpack/lib/ids/ChunkModuleIdRangePlugin.js
generated
vendored
@@ -70,9 +70,7 @@ class ChunkModuleIdRangePlugin {
|
||||
chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn);
|
||||
} else {
|
||||
chunkModules = Array.from(modules)
|
||||
.filter(m => {
|
||||
return chunkGraph.isModuleInChunk(m, chunk);
|
||||
})
|
||||
.filter(m => chunkGraph.isModuleInChunk(m, chunk))
|
||||
.sort(compareModulesByPreOrderIndexOrIdentifier(moduleGraph));
|
||||
}
|
||||
|
||||
|
||||
6
node_modules/webpack/lib/ids/DeterministicChunkIdsPlugin.js
generated
vendored
6
node_modules/webpack/lib/ids/DeterministicChunkIdsPlugin.js
generated
vendored
@@ -51,9 +51,7 @@ class DeterministicChunkIdsPlugin {
|
||||
|
||||
const usedIds = getUsedChunkIds(compilation);
|
||||
assignDeterministicIds(
|
||||
Array.from(chunks).filter(chunk => {
|
||||
return chunk.id === null;
|
||||
}),
|
||||
Array.from(chunks).filter(chunk => chunk.id === null),
|
||||
chunk =>
|
||||
getFullChunkName(chunk, chunkGraph, context, compiler.root),
|
||||
compareNatural,
|
||||
@@ -65,7 +63,7 @@ class DeterministicChunkIdsPlugin {
|
||||
chunk.ids = [id];
|
||||
return true;
|
||||
},
|
||||
[Math.pow(10, maxLength)],
|
||||
[10 ** maxLength],
|
||||
10,
|
||||
usedIds.size
|
||||
);
|
||||
|
||||
2
node_modules/webpack/lib/ids/DeterministicModuleIdsPlugin.js
generated
vendored
2
node_modules/webpack/lib/ids/DeterministicModuleIdsPlugin.js
generated
vendored
@@ -77,7 +77,7 @@ class DeterministicModuleIdsPlugin {
|
||||
chunkGraph.setModuleId(module, id);
|
||||
return true;
|
||||
},
|
||||
[Math.pow(10, maxLength)],
|
||||
[10 ** maxLength],
|
||||
fixedLength ? 0 : 10,
|
||||
usedIds.size,
|
||||
salt
|
||||
|
||||
6
node_modules/webpack/lib/ids/HashedModuleIdsPlugin.js
generated
vendored
6
node_modules/webpack/lib/ids/HashedModuleIdsPlugin.js
generated
vendored
@@ -64,7 +64,11 @@ class HashedModuleIdsPlugin {
|
||||
);
|
||||
for (const module of modulesInNaturalOrder) {
|
||||
const ident = getFullModuleName(module, context, compiler.root);
|
||||
const hash = createHash(options.hashFunction);
|
||||
const hash = createHash(
|
||||
/** @type {NonNullable<HashedModuleIdsPluginOptions["hashFunction"]>} */ (
|
||||
options.hashFunction
|
||||
)
|
||||
);
|
||||
hash.update(ident || "");
|
||||
const hashId = /** @type {string} */ (
|
||||
hash.digest(options.hashDigest)
|
||||
|
||||
68
node_modules/webpack/lib/ids/IdHelpers.js
generated
vendored
68
node_modules/webpack/lib/ids/IdHelpers.js
generated
vendored
@@ -43,7 +43,7 @@ const avoidNumber = str => {
|
||||
} else if (firstChar > 57) {
|
||||
return str;
|
||||
}
|
||||
if (str === +str + "") {
|
||||
if (str === String(Number(str))) {
|
||||
return `_${str}`;
|
||||
}
|
||||
return str;
|
||||
@@ -53,12 +53,9 @@ const avoidNumber = str => {
|
||||
* @param {string} request the request
|
||||
* @returns {string} id representation
|
||||
*/
|
||||
const requestToId = request => {
|
||||
return request
|
||||
.replace(/^(\.\.?\/)+/, "")
|
||||
.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
|
||||
};
|
||||
exports.requestToId = requestToId;
|
||||
const requestToId = request =>
|
||||
request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
|
||||
module.exports.requestToId = requestToId;
|
||||
|
||||
/**
|
||||
* @param {string} string the string
|
||||
@@ -91,7 +88,7 @@ const getShortModuleName = (module, context, associatedObjectForCache) => {
|
||||
);
|
||||
return "";
|
||||
};
|
||||
exports.getShortModuleName = getShortModuleName;
|
||||
module.exports.getShortModuleName = getShortModuleName;
|
||||
|
||||
/**
|
||||
* @param {string} shortName the short name
|
||||
@@ -111,7 +108,7 @@ const getLongModuleName = (
|
||||
const fullName = getFullModuleName(module, context, associatedObjectForCache);
|
||||
return `${shortName}?${getHash(fullName, 4, hashFunction)}`;
|
||||
};
|
||||
exports.getLongModuleName = getLongModuleName;
|
||||
module.exports.getLongModuleName = getLongModuleName;
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
@@ -119,14 +116,9 @@ exports.getLongModuleName = getLongModuleName;
|
||||
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
||||
* @returns {string} full module name
|
||||
*/
|
||||
const getFullModuleName = (module, context, associatedObjectForCache) => {
|
||||
return makePathsRelative(
|
||||
context,
|
||||
module.identifier(),
|
||||
associatedObjectForCache
|
||||
);
|
||||
};
|
||||
exports.getFullModuleName = getFullModuleName;
|
||||
const getFullModuleName = (module, context, associatedObjectForCache) =>
|
||||
makePathsRelative(context, module.identifier(), associatedObjectForCache);
|
||||
module.exports.getFullModuleName = getFullModuleName;
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk the chunk
|
||||
@@ -156,7 +148,7 @@ const getShortChunkName = (
|
||||
.join(delimiter);
|
||||
return shortenLongString(chunkName, delimiter, hashFunction);
|
||||
};
|
||||
exports.getShortChunkName = getShortChunkName;
|
||||
module.exports.getShortChunkName = getShortChunkName;
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk the chunk
|
||||
@@ -191,7 +183,7 @@ const getLongChunkName = (
|
||||
.join(delimiter);
|
||||
return shortenLongString(chunkName, delimiter, hashFunction);
|
||||
};
|
||||
exports.getLongChunkName = getLongChunkName;
|
||||
module.exports.getLongChunkName = getLongChunkName;
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk the chunk
|
||||
@@ -213,7 +205,7 @@ const getFullChunkName = (
|
||||
);
|
||||
return fullModuleNames.join();
|
||||
};
|
||||
exports.getFullChunkName = getFullChunkName;
|
||||
module.exports.getFullChunkName = getFullChunkName;
|
||||
|
||||
/**
|
||||
* @template K
|
||||
@@ -246,7 +238,7 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
|
||||
const usedIds = new Set();
|
||||
if (compilation.usedModuleIds) {
|
||||
for (const id of compilation.usedModuleIds) {
|
||||
usedIds.add(id + "");
|
||||
usedIds.add(String(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,20 +246,18 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
|
||||
if (!module.needId) continue;
|
||||
const moduleId = chunkGraph.getModuleId(module);
|
||||
if (moduleId !== null) {
|
||||
usedIds.add(moduleId + "");
|
||||
} else {
|
||||
if (
|
||||
(!filter || filter(module)) &&
|
||||
chunkGraph.getNumberOfModuleChunks(module) !== 0
|
||||
) {
|
||||
modules.push(module);
|
||||
}
|
||||
usedIds.add(String(moduleId));
|
||||
} else if (
|
||||
(!filter || filter(module)) &&
|
||||
chunkGraph.getNumberOfModuleChunks(module) !== 0
|
||||
) {
|
||||
modules.push(module);
|
||||
}
|
||||
}
|
||||
|
||||
return [usedIds, modules];
|
||||
};
|
||||
exports.getUsedModuleIdsAndModules = getUsedModuleIdsAndModules;
|
||||
module.exports.getUsedModuleIdsAndModules = getUsedModuleIdsAndModules;
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation
|
||||
@@ -278,20 +268,20 @@ const getUsedChunkIds = compilation => {
|
||||
const usedIds = new Set();
|
||||
if (compilation.usedChunkIds) {
|
||||
for (const id of compilation.usedChunkIds) {
|
||||
usedIds.add(id + "");
|
||||
usedIds.add(String(id));
|
||||
}
|
||||
}
|
||||
|
||||
for (const chunk of compilation.chunks) {
|
||||
const chunkId = chunk.id;
|
||||
if (chunkId !== null) {
|
||||
usedIds.add(chunkId + "");
|
||||
usedIds.add(String(chunkId));
|
||||
}
|
||||
}
|
||||
|
||||
return usedIds;
|
||||
};
|
||||
exports.getUsedChunkIds = getUsedChunkIds;
|
||||
module.exports.getUsedChunkIds = getUsedChunkIds;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
@@ -359,7 +349,7 @@ const assignNames = (
|
||||
unnamedItems.sort(comparator);
|
||||
return unnamedItems;
|
||||
};
|
||||
exports.assignNames = assignNames;
|
||||
module.exports.assignNames = assignNames;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
@@ -413,7 +403,7 @@ const assignDeterministicIds = (
|
||||
} while (!assignId(item, id));
|
||||
}
|
||||
};
|
||||
exports.assignDeterministicIds = assignDeterministicIds;
|
||||
module.exports.assignDeterministicIds = assignDeterministicIds;
|
||||
|
||||
/**
|
||||
* @param {Set<string>} usedIds used ids
|
||||
@@ -432,7 +422,7 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
|
||||
*/
|
||||
assignId = module => {
|
||||
if (chunkGraph.getModuleId(module) === null) {
|
||||
while (usedIds.has(nextId + "")) nextId++;
|
||||
while (usedIds.has(String(nextId))) nextId++;
|
||||
chunkGraph.setModuleId(module, nextId++);
|
||||
}
|
||||
};
|
||||
@@ -450,7 +440,7 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
|
||||
assignId(module);
|
||||
}
|
||||
};
|
||||
exports.assignAscendingModuleIds = assignAscendingModuleIds;
|
||||
module.exports.assignAscendingModuleIds = assignAscendingModuleIds;
|
||||
|
||||
/**
|
||||
* @param {Iterable<Chunk>} chunks the chunks
|
||||
@@ -464,7 +454,7 @@ const assignAscendingChunkIds = (chunks, compilation) => {
|
||||
if (usedIds.size > 0) {
|
||||
for (const chunk of chunks) {
|
||||
if (chunk.id === null) {
|
||||
while (usedIds.has(nextId + "")) nextId++;
|
||||
while (usedIds.has(String(nextId))) nextId++;
|
||||
chunk.id = nextId;
|
||||
chunk.ids = [nextId];
|
||||
nextId++;
|
||||
@@ -480,4 +470,4 @@ const assignAscendingChunkIds = (chunks, compilation) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.assignAscendingChunkIds = assignAscendingChunkIds;
|
||||
module.exports.assignAscendingChunkIds = assignAscendingChunkIds;
|
||||
|
||||
9
node_modules/webpack/lib/ids/SyncModuleIdsPlugin.js
generated
vendored
9
node_modules/webpack/lib/ids/SyncModuleIdsPlugin.js
generated
vendored
@@ -10,6 +10,7 @@ const { getUsedModuleIdsAndModules } = require("./IdHelpers");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||
|
||||
const plugin = "SyncModuleIdsPlugin";
|
||||
|
||||
@@ -42,7 +43,9 @@ class SyncModuleIdsPlugin {
|
||||
let dataChanged = false;
|
||||
if (this._read) {
|
||||
compiler.hooks.readRecords.tapAsync(plugin, callback => {
|
||||
const fs = compiler.intermediateFileSystem;
|
||||
const fs =
|
||||
/** @type {IntermediateFileSystem} */
|
||||
(compiler.intermediateFileSystem);
|
||||
fs.readFile(this._path, (err, buffer) => {
|
||||
if (err) {
|
||||
if (err.code !== "ENOENT") {
|
||||
@@ -69,7 +72,9 @@ class SyncModuleIdsPlugin {
|
||||
for (const [key, value] of sorted) {
|
||||
json[key] = value;
|
||||
}
|
||||
const fs = compiler.intermediateFileSystem;
|
||||
const fs =
|
||||
/** @type {IntermediateFileSystem} */
|
||||
(compiler.intermediateFileSystem);
|
||||
fs.writeFile(this._path, JSON.stringify(json), callback);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user