Skip to content

Commit

Permalink
fix: warn about node version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 20, 2024
1 parent 68690d4 commit 1dd6e10
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"is-wsl": "^2.2.0",
"lilconfig": "^3.1.2",
"minimatch": "^9.0.5",
"semver": "^7.6.3",
"string-width": "^4.2.3",
"supports-color": "^8",
"widest-line": "^3.1.0",
Expand Down
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {isTruthy} from './util/util'
function checkCWD() {
try {
process.cwd()
Expand All @@ -8,7 +9,25 @@ function checkCWD() {
}
}

function checkNodeVersion() {
if (process.env.OCLIF_DISABLE_ENGINE_WARNING && isTruthy(process.env.OCLIF_DISABLE_ENGINE_WARNING)) return
try {
const semver = require('semver')
const path = require('node:path')
const root = path.join(__dirname, '..')
const pjson = require(path.join(root, 'package.json'))
if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
process.emitWarning(
`Node version must be ${pjson.engines.node} to use this CLI. Current node version: ${process.versions.node}`,
)
}
} catch {
// ignore
}
}

checkCWD()
checkNodeVersion()

export * as Args from './args'
export {Command} from './command'
Expand Down

0 comments on commit 1dd6e10

Please sign in to comment.