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

@@ -11,9 +11,7 @@ const Watchpack = require("watchpack");
/** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
/** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
/** @typedef {import("../util/fs").WatchFileSystem} WatchFileSystem */
/** @typedef {import("../util/fs").WatchMethod} WatchMethod */
/** @typedef {import("../util/fs").Watcher} Watcher */
class NodeWatchFileSystem {
/**
@@ -24,19 +22,11 @@ class NodeWatchFileSystem {
this.watcherOptions = {
aggregateTimeout: 0
};
/** @type {Watchpack | null} */
this.watcher = new Watchpack(this.watcherOptions);
}
/**
* @param {Iterable<string>} files watched files
* @param {Iterable<string>} directories watched directories
* @param {Iterable<string>} missing watched existence entries
* @param {number} startTime timestamp of start time
* @param {WatchOptions} options options object
* @param {function(Error | null, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
* @param {function(string, number): void} callbackUndelayed callback when the first change was detected
* @returns {Watcher} a watcher
*/
/** @type {WatchMethod} */
watch(
files,
directories,
@@ -93,7 +83,8 @@ class NodeWatchFileSystem {
*/
(changes, removals) => {
// pause emitting events (avoids clearing aggregated changes and removals on timeout)
this.watcher.pause();
/** @type {Watchpack} */
(this.watcher).pause();
const fs = this.inputFileSystem;
if (fs && fs.purge) {
@@ -161,16 +152,12 @@ class NodeWatchFileSystem {
"DEP_WEBPACK_WATCHER_GET_AGGREGATED_CHANGES"
),
getFileTimeInfoEntries: util.deprecate(
() => {
return fetchTimeInfo().fileTimeInfoEntries;
},
() => fetchTimeInfo().fileTimeInfoEntries,
"Watcher.getFileTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
"DEP_WEBPACK_WATCHER_FILE_TIME_INFO_ENTRIES"
),
getContextTimeInfoEntries: util.deprecate(
() => {
return fetchTimeInfo().contextTimeInfoEntries;
},
() => fetchTimeInfo().contextTimeInfoEntries,
"Watcher.getContextTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
"DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES"
),

View File

@@ -43,7 +43,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
rootOutputDir
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}`
: "__filename"
});`;
}
@@ -227,7 +227,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
Template.indent([
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
Template.indent([
`currentUpdate[moduleId] = updatedModules[moduleId];`,
"currentUpdate[moduleId] = updatedModules[moduleId];",
"if(updatedModulesList) updatedModulesList.push(moduleId);"
]),
"}"

View File

@@ -18,6 +18,7 @@ class ReadFileCompileAsyncWasmPlugin {
this._type = type;
this._import = useImport;
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
@@ -89,26 +90,28 @@ class ReadFileCompileAsyncWasmPlugin {
compilation.hooks.runtimeRequirementInTree
.for(RuntimeGlobals.instantiateWasm)
.tap("ReadFileCompileAsyncWasmPlugin", (chunk, set) => {
if (!isEnabledForChunk(chunk)) return;
const chunkGraph = compilation.chunkGraph;
if (
!chunkGraph.hasModuleInGraph(
.tap(
"ReadFileCompileAsyncWasmPlugin",
(chunk, set, { chunkGraph }) => {
if (!isEnabledForChunk(chunk)) return;
if (
!chunkGraph.hasModuleInGraph(
chunk,
m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
)
) {
return;
}
set.add(RuntimeGlobals.publicPath);
compilation.addRuntimeModule(
chunk,
m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
)
) {
return;
new AsyncWasmLoadingRuntimeModule({
generateLoadBinaryCode,
supportsStreaming: false
})
);
}
set.add(RuntimeGlobals.publicPath);
compilation.addRuntimeModule(
chunk,
new AsyncWasmLoadingRuntimeModule({
generateLoadBinaryCode,
supportsStreaming: false
})
);
});
);
}
);
}

View File

@@ -81,9 +81,8 @@ class ReadFileCompileWasmPlugin {
compilation.hooks.runtimeRequirementInTree
.for(RuntimeGlobals.ensureChunkHandlers)
.tap("ReadFileCompileWasmPlugin", (chunk, set) => {
.tap("ReadFileCompileWasmPlugin", (chunk, set, { chunkGraph }) => {
if (!isEnabledForChunk(chunk)) return;
const chunkGraph = compilation.chunkGraph;
if (
!chunkGraph.hasModuleInGraph(
chunk,

View File

@@ -43,7 +43,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
rootOutputDir !== "./"
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}`
: "__filename"
});`;
}
@@ -189,7 +189,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
Template.indent([
`if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
Template.indent([
`currentUpdate[moduleId] = updatedModules[moduleId];`,
"currentUpdate[moduleId] = updatedModules[moduleId];",
"if(updatedModulesList) updatedModulesList.push(moduleId);"
]),
"}"

View File

@@ -19,7 +19,7 @@ const truncateArgs = require("../logging/truncateArgs");
*/
module.exports = ({ colors, appendOnly, stream }) => {
/** @type {string[] | undefined} */
let currentStatusMessage = undefined;
let currentStatusMessage;
let hasStatusMessage = false;
let currentIndent = "";
let currentCollapsed = 0;
@@ -38,17 +38,17 @@ module.exports = ({ colors, appendOnly, stream }) => {
return (
prefix +
colorPrefix +
str.replace(/\n/g, colorSuffix + "\n" + prefix + colorPrefix) +
str.replace(/\n/g, `${colorSuffix}\n${prefix}${colorPrefix}`) +
colorSuffix
);
} else {
return prefix + str.replace(/\n/g, "\n" + prefix);
}
return prefix + str.replace(/\n/g, `\n${prefix}`);
};
const clearStatusMessage = () => {
if (hasStatusMessage) {
stream.write("\x1b[2K\r");
stream.write("\u001B[2K\r");
hasStatusMessage = false;
}
};
@@ -58,8 +58,8 @@ module.exports = ({ colors, appendOnly, stream }) => {
const l = /** @type {TODO} */ (stream).columns || 40;
const args = truncateArgs(currentStatusMessage, l - 1);
const str = args.join(" ");
const coloredStr = `\u001b[1m${str}\u001b[39m\u001b[22m`;
stream.write(`\x1b[2K\r${coloredStr}`);
const coloredStr = `\u001B[1m${str}\u001B[39m\u001B[22m`;
stream.write(`\u001B[2K\r${coloredStr}`);
hasStatusMessage = true;
};
@@ -67,10 +67,11 @@ module.exports = ({ colors, appendOnly, stream }) => {
* @param {string} prefix prefix
* @param {string} colorPrefix color prefix
* @param {string} colorSuffix color suffix
* @returns {(function(...any[]): void)} function to write with colors
* @returns {(function(...EXPECTED_ANY[]): void)} function to write with colors
*/
const writeColored = (prefix, colorPrefix, colorSuffix) => {
return (...args) => {
const writeColored =
(prefix, colorPrefix, colorSuffix) =>
(...args) => {
if (currentCollapsed > 0) return;
clearStatusMessage();
const str = indent(
@@ -79,34 +80,33 @@ module.exports = ({ colors, appendOnly, stream }) => {
colorPrefix,
colorSuffix
);
stream.write(str + "\n");
stream.write(`${str}\n`);
writeStatusMessage();
};
};
const writeGroupMessage = writeColored(
"<-> ",
"\u001b[1m\u001b[36m",
"\u001b[39m\u001b[22m"
"\u001B[1m\u001B[36m",
"\u001B[39m\u001B[22m"
);
const writeGroupCollapsedMessage = writeColored(
"<+> ",
"\u001b[1m\u001b[36m",
"\u001b[39m\u001b[22m"
"\u001B[1m\u001B[36m",
"\u001B[39m\u001B[22m"
);
return {
log: writeColored(" ", "\u001b[1m", "\u001b[22m"),
log: writeColored(" ", "\u001B[1m", "\u001B[22m"),
debug: writeColored(" ", "", ""),
trace: writeColored(" ", "", ""),
info: writeColored("<i> ", "\u001b[1m\u001b[32m", "\u001b[39m\u001b[22m"),
warn: writeColored("<w> ", "\u001b[1m\u001b[33m", "\u001b[39m\u001b[22m"),
error: writeColored("<e> ", "\u001b[1m\u001b[31m", "\u001b[39m\u001b[22m"),
info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"),
warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"),
error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"),
logTime: writeColored(
"<t> ",
"\u001b[1m\u001b[35m",
"\u001b[39m\u001b[22m"
"\u001B[1m\u001B[35m",
"\u001B[39m\u001B[22m"
),
group: (...args) => {
writeGroupMessage(...args);
@@ -123,18 +123,21 @@ module.exports = ({ colors, appendOnly, stream }) => {
groupEnd: () => {
if (currentCollapsed > 0) currentCollapsed--;
else if (currentIndent.length >= 2)
currentIndent = currentIndent.slice(0, currentIndent.length - 2);
currentIndent = currentIndent.slice(0, -2);
},
profile: console.profile && (name => console.profile(name)),
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
clear:
!appendOnly &&
console.clear &&
(() => {
clearStatusMessage();
console.clear();
writeStatusMessage();
}),
/** @type {() => void} */
(
!appendOnly &&
console.clear &&
(() => {
clearStatusMessage();
console.clear();
writeStatusMessage();
})
),
status: appendOnly
? writeColored("<s> ", "", "")
: (name, ...args) => {