logancyang_obsidian-copilot/scripts/printPromptDebug.js
Zero Liu 2df1be0b4f
chore(lint): enable no-unsanitized/method and property (#2418)
Remove the explicit "off" overrides in eslint.config.mjs so the rules
from obsidianmd.configs.recommended apply. Add a scoped disable for the
sole violation in scripts/printPromptDebug.js, where the dynamic import
targets a controlled path under os.tmpdir() produced by esbuild.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 01:56:00 -07:00

62 lines
1.6 KiB
JavaScript
Executable file

#!/usr/bin/env node
/**
* Bundle the TypeScript entry file into a temporary ESM module and execute it.
*/
async function main() {
const [{ build }, fs, os, path, url] = await Promise.all([
import("esbuild"),
import("node:fs/promises"),
import("node:os"),
import("node:path"),
import("node:url"),
]);
const entryFile = path.resolve(__dirname, "printPromptDebugEntry.ts");
const outfile = path.join(os.tmpdir(), `prompt-debug-${Date.now()}.mjs`);
if (!Array.prototype.contains) {
Object.defineProperty(Array.prototype, "contains", {
value(value) {
return this.includes(value);
},
enumerable: false,
});
}
const obsidianStubPlugin = {
name: "obsidian-stub",
setup(build) {
build.onResolve({ filter: /^obsidian$/ }, () => ({
path: path.resolve(__dirname, "stubs/obsidian.ts"),
}));
},
};
await build({
entryPoints: [entryFile],
outfile,
bundle: true,
platform: "node",
format: "esm",
sourcemap: false,
target: "node18",
tsconfig: path.resolve(__dirname, "../tsconfig.json"),
plugins: [obsidianStubPlugin],
});
try {
// eslint-disable-next-line no-unsanitized/method -- outfile is a controlled path under os.tmpdir(), produced by the esbuild step above.
const module = await import(url.pathToFileURL(outfile).href);
await module.run(process.argv.slice(2));
} finally {
await fs.unlink(outfile).catch(() => {
/* ignore cleanup errors */
});
}
}
main().catch((error) => {
console.error("Failed to generate prompt debug report:", error);
process.exitCode = 1;
});