Skip to content

Commit

Permalink
perf(cli): enable node 22 compile cache (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Sep 30, 2024
1 parent 2ae340f commit 36e0957
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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

0 comments on commit 36e0957

Please sign in to comment.