moxystudio / node-cross-spawn Goto Github PK
View Code? Open in Web Editor NEWA cross platform solution to node's spawn and spawnSync
License: MIT License
A cross platform solution to node's spawn and spawnSync
License: MIT License
If I pass a file such as node_modules\foo\index.js
as the 2nd arg to spawn.sync, where foo is a JUNCTION (NTFS link) to another folder then I get the error
"The system cannot find the file specified!"
It's obviously not following through the link
This situation occurs when locally developing a package andwanting to run somehting in it.
In my use of cross-spawn
(actually via the cross-env
package), I have discovered that there is some special error-emission behavior (apparently for Windows and cmd.exe
?) implemented by the enoent.js
source file, which is described on the following line:
https://github.com/moxystudio/node-cross-spawn/blob/master/lib/enoent.js#L25
This line also contains a comment which refers the original issue.
Basically, the special behavior is: If the spawned process exits with 1 and the command line cannot be found in file system, emit an Error
describing an ENOENT
error condition (i.e., "command not found").
(It may be helpful to familiarize yourself with the source code and the details of the original issue before reading on.)
But, there is (and IMO has always been) a problem: The logic in enoent.js
assumes that exit code 1 should aways trigger the special ENOENT
error-emission behavior... but the assumptions behind that special behavior are only correct in certain cases, wrong in others.
Firstly, cmd.exe
may not even be in the picture, so any behavior based on the assumption that it is, is flawed. (Windows has a new shell, now the default, called PowerShell.exe
, so the chances that cmd.exe
is not being used is actually quite high.)
Secondly, there are many used-cases in which an exit code of 1 does not implicitly mean "command not found". Even with cmd.exe
this could easily be the case... any Windows command script, or process launched by the script, could simply choose to exit the script with 1, or any other code, for any purpose.
Thirdly, the command passed to cross-spawn
may not be an actual file-system location that can be "verified" exists or not. This is especially true with PowerShell, since the command might refer to a "cmdlet" (callable entities which are named independently of the file system) that ran successfully, but simply chose to exit with 1.
In short, this special hard-coded behavior can easily do the wrong thing. For some cases, it may be desirable to convert exit code 1 + "command not found" into an emission of ENOENT
, but in other cases, this logic is wrong, and only creates confusion and annoyance.
Case in point: Unit test frameworks (mocha
for example) exit with the number of failed tests (i.e., 0 for success, any other number for failure). When cross-spawn
is used in such a case, a confusing ENOENT
error occurs whenever 1 test fails, but not when 2 more tests fail.
For real-world cases like this, where the special ENOENT
behavior is not appropriate, would you consider adding a flag to allow the caller to opt-out of the special logic? That is, just pass any exit code straight through. (Better yet, IMO, place the current special behavior behind an opt-in flag instead.)
Thanks.
I'm not able to figure it out... perhaps you know?
Hi
I'm not able to pipe the stfout/err to a file. This is the sample im trying:
var spawn = require('cross-spawn),
out = fs.openSync('run.log', 'a');
var childProcess = spawn('myserver', ['run'], {
stdio: [ 'ignore', out, out ], // piping stdout and stderr to run.log
detached: true
});
childProcess.unref();
sleep(2300); // delay needed for the "myserver run" to start
var run_output = fs.readFileSync(path.join(working_dir, 'run.log')).toString();
expect(run_output).includes("listening on 100101");
On running this i see a new command prompt popping up, with the "listening on 100101" message.
And run.log is empty.
Ideally, I would expect it to just pipe the output to run.log and NOT bring up a new cmd prompt.
Could you please help me with this?
Im running it on
Windows 10
"mocha": "^2.4.5"
Thanks
Ramya
As this module is shipped with ember-cli and several ember-cli users have issues to compile native c extensions it would be nice to have the async version available as a separate module
Related: #18
index.js
line 5 declares a variable named spawnSync
.
index.js
line 119 declares a function named spawnSync
.
index.js
line 125 intends to export the spawnSync
function, but it actually exports the spawnSync
variable. Oops.
I'll submit a pull request in a sec to rename the variable to sync
.
The recent ginormous v6 commit introduced an unconditional path.normalize()
wrapping the command, which breaks spawn('./foo', { cwd: 'subdir' )
:
Line 107 in e77b8f2
I can't say what bug it was intended to fix, as the giant commit perverts all useful context. It is definitely breaking posix "local relative on rebased cwd" calls.
Async vs sync makes no difference, but the sync calls are easier to demonstrate.
subdir/foo
:
#!/usr/bin/env node
console.log("foo");
test.js
:
const path = require('path');
const childProcess = require('child_process');
const spawn = require('cross-spawn');
const cmd = './foo';
const opts = { cwd: path.resolve(__dirname, 'subdir') };
// works
childProcess.spawnSync(cmd, opts) // stdout: "foo"
// fails
spawn.sync(cmd, opts) // throws ENOENT "foo"
Upgrading cross-spawn to v6 in https://github.com/yargs/yargs current master with no other changes will demonstrate this "in the wild".
485 passing (3s)
10 failing
1) integration tests should run as a shell script with no arguments:
Uncaught Error: spawn bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
2) integration tests should run as a shell script with arguments:
Uncaught Error: spawn bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
3) integration tests allows --help to be completed without returning help message:
Uncaught Error: spawn bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
4) integration tests flushes all output when --help is executed:
Uncaught Error: spawn issue-497.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
5) integration tests correctly fills positional command args with preceding option:
Uncaught Error: spawn opt-assignment-and-positional-command-arg.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
6) integration tests correctly fills positional command args with = assignment in preceding option:
Uncaught Error: spawn opt-assignment-and-positional-command-arg.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
7) integration tests load root package.json version # defaults to appropriate version # when yargs is installed normally:
Uncaught Error: spawn normal-bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
8) integration tests load root package.json version # defaults to appropriate version # when yargs is symlinked:
Uncaught Error: spawn symlink-bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
9) integration tests load root package.json parser settings reads parser config settings when yargs is installed normally:
Uncaught Error: spawn normal-bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
10) integration tests load root package.json parser settings reads parser config settings when yargs is installed as a symlink:
Uncaught Error: spawn symlink-bin.js ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Branch | Build failing π¨ |
---|---|
Dependency | babel-preset-moxy |
Current Version | 2.3.3 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
babel-preset-moxy is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 2 commits.
d94c357
chore(release): 2.3.4
722526c
fix: fix dev errors when using transform-react-inline-elements
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
var spawn = require('cross-spawn'); // version 0.2.6
// var command = "node"; // works fine
var command = "c:\\Program Files\\iojs\\node.exe";
// fails even though path is valid
// error is Cannot find module 'D:\Dev\test\Files\iojs\node.exe'
// when executed from 'D:\Dev\test\' directory
var args = ["--version"];
var spawned = spawn(command, args);
spawned.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
spawned.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
spawned.on('close', function (code) {
console.log('child process exited with code ' + code);
});
Should check if passed argument is number because numbers don't have .replace method
usecase: spawn("weinre", ["--httpPort", 1234]);
Thanks for developing cross-spawn! It is disappointing that Node.js does not support this out of the box, and your package provides something of great value to those developing packages that require support for Windows.
Normally, when spawn
cannot find the program to be executed it returns an error ENOENT. However, since this command is wrapped in cmd.exe
it no longer does that, and instead returns an error generated by cmd.exe
and has returnCode=1
and stderr
in the form βcommandβ is not recognized as an internal or external command, operable program or batch file.
My workaround was to check if returnCode
equals 1
(non-zero) and if the stderr
message contains similar text, such as the part: is not recognized as an internal or external command
.
I am using it here for my package Atom Beautify: Glavin001/atom-beautify@57ffe75
Please let me know what you think, and if I should submit a Pull Request with the workaround I described above.
Running into a weird issue when I try to use cross-spawn to execute an npm command:
This seems possibly related to:
When cross-spawn
is invoked in a pre-commit
hook code by husky, if the process.env
is used, npm command errors out inexplicably on windows:
Ξ» git commit
husky > npm run -s precommit (node v8.5.0)
,,
husky > pre-commit hook failed (add --no-verify to bypass)
On manually removing the silent(-s
) flag in the husky pre-commit hook(subl ./.git/hooks/pre-commit
), we can see the error logs:
Ξ» git commit
husky > npm run precommit (node v8.5.0)
> [email protected] precommit E:\Projects\experiments\test-cross-spawn-env
> npm run spawn
> [email protected] spawn E:\Projects\experiments\test-cross-spawn-env
> node spawn.js
npm WARN invalid config access=undefined
npm WARN invalid config also=undefined
npm WARN invalid config https-proxy=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN invalid config init-author-url=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN invalid config only=undefined
npm WARN invalid config proxy=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN onload-script failed to require onload script undefined
npm WARN onload-script Error: Cannot find module 'undefined'
npm WARN onload-script at Function.Module._resolveFilename (module.js:527:15)
npm WARN onload-script at Function.Module._load (module.js:476:23)
npm WARN onload-script at Module.require (module.js:568:17)
npm WARN onload-script at require (internal/module.js:11:18)
npm WARN onload-script at cb (C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:225:11)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:356:16
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:81:7
npm WARN onload-script at Array.forEach (<anonymous>)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:80:13
npm WARN onload-script at f (C:\nvm\v8.5.0\node_modules\npm\node_modules\once\once.js:25:25)
npm WARN onload-script { Error: Cannot find module 'undefined'
npm WARN onload-script at Function.Module._resolveFilename (module.js:527:15)
npm WARN onload-script at Function.Module._load (module.js:476:23)
npm WARN onload-script at Module.require (module.js:568:17)
npm WARN onload-script at require (internal/module.js:11:18)
npm WARN onload-script at cb (C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:225:11)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:356:16
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:81:7
npm WARN onload-script at Array.forEach (<anonymous>)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:80:13
npm WARN onload-script at f (C:\nvm\v8.5.0\node_modules\npm\node_modules\once\once.js:25:25)
npm WARN onload-script stack: 'Error: Cannot find module \'undefined\'\n at Function.Module._resolveFilename (module.js:527:15)\n at Function.Module._load (module.js:476:23)\n at Module.require (module.js:568:17)\n at require (internal/module.js:11:18)\n at cb (C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\npm.js:225:11)\n
at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\npm.js:356:16\n at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\config\\core.js:81:7\n at Array.forEach (<anonymous>)\n at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\config\\core.js:80:13\n at f (C:\\nvm\\v8.5.0\\node_modules\\npm\\node_modules\\once\\once.js:25:25)',
npm WARN onload-script code: 'MODULE_NOT_FOUND' }
npm WARN invalid config access=undefined
npm WARN invalid config also=undefined
npm WARN invalid config https-proxy=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN invalid config init-author-url=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN invalid config only=undefined
npm WARN invalid config proxy=undefined
npm WARN invalid config Must be a full url with 'http://'
npm WARN onload-script failed to require onload script undefined
npm WARN onload-script Error: Cannot find module 'undefined'
npm WARN onload-script at Function.Module._resolveFilename (module.js:527:15)
npm WARN onload-script at Function.Module._load (module.js:476:23)
npm WARN onload-script at Module.require (module.js:568:17)
npm WARN onload-script at require (internal/module.js:11:18)
npm WARN onload-script at cb (C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:225:11)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:356:16
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:81:7
npm WARN onload-script at Array.forEach (<anonymous>)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:80:13
npm WARN onload-script at f (C:\nvm\v8.5.0\node_modules\npm\node_modules\once\once.js:25:25)
npm WARN onload-script { Error: Cannot find module 'undefined'
npm WARN onload-script at Function.Module._resolveFilename (module.js:527:15)
npm WARN onload-script at Function.Module._load (module.js:476:23)
npm WARN onload-script at Module.require (module.js:568:17)
npm WARN onload-script at require (internal/module.js:11:18)
npm WARN onload-script at cb (C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:225:11)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\npm.js:356:16
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:81:7
npm WARN onload-script at Array.forEach (<anonymous>)
npm WARN onload-script at C:\nvm\v8.5.0\node_modules\npm\lib\config\core.js:80:13
npm WARN onload-script at f (C:\nvm\v8.5.0\node_modules\npm\node_modules\once\once.js:25:25)
npm WARN onload-script stack: 'Error: Cannot find module \'undefined\'\n at Function.Module._resolveFilename (module.js:527:15)\n at Function.Module._load (module.js:476:23)\n at Module.require (module.js:568:17)\n at require (internal/module.js:11:18)\n at cb (C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\npm.js:225:11)\n
at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\npm.js:356:16\n at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\config\\core.js:81:7\n at Array.forEach (<anonymous>)\n at C:\\nvm\\v8.5.0\\node_modules\\npm\\lib\\config\\core.js:80:13\n at f (C:\\nvm\\v8.5.0\\node_modules\\npm\\node_modules\\once\\once.js:25:25)',
npm WARN onload-script code: 'MODULE_NOT_FOUND' }
> [email protected] hello E:\Projects\experiments\test-cross-spawn-env
> node index.js
npm ERR! file undefined
npm ERR! path undefined
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn undefined
npm ERR! [email protected] hello: `node index.js`
npm ERR! spawn undefined ENOENT
npm ERR!
npm ERR! Failed at the [email protected] hello script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! code ELIFECYCLE
npm ERR! errno -4058
npm ERR! [email protected] hello: `node index.js`
npm ERR! Exit status -4058
npm ERR!
npm ERR! Failed at the [email protected] hello 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\suhas.karanth\AppData\Roaming\npm-cache\_logs\2017-09-21T04_55_49_244Z-debug.log
,,
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] spawn: `node spawn.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] spawn 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\suhas.karanth\AppData\Roaming\npm-cache\_logs\2017-09-21T04_55_49_341Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] precommit: `npm run spawn`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] precommit 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\suhas.karanth\AppData\Roaming\npm-cache\_logs\2017-09-21T04_55_49_408Z-debug.log
husky > pre-commit hook failed (add --no-verify to bypass)
I faced and fixed these issues in a couple of places. The solution was to filter process.env
for undefined
values:
Repo | Issue | PR |
---|---|---|
kentcdodds/kcd-scripts | kentcdodds/kcd-scripts#4 | kentcdodds/kcd-scripts#5 |
ta2edchimp/opt-cli | sezna/nps#155 | ta2edchimp/opt-cli#213 |
I have created a repo for demonstrating the issue - https://github.com/sudo-suhas/test-cross-spawn-env
I am not entirely sure if this is a problem which cross-spawn
should handle. Thoughts?
cc @kentcdodds
I'm using the library to execute a command in terminal:
process = spawn(command, params, options);
process.stdout.on('data', onLine);
process.stderr.on('data', onLine);
process.on('error', onError);
process.on('close', onClose);
It enters onLine
several times with the output, but then just hangs and does nothing (no exit, no error). What are the possible reasons for that? Is that a bug?
If I execute the command in Terminal, everything's fine. The command is linking a module to react native application (react-native link).
Branch | Build failing π¨ |
---|---|
Dependency | eslint |
Current Version | 3.12.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
indent
regression with function calls (fixes #7732, fixes #7733) (#7734) (Teddy Katz)The new version differs by 6 commits .
9679daa
3.12.1
8a31bc8
Build: package.json and changelog update for 3.12.1
0ad4d33
Fix: indent
regression with function calls (fixes #7732, fixes #7733) (#7734)
ab246dd
Docs: Rules restricting globals/properties/syntax are linked together (#7743)
df2f115
Docs: Add eslint-config-mdcs to JSCS Migration Guide (#7737)
4b77333
Build: avoid creating broken rule links in the changelog (#7731)
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
Hello,
Actually I'm building a CLI app, I want to ask users some question, like project name or project author. And I want to give them default value of project author as git user.name.
My code below:
const spawn = require('cross-spawn')
const { red } = require('chalk')
const { error } = console
const child = spawn('git', ['config', 'user.name'], { stdio: 'inherit' })
child.on('close', code => {
if (code !== 0) {
error(red(`Process exited with error code ${code}`))
}
})
This code is perfectly printing the git user.name in the console but I want to store it in a variable or something like that so I can use it in the future.
Note: My app is a lot like npm init
or yarn init
command. It just asks some questions with some default values and creates a config file.
Thank you π
hey there π
thanks for a very helpful lib ππ
i'm coming here by way of execa having hit upon a fairly gnarly edge-case:
let's say you have a js script that tries to execute a file via execa
and the file it executes runs which
. if you run that script via npm - e.g. npm run my-script.js
- cross-spawn's which
dependency overrides the native one and can produce different / unexpected results.
this is due to the which
dependency (source) installing a which
bin into node_modules/.bin
(source) combined with the behavior of npm run
:
In addition to the shellβs pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts
(source)
in my case, i was trying to run a script file on windows using cygwin. within powershell, running:
bash -c "which make"
gave me:
/usr/bin/make
but doing the same using a node script run via npm run
:
const { stdout } = await execa('bash -c "which make");
gave me:
C:\cygwin\bin\make.EXE
the later uses a windows-style path b/c it relies on node's view of the environment (vs. cygwin' bash's view).
it gets worse when you try to look for an executable script that is not an .exe
- e.g. bash -c "which libtool"
. in this case, the node / npm version of which
returns nothing while the native version correctly locates the script in /usr/bin/libtool
my work-around at the moment is to simply not use npm run
to execute my script. naively, i wonder if there's a way to avoid having the which
dependency install a bin (since it looks like cross-spawn
only ever uses the dependency via require('which')
.
π€·ββ
Branch | Build failing π¨ |
---|---|
Dependency | rimraf |
Current Version | 2.6.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As rimraf is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
https://github.com/IndigoUnited/node-cross-spawn/blob/master/lib/parse.js#L64
check the comspec enviroment variable
this way it prevents anyone trying to use something other than cmd on windows
I'm trying to use cross-spawn
as a drop-in replacement for spawn
and execute the following command using the node 6 shell options, but it looks like the escaping in cross-spawn doesn't work the same as on linux.
On linux:
spawn('node', ['-e', 'console.log\\(\\"hello\\"\\)'], { shell: true});
> "test"
On windows:
crossSpawn('node', ['-e', 'console.log\\(\\"hello\\"\\)'], { shell: true});
> [eval]:1
console.log\(\"hello\"\)
^^^^
SyntaxError: Unexpected token ILLEGAL
at Object.exports.runInThisContext (vm.js:53:16)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:409:26)
at node.js:579:27
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
Just the messenger: duojs/duo#265
Support an option to internally call process.exit(result.status)
.
Originally I wanted to extract this as a separate module, but I think it actually makes most sense to simply add it to cross-spawn
itself. Would you be interested? The win32
version of the function would be:
function kill() {
crossSpawn("taskkill", ["/F", "/T", "/PID", this.pid])
}
And the posix
:
const getDescendentProcessInfo = require("ps-tree")
function kill() {
getDescendentProcessInfo(this.pid, (err, descendent) => {
if (err) {
return
}
descendent.forEach(({PID: pid}) => {
try {
process.kill(pid)
}
catch (_err) {
// ignore.
}
})
})
}
Would you be willing to accept a PR for this?
cc @mysticatea
#!/usr/bin/env node
var spawn = require('cross-spawn');
var script = process.argv[2];
var args = process.argv.slice(3);
...
var result = spawn.sync(
'node',
[require.resolve('../scripts/' + script)].concat(args),
{stdio: 'inherit'}
);
console.log(result.signal);
console.log(result.status);
process.exit(result.status);
Result when the child process is hit with kill -9
:
SIGKILL
0
result.status
should be equal to 9.
I'm trying to execute a command in an rvm environment. To do so, I first need to execute rvm env --path -- ruby-version
to yield the file with environment variables that should be sourced. The problem is that this command always returns the global environment, instead of the local environment based on the cwd
.
I have verified that the cwd
is correct, as well as verifying the output via commandline.
Script:
#!/usr/bin/env bash
ENV_RVM=`rvm env --path --ruby-version`
echo "RVM at $ENV_RVM from `pwd`"
source $ENV_RVM
#rails runner $1
Command line results:
RVM at /Users/kross/.rvm/environments/ruby-2.2.2@af_core from /Users/kross/projects/af_core/spec/dummy
spawn.sync results:
RVM at /Users/kross/.rvm/environments/ruby-2.2.2 from /Users/kross/projects/af_core/spec/dummy
Any thoughts on options I am missing to get RVM to behave as it does on command line?
using the rm -rf [directorypath] command on windows fails to recognize the command, any idea why? your help will be greatly appreciated. Nice project by the way!
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "node test.js"
},
"dependencies": {
"cross-spawn": "^6.0.5"
}
}
var crossSpawn = require('cross-spawn');
var cmd = crossSpawn.sync('yarn', ['--version'], {
stdio: 'inherit',
});
console.log('yarn --version return:', cmd.status);
console.log('path of child process:', cmd.options.envPairs.filter(e => /^path=/i.test(e)));
process.exit(cmd.status);
yarn install
yarn node test.js
yarn run test
PS D:\Projects\test> yarn node test.js
yarn node v1.12.1
1.12.1
yarn --version return: 0
path of child process: [ 'Path=xxxxxxxxxxxxxxx' ]
Done in 0.83s.
PS D:\Projects\test> yarn run test
yarn run v1.12.1
$ node test.js
The filename, directory name, or volume label syntax is incorrect.
yarn --version return: 1
path of child process: [ 'Path=A:\\USR-TMP\\yarn--1541088945270-0.3043972176672871;xxxxxxxxxxxxxxxxxxxx' ]
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
generated yarn
and node
in my $TEMP folder, contains bash script.
this is also a yarn issue.
But yarn not want to fool this module, so the detect logic must have a bug. ( Or maybe there is a bug in nodejs core π€£ )
Meaning can I live log the child process but then save the out resulting output to a variable?
Branch | Build failing π¨ |
---|---|
Dependency | eslint |
Current Version | 3.13.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
The new version differs by 4 commits .
7f8393c
3.13.1
91883bf
Build: package.json and changelog update for 3.13.1
3fc4e3f
Fix: prefer-destructuring reporting compound assignments (fixes #7881) (#7882)
f90462e
Fix: no-extra-label autofix should not remove labels used elsewhere (#7885)
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
Commands with spaces fail with shell: true
, but work if it's false. node developers say fixing this from their side would break other things: nodejs/node#7367 . Should this be fixed in cross-spawn? What do you think?
> require('cross-spawn').spawn('C:\\Program Files\\nodejs\\node.exe', [], {shell:true})
undefined
> Error: spawn C:\Program Files\nodejs\node.exe ENOENT
at notFoundError (C:\Users\redacted\node_modules\cross-spawn\lib\enoent.js:11:11)
at verifyENOENT (C:\Users\redacted\node_modules\cross-spawn\lib\enoent.js:46:16)
at ChildProcess.cp.emit (C:\Users\redacted\node_modules\cross-spawn\lib\enoent.js:33:19)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
> require('cross-spawn').spawn('C:\\Program Files\\nodejs\\node.exe', [], {shell:false})
ChildProcess {
...
Using yeoman, which uses node-cross-spawn as dependency, I'm trying to start a git repo when scaffolding an application with a yeoman custom generator, this is what I got at the install
step:
install: function () {
this.installDependencies();
this.spawnCommand('npm', ['i', '--save' , 'express', 'mongodb', 'mongoose', 'lodash', 'bluebird', 'async', 'morgan']);
this.spawnCommand('git' ['init']); // Here it fails
this.spawnCommand('git', ['add', '.']);
this.spawnCommand('git', ['commit', '-am', '"yo scaffolded app"']);
}
However when trying to run this I get:
events.js:85
throw er; // Unhandled 'error' event
^
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (child_process.js:1136:26)
at Object.exports.spawn (child_process.js:995:9)
at spawn (/storage/home/dev/generator-koala/node_modules/yeoman-generator/node_modules/cross-spawn/index.js:87:19)
at spawnCommand (/storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/actions/spawn_command.js:17:10)
at module.exports.yeoman.generators.Base.extend.install (/storage/home/dev/generator-koala/generators/app/index.js:72:10)
at /storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/base.js:421:16
at processImmediate [as _immediateCallback] (timers.js:367:17)
I do have git installed, how should I fix this?
We're having failing tests with yeoman generators. Here's a trace:
https://travis-ci.org/yeoman/generator-node/jobs/71051980
In the trace you can see we're using cross-spawn 1.0.3
Something for the future, I was looking into reducing my CLI tool size and noticed the semver
package at the top when sorting by size.
When going with Node.js 6 and higher two dependencies, semver
and nice-try
are not needed anymore since they are used only once for feature detection here:
Line 15 in bbd342b
Hello,
I got here because I'm trying to convert pdf files to images using graphicsmagic. The thing is that PDF files exported with Microsoft word on Mac OS X, have some weird thing and the command of graphicsmagick throws a warning in the console. The issue here is that that warning printed in the console is attached to the stdout from this library causing that the resulting file is corrupted (has the warning in the beginning of the file). And I've found no way of fixing this issue. Any ideas?
The README
says the shell
option of child_process.spawn
doesn't work in Node <v6
but the change was actually cherry-picked into v4 LTS
and v5
, see nodejs/node#4598. I'll send a PR to correct it.
Trying to install pimatic on raspi I'm stuck at cross-spawn, please excuse if this is the wrong place to ask:
npm install pimatic --production
npm http GET http://registry.npmjs.org/socket.io
npm http GET http://registry.npmjs.org/cross-spawn
npm http 200 http://registry.npmjs.org/cross-spawn
npm http 200 http://registry.npmjs.org/socket.io
npm http GET http://registry.npmjs.org/socket.io/-/socket.io-1.0.6.tgz
npm http 200 http://registry.npmjs.org/socket.io/-/socket.io-1.0.6.tgz
npm ERR! Error: No compatible version found: cross-spawn@'^0.2.3'
npm ERR! Valid install targets:
npm ERR! ["0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.1.6","0.1.7","0.2.0","0.2.1","0.2.2","0.2.3"]
npm ERR! at installTargetsError (/opt/node/lib/node_modules/npm/lib/cache.js:709:10)
npm ERR! at /opt/node/lib/node_modules/npm/lib/cache.js:631:10
npm ERR! at saved (/opt/node/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Linux 3.12.24+
npm ERR! command "/opt/node/bin/node" "/opt/node/bin/npm" "install" "pimatic" "--production"
npm ERR! cwd /home/pi/pimatic
npm ERR! node -v v0.10.8
npm ERR! npm -v 1.2.23
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/pi/pimatic/npm-debug.log
npm ERR! not ok code 0
Branch | Build failing π¨ |
---|---|
Dependency | lru-cache |
Current Version | 4.0.2 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
lru-cache is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you itβs very likely also breaking them.
I recommend you give this issue a very high priority. Iβm sure you can resolve this πͺ
The new version differs by 9 commits.
1a77f87
v4.1.0
1c49494
more timing slack
8be4c24
autopublish scripts
363e0d9
the lock file
d342daa
move main to index.js
4ef200a
add noDisposeOnSet option
c65bd6f
test: update tap, add more slack in timing test
f23cecd
travis update
37526e2
neveragain.tech pledge request
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
"foo|bar>baz"
Branch | Build failing π¨ |
---|---|
Dependency | eslint |
Current Version | 3.14.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
no-extra-parens
incorrect precedence (fixes #7978) (#7999) (alberto)template-tag-spacing
rule (fixes #7631) (#7913) (Jonathan Wilsson)The new version differs by 17 commits .
8ea98f9
3.15.0
77b5cb7
Build: package.json and changelog update for 3.15.0
f2a3580
Fix: no-extra-parens
incorrect precedence (fixes #7978) (#7999)
d6b6ba1
Fix: no-var should fix ForStatement.init (#7993)
99d386d
Upgrade: Espree v3.4.0 (#8019)
42390fd
Docs: update README.md for team (#8016)
d7ffd88
Chore: enable template-tag-spacing on ESLint codebase (#8005)
f2be7e3
Docs: Fix typo in object-curly-newline.md (#8002)
df2351a
Docs: Fix misleading section in brace-style documentation (#7996)
5ae6e00
Chore: avoid unnecessary feature detection for Symbol (#7992)
5d57c57
Chore: fix no-else-return lint error (refs #7986) (#7994)
62fb054
Chore: enable no-else-return on ESLint codebase (#7986)
c59a0ba
Update: add ignoreRestSiblings option to no-unused-vars (#7968)
5cdfa99
Chore: enable no-unneeded-ternary on ESLint codebase (#7987)
fbd7c13
Update: ensure operator-assignment handles exponentiation operators (#7970)
There are 17 commits in total. See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
Can we remove the spawn-sync
dependency? Node 0.10 will be completely unsupported in about 6 months (even including security releases). It's going to be completely dead soon.
It's a huge burden to maintainers to answer users questions about the native dependency errors in the npm install output. Even though we know it's harmless output, since the dependency is optional, users don't. So, we see a lot of opened issues about this.
Here's a proposal:
spawn-sync
, effectively dropping 0.10 supportRelated issues:
#18
websockets/ws#577
You require spawn-sync
:
/Users/jerrygreen/projects/project_name/node_modules/cross-spawn/index.js:32:34: Cannot resolve dependency 'spawn-sync'
30 | if (!cpSpawnSync) {
31 | try {
> 32 | cpSpawnSync = require('spawn-sync'); // eslint-disable-line global-require
| ^
33 | } catch (ex) {
34 | throw new Error(
35 | 'In order to use spawnSync on node 0.10 or older, you must ' +
But here's your dependencies:
[email protected], cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
dependencies:
lru-cache "^4.0.1"
shebang-command "^1.2.0"
which "^1.2.9"
There's no such thing as spawn-sync
. Wuuut?
Node 0.12 now has spawnSync
in addition to spawn
. It would be great it node-cross-spawn supported this new method.
child_process.spawn
recently got a shell
option that spawns cmd.exe
for you on Windows, pretty much the way cross-spawn
does. However, as discussed in nodejs/node#6671 and nodejs/node#6784, it signifcantly impacts performance.
To avoid unnecessarily slowing down the spawn call, I suggested looking at the file extension to determine if a shell is actually required. The PR got rejected, which I understand (see link above), but I think it makes sense to include the same logic in cross-spawn
.
Before I actually create a PR, I'd like to test the water first. Do you think it's a good idea?
Travis CI does not support Windows, although how about AppVeyor?
Any other reason why there isn't a Windows CI setup for this project already?
Documentation do not provide sufficient information on what is the parameter used under spawn command. The document is only for those who are into javascript for few years. Not recommended for new buddies or new learners
I am trying to use execa by running code in worker threads, and it is generating the TypeError error [ERR_WORKER_UNSUPPORTED_OPERATION]: process.chdir () is not supported in workers.
process.chdir(cwd)
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm http GET https://registry.npmjs.org/webshot
npm http 200 https://registry.npmjs.org/webshot
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/cross-spawn
npm http GET https://registry.npmjs.org/phantomjs
npm http GET https://registry.npmjs.org/tmp
npm http 304 https://registry.npmjs.org/cross-spawn
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/phantomjs
npm http 304 https://registry.npmjs.org/tmp
npm ERR! Error: No compatible version found: cross-spawn@'^0.2.3'
npm ERR! Valid install targets:
npm ERR! ["0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.1.6","0.1.7","0.2.0","0.2.1","0.2.2","0.2.3","0.2.4","0.2.5","0.2.6"]
npm ERR! at installTargetsError (/service/app/node_modules/npm/lib/cache.js:719:10)
npm ERR! at /service/app/node_modules/npm/lib/cache.js:641:10
npm ERR! at saved (/service/app/node_modules/npm/node_modules/npm-registry-client/lib/get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]
npm ERR! System Linux 2.6.32-358.6.2.el6.x86_64
npm ERR! command "/service/app/node-v0.10.12/bin/node" "/usr/local/bin/npm" "install" "webshot"
npm ERR! cwd /home/lance
npm ERR! node -v v0.10.12
npm ERR! npm -v 1.2.32
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/lance/npm-debug.log
npm ERR! not ok code 0
Branch | Build failing π¨ |
---|---|
Dependency | rimraf |
Current Version | 2.5.4 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As rimraf is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
The new version differs by 5 commits .
5b661e4
v2.6.0
c09915f
update tap
d53235d
Make rimraf.sync 10000% more reliable on Windows
e8b10a7
Retry on EBUSY et al on non-windows platforms as well
0fac5f7
Add --no-glob option to cli
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.