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

@@ -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;