From 2851ad70e6426b54f82e520c4106d0369ae723fc Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Thu, 11 Jan 2024 15:45:05 +0800 Subject: [PATCH 1/2] fix: add check cmd --- .gitignore | 1 + index.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6a0d94c..c6897ad 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ npm-debug.log coverage/ test/fixtures/ts/**/*.js .DS_Store +package-lock.json diff --git a/index.js b/index.js index 799aece..4ceca68 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,22 @@ const assert = require('assert'); const path = require('path'); const spawn = require('child_process').spawn; +function isCmd() { + if (os.platform() !== 'win32') { + return false + } + + try { + const result = spawnSync(`ls`, { + stdio: 'pipe', + }) + + return result.error !== undefined + } catch (err) { + return true + } +} + /** * Run shell script in child process * Support OSX, Linux and Windows @@ -36,7 +52,8 @@ module.exports = function runScript(script, options, extraOptions) { if (script.indexOf('./') === 0 || script.indexOf('.\\') === 0 || script.indexOf('../') === 0 || script.indexOf('..\\') === 0) { const splits = script.split(' '); - splits[0] = path.join(options.cwd, splits[0]); + // in bash C:\Windows\system32 -> C:\\Windows\\system32 + splits[0] = path.join(isCmd() ? options.cwd : path.normalize(options.cwd), splits[0]); script = splits.join(' '); } } From a95e77952cfebf8d8502595c97913767b30de6b9 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Thu, 11 Jan 2024 16:05:20 +0800 Subject: [PATCH 2/2] fix: fix eslint --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4ceca68..79e217c 100644 --- a/index.js +++ b/index.js @@ -5,9 +5,10 @@ const is = require('is-type-of'); const assert = require('assert'); const path = require('path'); const spawn = require('child_process').spawn; +const spawnSync = require('child_process').spawnSync; function isCmd() { - if (os.platform() !== 'win32') { + if (process.platform !== 'win32') { return false }