File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 "build" : " tsc && eslint" ,
2020 "compile" : " tsc" ,
2121 "lint" : " eslint" ,
22+ "check-node-version" : " node ./scripts/check-node-version.mjs" ,
2223 "readme:gen" : " node scripts/readme-gen.mjs" ,
23- "start" : " tsx ./src/helloWorldRunner.ts" ,
24- "start-sample" : " tsx ./src/index.ts" ,
25- "xl1" : " xl1 ."
24+ "start" : " node ./scripts/check-node-version.mjs && tsx ./src/helloWorldRunner.ts" ,
25+ "start-sample" : " node ./scripts/check-node-version.mjs && tsx ./src/index.ts"
2626 },
2727 "dependencies" : {
2828 "@xylabs/assert" : " ~5.0.0" ,
4848 "typescript" : " ~5.8.3"
4949 },
5050 "engines" : {
51- "node" : " >=22"
51+ "node" : " >=22.0.0 <23.0.0 || >=24.0.0 <25.0.0 "
5252 },
5353 "volta" : {
5454 "node" : " 22.5.1" ,
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import fs from 'node:fs'
4+ import path from 'node:path'
5+ import { fileURLToPath } from 'node:url'
6+ import semver from 'semver'
7+
8+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
9+
10+ // Step 1: Read package.json
11+ const packageJsonPath = path . resolve ( __dirname , '../package.json' )
12+
13+ let packageJson
14+ try {
15+ const raw = fs . readFileSync ( packageJsonPath , 'utf-8' )
16+ packageJson = JSON . parse ( raw )
17+ } catch ( err ) {
18+ console . error ( '❌ Failed to read package.json:' , err . message )
19+ process . exit ( 1 )
20+ }
21+
22+ // Step 2: Extract engines.node
23+ const requiredNode = packageJson . engines ?. node
24+
25+ if ( ! requiredNode ) {
26+ console . warn ( '⚠️ No "engines.node" field found in package.json.' )
27+ process . exit ( 0 ) // No check needed
28+ }
29+
30+ // Step 3: Check current version
31+ const currentVersion = process . versions . node
32+
33+ if ( semver . satisfies ( currentVersion , requiredNode ) ) {
34+ console . log ( `✅ Node.js ${ currentVersion } satisfies "${ requiredNode } ".` )
35+ process . exit ( 0 )
36+ } else {
37+ console . error ( `❌ Node.js ${ currentVersion } does NOT satisfy "engines.node": "${ requiredNode } ".` )
38+ process . exit ( 1 )
39+ }
You can’t perform that action at this time.
0 commit comments