From 8d2afe328e754d61a8819bd226f260ec7d07a8ff Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 4 Nov 2024 16:02:21 +0800 Subject: [PATCH 1/2] perf(CLI): enable Node cache before loading modules --- packages/core/bin/rslib.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/bin/rslib.js b/packages/core/bin/rslib.js index 79da1723e..995c098fc 100755 --- a/packages/core/bin/rslib.js +++ b/packages/core/bin/rslib.js @@ -1,7 +1,19 @@ #!/usr/bin/env node -import { logger, prepareCli, runCli } from '../dist/index.js'; +import nodeModule from 'node:module'; + +// enable on-disk code caching of all modules loaded by Node.js +// requires Nodejs >= 22.8.0 +const { enableCompileCache } = nodeModule; +if (enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { + try { + enableCompileCache(); + } catch { + // ignore errors + } +} async function main() { + const { logger, prepareCli, runCli } = await import('../dist/index.js'); prepareCli(); try { From 7456f29a42afa152233c42775642b87474df8194 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 4 Nov 2024 16:08:57 +0800 Subject: [PATCH 2/2] fix: no need for NODE_DISABLE_COMPILE_CACHE --- packages/core/bin/rslib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/bin/rslib.js b/packages/core/bin/rslib.js index 995c098fc..665f09b3f 100755 --- a/packages/core/bin/rslib.js +++ b/packages/core/bin/rslib.js @@ -4,7 +4,7 @@ import nodeModule from 'node:module'; // enable on-disk code caching of all modules loaded by Node.js // requires Nodejs >= 22.8.0 const { enableCompileCache } = nodeModule; -if (enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { +if (enableCompileCache) { try { enableCompileCache(); } catch {