File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 "sideEffects" : false ,
2222 "type" : " module" ,
2323 "scripts" : {
24- "build" : " vite build --mode production" ,
24+ "check-node-version" : " node ./scripts/check-node-version.mjs" ,
25+ "build" : " npm run check-node-version && vite build --mode production" ,
2526 "lint" : " eslint" ,
2627 "package-build" : " npm run build" ,
2728 "serve" : " npm run build && npx serve ./build" ,
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