Skip to content

Commit 8588ef3

Browse files
authored
feat: Check Node Version (#8)
Check the Node version being ran and exit out if using an incompatible Node version.
1 parent f6982a1 commit 8588ef3

File tree

8 files changed

+90
-4
lines changed

8 files changed

+90
-4
lines changed

bundlers/next-js/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
"@/*": ["./src/*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": [
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
".next/types/**/*.ts",
30+
"next.config.js"
31+
],
2632
"exclude": ["node_modules"]
2733
}

bundlers/vite/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"@codecov/vite-plugin": "workspace:^",
2727
"typescript": "^5.0.2",
2828
"vite": "^4.4.5"
29+
},
30+
"volta": {
31+
"extends": "../../package.json"
2932
}
3033
}

bundlers/webpack/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"dependencies": {
1717
"@codecov/webpack-plugin": "workspace:^",
1818
"lodash": "^4.17.21"
19+
},
20+
"volta": {
21+
"extends": "../../package.json"
1922
}
2023
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
"engines": {
3636
"node": ">=20.0.0"
3737
}
38-
}
38+
}

packages/bundler-plugin-core/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535
"author": "",
3636
"license": "Apache-2.0",
3737
"dependencies": {
38+
"chalk": "4.1.2",
39+
"semver": "^7.5.4",
3840
"unplugin": "^1.5.0",
3941
"zod": "^3.22.4"
4042
},
4143
"devDependencies": {
4244
"@types/node": "^20.8.6",
45+
"@types/semver": "^7.5.5",
4346
"typescript": "^5.0.4",
4447
"unbuild": "^2.0.0"
4548
},

packages/bundler-plugin-core/src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { type UnpluginOptions, createUnplugin } from "unplugin";
2+
import { satisfies } from "semver";
3+
import { z } from "zod";
4+
25
import {
36
type BundleAnalysisUploadPlugin,
47
type Asset,
@@ -9,17 +12,27 @@ import {
912
} from "./types.js";
1013

1114
import { jsonSchema } from "./schemas.js";
12-
import { z } from "zod";
15+
import { red } from "./utils/logging.js";
16+
17+
const NODE_VERSION_RANGE = ">=18.18.0";
18+
1319
interface CodecovUnpluginFactoryOptions {
1420
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin;
1521
}
1622

1723
export function codecovUnpluginFactory({
1824
bundleAnalysisUploadPlugin,
1925
}: CodecovUnpluginFactoryOptions) {
20-
return createUnplugin<Options, true>((userOptions, _unpluginMetaContext) => {
26+
return createUnplugin<Options, true>((userOptions, unpluginMetaContext) => {
2127
const plugins: UnpluginOptions[] = [];
2228

29+
if (!satisfies(process.version, NODE_VERSION_RANGE)) {
30+
red(
31+
`Codecov ${unpluginMetaContext.framework} bundler plugin requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,
32+
);
33+
process.exit(1);
34+
}
35+
2336
if (userOptions?.enableBundleAnalysis) {
2437
const statsFileName = z
2538
.string()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Chalk from "chalk";
2+
3+
export function prepareMessage(msg: unknown): string {
4+
if (typeof msg === "string") {
5+
return msg;
6+
}
7+
if (msg instanceof Error) {
8+
return `${msg.stack ?? ""}`;
9+
}
10+
return JSON.stringify(msg, null, "\t");
11+
}
12+
13+
export function l(msg: string): void {
14+
console.log(msg);
15+
}
16+
17+
export function nl(): void {
18+
return l("");
19+
}
20+
21+
export function green(msg: string): void {
22+
return l(Chalk.green(prepareMessage(msg)));
23+
}
24+
25+
export function red(msg: string): void {
26+
return l(Chalk.red(prepareMessage(msg)));
27+
}
28+
29+
export function dim(msg: string): void {
30+
return l(Chalk.dim(prepareMessage(msg)));
31+
}
32+
33+
export function yellow(msg: string): void {
34+
return l(Chalk.yellow(prepareMessage(msg)));
35+
}
36+
37+
export function cyan(msg: string): void {
38+
return l(Chalk.cyan(prepareMessage(msg)));
39+
}
40+
41+
// Disable eslint because we want to allow any type of message when debugging
42+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
43+
export function debug(msg: any): void {
44+
return l(Chalk.italic.yellow(prepareMessage(msg)));
45+
}

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)