mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
Fix several lints (#19121)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import path from "node:path";
|
||||
import NodeErrors from "../bun.js/bindings/ErrorCode.ts";
|
||||
import { writeIfNotChanged } from "./helpers.ts";
|
||||
const outputDir = process.argv[2];
|
||||
|
||||
if (!outputDir) {
|
||||
@@ -91,7 +92,7 @@ for (let [code, constructor, name, ...other_constructors] of NodeErrors) {
|
||||
if (name == null) name = constructor.name;
|
||||
|
||||
// it's useful to avoid the prefix, but module not found has a prefixed and unprefixed version
|
||||
const codeWithoutPrefix = code === 'ERR_MODULE_NOT_FOUND' ? code : code.replace(/^ERR_/, '');
|
||||
const codeWithoutPrefix = code === "ERR_MODULE_NOT_FOUND" ? code : code.replace(/^ERR_/, "");
|
||||
|
||||
enumHeader += ` ${code} = ${i},\n`;
|
||||
listHeader += ` { JSC::ErrorType::${constructor.name}, "${name}"_s, "${code}"_s },\n`;
|
||||
@@ -148,6 +149,35 @@ zig += `
|
||||
};
|
||||
`;
|
||||
|
||||
await Bun.write(path.join(outputDir, "ErrorCode+List.h"), enumHeader);
|
||||
await Bun.write(path.join(outputDir, "ErrorCode+Data.h"), listHeader);
|
||||
await Bun.write(path.join(outputDir, "ErrorCode.zig"), zig);
|
||||
let builtindtsPath = path.join(import.meta.dir, "..", "..", "src", "js", "builtins.d.ts");
|
||||
let builtindts = await Bun.file(builtindtsPath).text();
|
||||
|
||||
let dts = `
|
||||
// Generated by: src/codegen/generate-node-errors.ts
|
||||
// Input: src/bun.js/bindings/ErrorCode.ts
|
||||
|
||||
// Global error code functions for TypeScript
|
||||
`;
|
||||
for (const [code, constructor, name, ...other_constructors] of NodeErrors) {
|
||||
const hasExistingOverride = builtindts.includes(`declare function $${code}`);
|
||||
if (hasExistingOverride) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const namedError =
|
||||
name && name !== constructor.name
|
||||
? `${constructor.name} & { name: "${name}", code: "${code}" }`
|
||||
: `${constructor.name} & { code: "${code}" }`;
|
||||
dts += `
|
||||
/**
|
||||
* Construct an {@link ${constructor.name} ${constructor.name}} with the \`"${code}"\` error code.
|
||||
*
|
||||
* To override this, update ErrorCode.cpp. To remove this generated type, mention \`"${code}"\` in builtins.d.ts.
|
||||
*/
|
||||
declare function $${code}(message: string): ${namedError};\n`;
|
||||
}
|
||||
|
||||
writeIfNotChanged(path.join(outputDir, "ErrorCode+List.h"), enumHeader);
|
||||
writeIfNotChanged(path.join(outputDir, "ErrorCode+Data.h"), listHeader);
|
||||
writeIfNotChanged(path.join(outputDir, "ErrorCode.zig"), zig);
|
||||
writeIfNotChanged(path.join(outputDir, "ErrorCode.d.ts"), dts);
|
||||
|
||||
Reference in New Issue
Block a user