Skip to content

Commit 5d4a240

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 3735985 commit 5d4a240

4 files changed

Lines changed: 68 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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Node.js majors the plugins are built and tested against: the example matrix
3+
* in .github/workflows/ci.yml and the prebuildify targets in package.json.
4+
*/
5+
export const SUPPORTED_NODE_MAJORS = [22, 24];
6+
7+
/**
8+
* Warning for a Node.js version outside the tested set, `null` when supported.
9+
*/
10+
export function getUnsupportedNodeVersionWarning(
11+
version: string,
12+
): string | null {
13+
const major = parseInt(version.split(".")[0], 10);
14+
if (SUPPORTED_NODE_MAJORS.includes(major)) {
15+
return null;
16+
}
17+
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.`;
18+
}
19+
20+
let hasWarned = false;
21+
22+
/**
23+
* Print the unsupported-version warning at most once per process. Integrations
24+
* call their setup path per suite or per worker.
25+
*/
26+
export function warnOnUnsupportedNodeVersion(): void {
27+
if (hasWarned) {
28+
return;
29+
}
30+
const warning = getUnsupportedNodeVersionWarning(process.versions.node);
31+
if (warning === null) {
32+
return;
33+
}
34+
hasWarned = true;
35+
console.warn(warning);
36+
}
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)