From 0b52ec6afbae037e52f95f4bdde9e066dc0829d6 Mon Sep 17 00:00:00 2001 From: chlorine Date: Sun, 17 Nov 2024 00:25:13 +0800 Subject: [PATCH] perf: use module.enableCompileCache in NodeJS v22 --- sources/corepackUtils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sources/corepackUtils.ts b/sources/corepackUtils.ts index 15e84056e..598cdd64b 100644 --- a/sources/corepackUtils.ts +++ b/sources/corepackUtils.ts @@ -403,9 +403,11 @@ export async function runVersion(locator: Locator, installSpec: InstallSpec & {s // Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache // $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version // [SIGSEGV] - if (locator.name !== `npm` || semverLt(locator.reference, `9.7.0`)) - // @ts-expect-error - No types - await import(`v8-compile-cache`); + if (locator.name !== `npm` || semverLt(locator.reference, `9.7.0`)) { + if (!Module.enableCompileCache?.()) + // @ts-expect-error - No types + await import(`v8-compile-cache`); + } // We load the binary into the current process, // while making it think it was spawned.