Skip to content

Commit 0c74481

Browse files
adamdharringtonKent C. Dodds
authored andcommitted
fix(resolveBin): windows will resolve to .cmd binaries if available (#8) (#88)
1 parent 7970d40 commit 0c74481

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/__tests__/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ test(`resolveBin resolves to the binary if it's in $PATH`, () => {
5151
expect(whichSyncMock).toHaveBeenCalledWith('cross-env')
5252
})
5353

54+
describe('for windows', () => {
55+
let realpathSync
56+
57+
beforeEach(() => {
58+
jest.doMock('fs', () => ({realpathSync: jest.fn()}))
59+
realpathSync = require('fs').realpathSync
60+
})
61+
afterEach(() => {
62+
jest.unmock('fs')
63+
})
64+
65+
test('resolveBin resolves to .bin path when which returns a windows-style cmd', () => {
66+
const fullBinPath = '\\project\\node_modules\\.bin\\concurrently.CMD'
67+
realpathSync.mockImplementation(() => fullBinPath)
68+
expect(require('../utils').resolveBin('concurrently')).toBe(fullBinPath)
69+
expect(realpathSync).toHaveBeenCalledTimes(2)
70+
})
71+
})
72+
5473
test('getConcurrentlyArgs gives good args to pass to concurrently', () => {
5574
expect(
5675
require('../utils').getConcurrentlyArgs({

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) {
2424
let pathFromWhich
2525
try {
2626
pathFromWhich = fs.realpathSync(which.sync(executable))
27+
if (pathFromWhich && pathFromWhich.includes('.CMD')) return pathFromWhich
2728
} catch (_error) {
2829
// ignore _error
2930
}

0 commit comments

Comments
 (0)