diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0bed7dc..3acc795 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,3 +1,4 @@ +import { writeFileSync } from "fs"; import path from "path"; declare const __VERSION__: string; @@ -33,6 +34,31 @@ export const initCore = () => { require("v8").setFlagsFromString("--allow-natives-syntax"); } measurement.stopInstrumentation(`Metadata: codspeed-node ${__VERSION__}`); + + if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== undefined) { + const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); + 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"); + } + const introspectionMetadata = { + flags, + }; + writeFileSync( + process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__, + JSON.stringify(introspectionMetadata) + ); + process.exit(213); + } }; export const optimizeFunction = async (fn: CallableFunction) => {