Skip to content

Commit ff495d9

Browse files
authored
fix: add check cmd on Windows (#21)
1 parent 8bbc547 commit ff495d9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ npm-debug.log
1515
coverage/
1616
test/fixtures/ts/**/*.js
1717
.DS_Store
18+
package-lock.json

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ const is = require('is-type-of');
55
const assert = require('assert');
66
const path = require('path');
77
const spawn = require('child_process').spawn;
8+
const spawnSync = require('child_process').spawnSync;
9+
10+
function isCmd() {
11+
if (process.platform !== 'win32') {
12+
return false
13+
}
14+
15+
try {
16+
const result = spawnSync(`ls`, {
17+
stdio: 'pipe',
18+
})
19+
20+
return result.error !== undefined
21+
} catch (err) {
22+
return true
23+
}
24+
}
825

926
/**
1027
* Run shell script in child process
@@ -36,7 +53,8 @@ module.exports = function runScript(script, options, extraOptions) {
3653
if (script.indexOf('./') === 0 || script.indexOf('.\\') === 0 ||
3754
script.indexOf('../') === 0 || script.indexOf('..\\') === 0) {
3855
const splits = script.split(' ');
39-
splits[0] = path.join(options.cwd, splits[0]);
56+
// in bash C:\Windows\system32 -> C:\\Windows\\system32
57+
splits[0] = path.join(isCmd() ? options.cwd : path.normalize(options.cwd), splits[0]);
4058
script = splits.join(' ');
4159
}
4260
}

0 commit comments

Comments
 (0)