Open eight04 opened 6 years ago
What version of node?
Node.js v9.7.1 Windows 7 x64
Ok so I had to pull the execSync polyfill due to a security issue reported in #16, will have to look into alternatives for windows, at least getting this running on the cli. Apologies, for windows I recommend continuing to use 4.x for now.
Feel free to do some investigation and send a PR, might be a few days until I get around to looking at it.
I think that on Windows, only executables (.exe) are spawn-able without extension name. Here is a test script:
async function test() {
const {spawn} = require("child_process");
const eventToPromise = require("event-to-promise");
let p;
p = spawn("where", ["web-ext"], {stdio: "inherit"});
await eventToPromise(p, "exit");
p = spawn("where.exe", ["web-ext"], {stdio: "inherit"});
await eventToPromise(p, "exit");
p = spawn("web-ext", ["--version"], {stdio: "inherit"});
try {
await eventToPromise(p, "exit");
} catch (err) {
console.log("spawn error", err);
}
p = spawn("web-ext.cmd", ["--version"], {stdio: "inherit"});
await eventToPromise(p, "exit");
p = spawn("web-ext", ["--version"], {stdio: "inherit", shell: true});
await eventToPromise(p, "exit");
p = spawn("web-ext", ["--version"], {stdio: "inherit", shell: true, env: {pathext: ";"}});
try {
await eventToPromise(p, "exit");
} catch (err) {
console.log("spawn error", err);
}
}
test();
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd
spawn error { Error: spawn web-ext ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
at onErrorNT (internal/child_process.js:379:16)
at process._tickCallback (internal/process/next_tick.js:114:19)
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn web-ext',
path: 'web-ext',
spawnargs: [ '--version' ] }
2.6.0
2.6.0
'web-ext' 不是內部或外部命令、可執行的程式或批次檔。
To correctly spawn a .cmd
file, we have to use the full name, or invokes it through the shell that relies on environment variable pathext
.
Also note that, by spawning through shell, even the command isn't found, the child process (the shell process i.e. cmd.exe) is spawned successfully.
I would like to add options.shell = true
here:
https://github.com/timoxley/npm-run/blob/03d91cb860427265a4b22fe60e8001ccf4de688c/index.js#L54-L61
What do you think?
I am too facing the same issue.
Posting the error log here.
> api-doc@1.0.0 build-html:ecart-static-ui C:\Users\Lakky69\ecart\dev-tools\api-doc
> npm-run raml2html ecart-static-ui/index.raml -o dist/ecart-static-ui.html
Error: spawn raml2html ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
at onErrorNT (internal/child_process.js:376:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:502:3
npm ERR! code ELIFECYCLE
npm ERR! errno 4294963238
npm ERR! api-doc@1.0.0 build-html:ecart-static-ui: `npm-run raml2html ecart-static-ui/index.raml -o dist/ecart-static-ui.html`
npm ERR! Exit status 4294963238
npm ERR!
npm ERR! Failed at the api-doc@1.0.0 build-html:ecart-static-ui script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lakky69\AppData\Roaming\npm-cache\_logs\2018-04-20T09_43_34_743Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 4294963238
npm ERR! api-doc@1.0.0 build:ecart-static-ui: `npm run build-html:ecart-static-ui && npm run build-md:ecart-static-ui`
npm ERR! Exit status 4294963238
npm ERR!
npm ERR! Failed at the api-doc@1.0.0 build:ecart-static-ui script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lakky69\AppData\Roaming\npm-cache\_logs\2018-04-20T09_43_34_806Z-debug.log
@eight04 so hang on, does adding shell: true
fix the issue?
@timoxley Yes, it does.
diff --git a/index.js b/index.js
index c7925c6..5d79520 100644
--- a/index.js
+++ b/index.js
@@ -57,6 +57,7 @@ function augmentOptionsSync (options) {
var env = Object.create(options.env)
env[npmPath.PATH] = newPath
options.env = env
+ options.shell = true
return options
}
D:\Dev\webextension-test>npm-run --version
5.0.1
D:\Dev\webextension-test>npm-run web-ext --version
2.6.0
Also the test failed on Windows:
D:\Dev\npm-run>npm test
> npm-run@5.0.1 test D:\Dev\npm-run
> tape test/*.js && npm run lint
TAP version 13
# bin ok
ok 1 should be truthy
ok 2 bin exists: D:\Dev\npm-run\bin\npm-run.js
# passing dashed args
internal/child_process.js:330
throw errnoException(err, 'spawn');
^
Error: spawn UNKNOWN
at ChildProcess.spawn (internal/child_process.js:330:11)
at exports.spawn (child_process.js:500:9)
at Test.<anonymous> (D:\Dev\npm-run\test\bin.js:26:15)
at Test.bound [as _cb] (D:\Dev\npm-run\node_modules\tape\lib\test.js:77:32)
at Test.run (D:\Dev\npm-run\node_modules\tape\lib\test.js:96:10)
at Test.bound [as run] (D:\Dev\npm-run\node_modules\tape\lib\test.js:77:32)
at Immediate.next (D:\Dev\npm-run\node_modules\tape\lib\results.js:71:15)
at runCallback (timers.js:763:18)
at tryOnImmediate (timers.js:734:5)
at processImmediate (timers.js:716:5)
npm ERR! Test failed. See above for more details.
Any ideas on this one? I can support in pushing this forward.
It works fine with v4.x.