From 84793356f779ac8971a0f74969630821eba037d1 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 30 Sep 2024 14:43:21 +0200 Subject: [PATCH 1/3] perf(cli): enable node 22 compile cache --- lib/jiti-cli.mjs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/jiti-cli.mjs b/lib/jiti-cli.mjs index b9c89d4a..40d535d3 100755 --- a/lib/jiti-cli.mjs +++ b/lib/jiti-cli.mjs @@ -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]; @@ -10,8 +10,26 @@ 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 } = nodeModule.createRequire(import.meta.url)("./jiti.cjs"); +// 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); +}); From 2cc86516fb0c81874d8b0ce900ead79232e43613 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 30 Sep 2024 15:41:03 +0200 Subject: [PATCH 2/3] chore: update snapshot --- test/__snapshots__/fixtures.test.ts.snap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index f9ccafd9..cacd2844 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -37,7 +37,8 @@ exports[`fixtures > esm > stdout 1`] = ` 'at getStack (/test)', 'at test (/test)', 'at async /index.js', - 'at async Function.import (/dist/jiti.cjs)' + 'at async Function.import (/dist/jiti.cjs)', + 'at async file:///lib/jiti-cli.mjs' ] }" `; From b2af7b88f9cbb62547636706a971e116c6f6501a Mon Sep 17 00:00:00 2001 From: pooya Date: Mon, 30 Sep 2024 15:58:23 +0200 Subject: [PATCH 3/3] chore: remove cjs comment (diff is same) --- lib/jiti-cli.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jiti-cli.mjs b/lib/jiti-cli.mjs index 40d535d3..3bb3b9e9 100755 --- a/lib/jiti-cli.mjs +++ b/lib/jiti-cli.mjs @@ -22,8 +22,7 @@ if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { const pwd = process.cwd(); -const { createJiti } = nodeModule.createRequire(import.meta.url)("./jiti.cjs"); -// const { createJiti } = await import("./jiti.cjs"); +const { createJiti } = await import("./jiti.cjs"); const jiti = createJiti(pwd);