Skip to content

Commit 5afca1a

Browse files
committed
feat(core): warn when running on an untested Node.js version
The plugins ship ABI-pinned prebuilds for Node.js 22 and 24 only, so any other major silently fails to load the native addon with no hint that the runtime version is the cause. Emit the warning before the native-binding check in setupCore, so the version is still printed on the majors where the addon cannot load and setupCore throws. The playwright plugin gets its own call because it registers the integration itself and bypasses setupCore. COD-3399
1 parent 0433753 commit 5afca1a

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎packages/core/src/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { checkV8Flags } from "./introspection";
22
import { MongoMeasurement } from "./mongoMeasurement";
33
import native_core from "./native_core";
4+
import { warnOnUnsupportedNodeVersion } from "./nodeVersion";
45
import { getCodspeedRunnerMode } from "./runnerMode";
56

67
declare const __VERSION__: string;
@@ -12,6 +13,8 @@ export const isBound = native_core.isBound;
1213
export const mongoMeasurement = new MongoMeasurement();
1314

1415
export const setupCore = () => {
16+
warnOnUnsupportedNodeVersion();
17+
1518
if (!native_core.isBound) {
1619
throw new Error(
1720
"Native core module is not bound, CodSpeed integration will not work properly",
@@ -44,6 +47,11 @@ export type {
4447
SetupInstrumentsResponse,
4548
} from "./generated/openapi";
4649
export { getV8Flags, tryIntrospect } from "./introspection";
50+
export {
51+
getUnsupportedNodeVersionWarning,
52+
SUPPORTED_NODE_MAJORS,
53+
warnOnUnsupportedNodeVersion,
54+
} from "./nodeVersion";
4755
export { optimizeFunction, optimizeFunctionSync } from "./optimization";
4856
export { wrapWithRootFrame, wrapWithRootFrameSync } from "./rootFrame";
4957
export * from "./utils";

‎packages/core/src/nodeVersion.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Majors the native addon ships prebuilds for, as listed in the
3+
* `build-native-addon` targets in package.json. Prebuilds are matched on the
4+
* exact ABI version, so on any other major the addon only loads when it has
5+
* been compiled from source locally.
6+
*/
7+
export const SUPPORTED_NODE_MAJORS = [22, 24];
8+
9+
export function getUnsupportedNodeVersionWarning(
10+
version: string,
11+
): string | null {
12+
const major = parseInt(version.split(".")[0], 10);
13+
if (SUPPORTED_NODE_MAJORS.includes(major)) {
14+
return null;
15+
}
16+
return `[CodSpeed] Node.js v${version} is not supported: CodSpeed is tested on Node.js ${SUPPORTED_NODE_MAJORS.join(", ")}. Support for other versions is experimental and measurements may be unstable.`;
17+
}
18+
19+
let hasWarned = false;
20+
21+
/**
22+
* Integrations call their setup path per suite or per worker, so the warning is
23+
* latched to once per process.
24+
*/
25+
export function warnOnUnsupportedNodeVersion(): void {
26+
if (hasWarned) {
27+
return;
28+
}
29+
const warning = getUnsupportedNodeVersionWarning(process.versions.node);
30+
if (warning === null) {
31+
return;
32+
}
33+
hasWarned = true;
34+
console.warn(warning);
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
export {}; // Make this a module
3+
4+
const { getUnsupportedNodeVersionWarning } = require("..") as {
5+
getUnsupportedNodeVersionWarning: (version: string) => string | null;
6+
};
7+
8+
describe("getUnsupportedNodeVersionWarning", () => {
9+
it.each(["22.22.2", "24.19.0"])("should not warn on Node %s", (version) => {
10+
expect(getUnsupportedNodeVersionWarning(version)).toBeNull();
11+
});
12+
13+
it.each(["20.5.1", "23.11.0", "26.0.0"])(
14+
"should warn on Node %s",
15+
(version) => {
16+
expect(getUnsupportedNodeVersionWarning(version)).toBe(
17+
`[CodSpeed] Node.js v${version} is not supported: CodSpeed is tested on Node.js 22, 24. Support for other versions is experimental and measurements may be unstable.`,
18+
);
19+
},
20+
);
21+
});

‎packages/playwright-plugin/src/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
MARKER_TYPE_BENCHMARK_END,
66
MARKER_TYPE_BENCHMARK_START,
77
msToS,
8+
warnOnUnsupportedNodeVersion,
89
writeWalltimeResults,
910
type Benchmark,
1011
type BenchmarkStats,
@@ -101,6 +102,8 @@ function ensureIntegrationSetup(): void {
101102
if (integrationInitialized) return;
102103
integrationInitialized = true;
103104

105+
warnOnUnsupportedNodeVersion();
106+
104107
InstrumentHooks.setIntegration("node-custom", __VERSION__);
105108
InstrumentHooks.setEnvironment("nodejs", "version", process.versions.node);
106109
InstrumentHooks.setEnvironment("nodejs", "v8", process.versions.v8);

0 commit comments

Comments
 (0)