diff --git a/.travis.yml b/.travis.yml index c7e5d33..78fe6b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ cache: yarn node_js: - '7' - '6' + - '4' diff --git a/cli.js b/cli.js index 79b0083..3309aab 100755 --- a/cli.js +++ b/cli.js @@ -1,16 +1,18 @@ #!/usr/bin/env node -const { spawn } = require('child_process') -const { bin, cwd, args, isYarn, isNPM } = require('./index') +'use strict' -if (!isYarn && !isNPM) { +const spawn = require('child_process').spawn +const nyr = require('./index') + +if (!nyr.isYarn && !nyr.isNPM) { throw new Error('Expected to be launched from either npm or yarn.') } -if (args.length < 2) { +if (nyr.args.length < 2) { throw new Error('Expected at least one argument with what script to run.') } -const child = spawn(bin, args, { cwd, stdio: 'inherit' }) +const child = spawn(nyr.bin, nyr.args, { cwd: nyr.cwd, stdio: 'inherit' }) child.on('exit', code => process.exit(code)) diff --git a/index.js b/index.js index c9c18fb..21c81ea 100755 --- a/index.js +++ b/index.js @@ -1,10 +1,7 @@ -const { - env: { npm_execpath: bin, DEBUG }, - argv, - cwd, -} = process +'use strict' -const args = argv.slice(2) +const bin = process.env.npm_execpath +const args = process.argv.slice(2) if (args[0] !== 'run') { args.unshift('run') @@ -13,13 +10,13 @@ if (args[0] !== 'run') { module.exports = { bin, args, - cwd: cwd(), + cwd: process.cwd(), isYarn: bin.endsWith('yarn.js'), isNPM: bin.endsWith('npm-cli.js'), } -if (DEBUG === 'nyr') { - const { inspect } = require('util') +if (process.env.DEBUG === 'nyr') { + const inspect = require('util').inspect const colors = process.stdout.isTTY console.log( '-- nyr DEBUG START --\n%s\n-- nyr DEBUG END --', diff --git a/package.json b/package.json index 2436311..7ab72a3 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "start": "DEBUG=nyr node ./index.js" }, "engine": { - "node": ">=6" + "node": ">=4" }, "devDependencies": { "@simonkberg/eslint-config": "^5.0.0", diff --git a/test/index.js b/test/index.js index c9f13b8..c5571dd 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,4 @@ -const { spawn } = require('child_process') -const { assign } = Object +const spawn = require('child_process').spawn const options = { cwd: process.cwd(), stdio: 'inherit', @@ -7,12 +6,7 @@ const options = { const run = name => new Promise((resolve, reject) => { const args = ['run', `test:${name}`] - const opts = assign({}, options, { - env: assign({}, process.env, { - _: name, - }), - }) - const child = spawn(name, args, opts) + const child = spawn(name, args, options) child.on('error', err => reject(err)) child.on('exit', code => diff --git a/test/npm.js b/test/npm.js index ba65486..a8a7f2b 100644 --- a/test/npm.js +++ b/test/npm.js @@ -1,8 +1,8 @@ const assert = require('assert') -const { bin, args, cwd, isYarn, isNPM } = require('../index') +const nyr = require('../index') -assert(bin.endsWith('npm-cli.js'), `'bin' is '${bin}'`) -assert(args.indexOf('run') === 0, `'args' is '${args}'`) -assert(cwd === process.cwd(), `'cwd' is '${cwd}'`) -assert(isYarn === false, `'isYarn' is '${isYarn}'`) -assert(isNPM === true, `'isNPM' is '${isNPM}'`) +assert(nyr.bin.endsWith('npm-cli.js'), `'bin' is '${nyr.bin}'`) +assert(nyr.args.indexOf('run') === 0, `'args' is '${nyr.args}'`) +assert(nyr.cwd === process.cwd(), `'cwd' is '${nyr.cwd}'`) +assert(nyr.isYarn === false, `'isYarn' is '${nyr.isYarn}'`) +assert(nyr.isNPM === true, `'isNPM' is '${nyr.isNPM}'`) diff --git a/test/yarn.js b/test/yarn.js index 9e4b827..10be038 100644 --- a/test/yarn.js +++ b/test/yarn.js @@ -1,8 +1,8 @@ const assert = require('assert') -const { bin, args, cwd, isYarn, isNPM } = require('../index') +const nyr = require('../index') -assert(bin.endsWith('yarn.js'), `'bin' is '${bin}'`) -assert(args.indexOf('run') === 0, `'args' is '${args}'`) -assert(cwd === process.cwd(), `'cwd' is '${cwd}'`) -assert(isYarn === true, `'isYarn' is '${isYarn}'`) -assert(isNPM === false, `'isNPM' is '${isNPM}'`) +assert(nyr.bin.endsWith('yarn.js'), `'bin' is '${nyr.bin}'`) +assert(nyr.args.indexOf('run') === 0, `'args' is '${nyr.args}'`) +assert(nyr.cwd === process.cwd(), `'cwd' is '${nyr.cwd}'`) +assert(nyr.isYarn === true, `'isYarn' is '${nyr.isYarn}'`) +assert(nyr.isNPM === false, `'isNPM' is '${nyr.isNPM}'`)