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 */