chore: centralizing warning filters

This commit is contained in:
Gustavo Madeira Santana
2026-02-08 05:17:59 -05:00
parent cef9bfce22
commit 3119057161
5 changed files with 160 additions and 41 deletions

View File

@@ -11,13 +11,36 @@ if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
}
}
const isModuleNotFoundError = (err) =>
err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
const installProcessWarningFilter = async () => {
// Keep bootstrap warnings consistent with the TypeScript runtime.
for (const specifier of ["./dist/warning-filter.js", "./dist/warning-filter.mjs"]) {
try {
const mod = await import(specifier);
if (typeof mod.installProcessWarningFilter === "function") {
mod.installProcessWarningFilter();
return;
}
} catch (err) {
if (isModuleNotFoundError(err)) {
continue;
}
throw err;
}
}
};
await installProcessWarningFilter();
const tryImport = async (specifier) => {
try {
await import(specifier);
return true;
} catch (err) {
// Only swallow missing-module errors; rethrow real runtime errors.
if (err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND") {
if (isModuleNotFoundError(err)) {
return false;
}
throw err;