Skip to content

Commit b7df48c

Browse files
committed
refactor(node): use NODE_VERSION constant instead of repeated process.version access
1 parent 184a286 commit b7df48c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/constants/node.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
* Node.js runtime: versions, features, flags, and capabilities.
33
*/
44

5+
const NODE_VERSION = process.version
6+
57
// Version detection.
68
export function getNodeVersion(): string {
7-
return process.version
9+
return NODE_VERSION
810
}
911

1012
export function getNodeMajorVersion(): number {
11-
return Number.parseInt(process.version.slice(1).split('.')[0] || '0', 10)
13+
return Number.parseInt(NODE_VERSION.slice(1).split('.')[0] || '0', 10)
1214
}
1315

1416
// Maintained Node.js versions.
@@ -64,7 +66,7 @@ export function supportsNodeRequireModule(): boolean {
6466
return (
6567
major >= 23 ||
6668
(major === 22 &&
67-
Number.parseInt(process.version.split('.')[1] || '0', 10) >= 12)
69+
Number.parseInt(NODE_VERSION.split('.')[1] || '0', 10) >= 12)
6870
)
6971
}
7072

@@ -73,7 +75,7 @@ export function supportsNodeRun(): boolean {
7375
return (
7476
major >= 23 ||
7577
(major === 22 &&
76-
Number.parseInt(process.version.split('.')[1] || '0', 10) >= 11)
78+
Number.parseInt(NODE_VERSION.split('.')[1] || '0', 10) >= 11)
7779
)
7880
}
7981

@@ -82,15 +84,15 @@ export function supportsNodeDisableSigusr1Flag(): boolean {
8284
// --disable-sigusr1 added in v22.14.0, v23.7.0.
8385
// Stabilized in v22.20.0, v24.8.0.
8486
if (major >= 24) {
85-
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
87+
const minor = Number.parseInt(NODE_VERSION.split('.')[1] || '0', 10)
8688
return minor >= 8
8789
}
8890
if (major === 23) {
89-
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
91+
const minor = Number.parseInt(NODE_VERSION.split('.')[1] || '0', 10)
9092
return minor >= 7
9193
}
9294
if (major === 22) {
93-
const minor = Number.parseInt(process.version.split('.')[1] || '0', 10)
95+
const minor = Number.parseInt(NODE_VERSION.split('.')[1] || '0', 10)
9496
return minor >= 14
9597
}
9698
return false

0 commit comments

Comments
 (0)