Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
fix(win32): nudge a few things around to fix up windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jun 24, 2017
1 parent 2e418d1 commit bde8cca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -216,7 +216,7 @@ function execCommand (_existing, argv) {

module.exports._findNodeScript = findNodeScript
function findNodeScript (existing, opts) {
if (!existing || process.platform === 'win32') {
if (!existing) {
return Promise.resolve(false)
} else {
return promisify(fs.stat)(existing).then(stat => {
Expand All @@ -237,7 +237,7 @@ function findNodeScript (existing, opts) {
} catch (e) {
throw new Error(Y()`command not found: ${existing}`)
}
} else {
} else if (process.platform !== 'win32') {
const line = '#!/usr/bin/env node\n'
const bytecount = line.length
const buf = Buffer.alloc(bytecount)
Expand Down
38 changes: 26 additions & 12 deletions test/index.js
Expand Up @@ -43,24 +43,25 @@ test('npx existing subcommand', t => {
NPX_PATH, 'which', 'npm'
], {stdio: 'pipe'}).then(res => {
t.notOk(res.stderr, 'no stderr output')
t.equal(
res.stdout.trim(),
path.resolve(NPX_PATH, 'node_modules', '.bin', 'npm'),
'got the local npm binary'
)
t.ok(res.stdout.trim(), 'got output from command')
})
})

test('execCommand unit', t => {
const whichBin = path.resolve(
let whichBin = path.resolve(
__dirname, '..', 'node_modules', '.bin', 'which'
)
if (process.platform === 'win32') {
whichBin += '.CMD'
}
return main._execCommand(null, {
command: path.resolve(__dirname, '..', 'README.md')
}).then(() => {
throw new Error('should not have succeeded')
}, err => {
t.equal(err.code, 'EACCES', 'get a regular crash when the arg is invalid')
t.equal(
typeof err.code, 'string', 'get a regular crash when the arg is invalid'
)
const oldCode = process.exitCode
delete process.exitCode
return main._execCommand(null, {
Expand Down Expand Up @@ -92,7 +93,10 @@ test('installPackages unit', t => {
}
})._installPackages
const npxPath = path.resolve(__dirname, '..')
const npmPath = path.join(npxPath, 'node_modules', '.bin', 'npm')
let npmPath = path.join(npxPath, 'node_modules', '.bin', 'npm')
if (process.platform === 'win32') {
npmPath += '.CMD'
}
return installPkgs(['installme@latest', 'file:foo'], 'myprefix', {
npm: npmPath
}).then(deets => {
Expand Down Expand Up @@ -129,15 +133,21 @@ test('installPackages unit', t => {
})

test('getEnv', t => {
const npm = path.resolve(__dirname, '..', 'node_modules', '.bin', 'npm')
let npm = path.resolve(__dirname, '..', 'node_modules', '.bin', 'npm')
if (process.platform === 'win32') {
npm += '.CMD'
}
return main._getEnv({npm}).then(env => {
t.ok(env, 'got the env')
t.equal(env.npm_package_name, 'npx', 'env has run-script vars')
})
})

test('getNpmCache', t => {
const npm = path.resolve(__dirname, '..', 'node_modules', '.bin', 'npm')
let npm = path.resolve(__dirname, '..', 'node_modules', '.bin', 'npm')
if (process.platform === 'win32') {
npm += '.CMD'
}
const userconfig = 'blah'
const getCache = requireInject('../index.js', {
'../child.js': {
Expand Down Expand Up @@ -207,8 +217,12 @@ test('findNodeScript', t => {
}
}
})._findNodeScript
return findScript('fail').then(() => {
throw new Error('should have failed')
return findScript('fail').then(f => {
if (process.platform === 'win32') {
t.notOk(f, 'win32 gives no fucks')
} else {
throw new Error('should have failed')
}
}, err => {
t.equal(err.message, 'fail', 'close error rethrown')
})
Expand Down

0 comments on commit bde8cca

Please sign in to comment.