Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(cli): enable node 22 compile cache #312

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/jiti-cli.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { resolve } from "node:path";
import { createJiti } from "./jiti.cjs";
import nodeModule from "node:module";

const script = process.argv.splice(2, 1)[0];

Expand All @@ -10,8 +10,25 @@ if (!script) {
process.exit(1);
}

// https://nodejs.org/api/module.html#moduleenablecompilecachecachedir
// https://github.com/nodejs/node/pull/54501
if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
nodeModule.enableCompileCache();
} catch {
// Ignore errors
}
}

const pwd = process.cwd();

const { createJiti } = await import("./jiti.cjs");

const jiti = createJiti(pwd);

const resolved = (process.argv[1] = jiti.resolve(resolve(pwd, script)));

jiti.import(resolved).catch(console.error);
await jiti.import(resolved).catch((error) => {
console.error(error);
process.exit(1);
});
3 changes: 2 additions & 1 deletion test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ exports[`fixtures > esm > stdout 1`] = `
'at getStack (<cwd>/test)',
'at test (<cwd>/test)',
'at async <cwd>/index.js',
'at async Function.import (<root>/dist/jiti.cjs)'
'at async Function.import (<root>/dist/jiti.cjs)',
'at async file://<root>/lib/jiti-cli.mjs'
]
}"
`;
Expand Down
Loading