From 6be5b89f84b21b0f5299bf2b333aabe65e840a88 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Tue, 27 Jun 2023 18:10:55 +0200 Subject: [PATCH] feat: expose the v8 flags with our node introspection mechanism --- packages/core/src/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0bed7dc..afc170c 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,36 @@ +import { writeFileSync } from "fs"; import path from "path"; + +const getV8Flags = (nodeVersionMajor: number) => { + const flags = [ + "--hash-seed=1", + "--random-seed=1", + "--no-opt", + "--predictable", + "--predictable-gc-schedule", + ]; + if (nodeVersionMajor < 18) { + flags.push("--no-randomize-hashes"); + } + if (nodeVersionMajor < 20) { + flags.push("--no-scavenge-task"); + } + return flags; +}; + +if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== undefined) { + const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); + + const introspectionMetadata = { + flags: getV8Flags(nodeVersionMajor), + }; + writeFileSync( + process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__, + JSON.stringify(introspectionMetadata) + ); + process.exit(0); +} + declare const __VERSION__: string; /* eslint-disable @typescript-eslint/no-empty-function */