Skip to content

Commit

Permalink
fix(node): support npm passthrough when env isnt supported due to old…
Browse files Browse the repository at this point in the history
… node version (lirantal#25)
  • Loading branch information
lirantal authored Apr 14, 2018
1 parent 1ad4ccf commit 7e3a7e7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/npq-hero.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env node
'use strict'

// Require minimum node version or bail out
const cliSupport = require('../lib/helpers/cliSupportHandler')
cliSupport.isEnvSupport() ||
(cliSupport.noSupportError() && cliSupport.packageManagerPassthrough())

const inquirer = require('inquirer')
const yargs = require('yargs')
const pkgMgr = require('../lib/packageManager')
Expand Down
5 changes: 4 additions & 1 deletion bin/npq.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env node
'use strict'

const inquirer = require('inquirer')
// Require minimum node version or bail out
const cliSupport = require('../lib/helpers/cliSupportHandler')
cliSupport.isEnvSupport() || cliSupport.noSupportError(true)

const inquirer = require('inquirer')
const cli = require('../lib/cli')
const pkgMgr = require('../lib/packageManager')
const Marshall = require('../lib/marshall')
Expand Down
35 changes: 35 additions & 0 deletions lib/helpers/cliSupportHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

const chalk = require('chalk')
const childProcess = require('child_process')
const semver = require('semver')
const DEFAULT_PKGMGR = process.env.NPQ_PKG_MGR || 'npm'

const nodeVersion = process.versions.node

module.exports.isEnvSupport = function () {
if (!semver.satisfies(nodeVersion, '>=7.6.0')) {
return false
}

return true
}

module.exports.noSupportError = function (failFast) {
console.error(chalk.red('error:'), 'npq suppressed due to old node version')

if (failFast === true) {
process.exit(-1)
}

return true
}

module.exports.packageManagerPassthrough = function () {
const result = childProcess.spawnSync(DEFAULT_PKGMGR, process.argv.slice(2), {
stdio: 'inherit',
shell: true
})

process.exit(result.status)
}

0 comments on commit 7e3a7e7

Please sign in to comment.