48 Commits

Author SHA1 Message Date
Zearin
9035b27403 docs: fix typos and adjust markdown formatting (#825)
Miscellaneous docs/markdown changes. No change to logic.
2018-02-19 22:21:17 -08:00
Brandon Freitag
9077f4171e
Remove separate "internal error" from exec (#802)
* Remove separate "internal error" from exec

* Fix unknown command error regex

* Add message about command not found regex

* Silence errors while reading files in exec

The stdout and stderr files may never be opened or written to in certain
circumstances. In particular, if the timeout is short enough, the child
node process does not have enough time to start, and the child script
does not execute, so the files are not written to. So, catch errors form
trying to read the files, and ignore them.

* Do not silence errors due to short timeouts

* Simplify test regex for missing command

* Default error code to 1 if not set
2018-01-29 12:28:02 -08:00
Nate Fischer
cb9cf276cb
Revert "refactor(exec): remove paramsFile (#807)" (#819)
This reverts commit 64d5899abc86dd7b7fa84455c0ce3551786c4b5b.

Reason for revert: If stdin is large, then the param object can become
an extremely long string, exceeding the maximum OS size limit on
commandline parameters.

Original change's description:
> refactor(exec): remove paramsFile (#807)
>
> The `paramsFile` is obsolete now that we use `execFileSync()` for our
> internal implementation. Instead, we pass parameters to the child
> process directly as a single commandline parameter to reduce file I/O.
>
> Issue #782

Fixes #818
2018-01-19 16:33:34 -08:00
Nate Fischer
64d5899abc
refactor(exec): remove paramsFile (#807)
The `paramsFile` is obsolete now that we use `execFileSync()` for our
internal implementation. Instead, we pass parameters to the child
process directly as a single commandline parameter to reduce file I/O.

Issue #782
2017-11-16 12:43:54 -08:00
Nate Fischer
6189d7f8e5
Remove codeFile parameter (#791)
This parameter isn't needed, we can easily rely on exit code status for this.

Eliminating the parameter reduces file IO, code complexity, and removes a busy
loop.

This also removes some legacy code related to streams.

Issue #782
2017-10-31 15:51:18 -07:00
Nate Fischer
b885590e0f Use execFileSync to launch child process (#790)
This uses `child_process.execFileSync` instead of `execSync` to launch the child
process. This further reduces the attack surface, removing a possible point for
command injection in the ShellJS implementation.

This does not affect backwards compatibility for the `shell.exec` API (the
behavior is determined by the call to `child_process.exec` within
`src/exec-child.js`).

Issue #782
2017-10-26 20:33:04 -07:00
Nate Fischer
9e3f9abd2a refactor(exec): move child process to source file (#786)
This PR refactors `shell.exec()` by putting its child process in a separate code
file. This also slightly cleans up dead code.

There's more potential to clean this up (e.g. exit status), but this is a good
enough start.

Issue #782
2017-10-19 13:19:52 -07:00
Brandon Freitag
dcead1be86 Add "encoding" option to exec (#763)
* Add 'encoding' option to shell.exec

* Add 'encoding' option to docs

* Add exec encoding option tests

* Clarify use of encoding with fs.readFileSync

* Add check for stderr buffer
2017-09-13 16:18:28 -07:00
Nate Fischer
5823ab18bb test(exec): add tests for coverage (#744)
* test(exec): add tests for coverage

No logic change.

This adds one test to cover some missing lines, and adds some `istanbul ignore`
directives.

I see 100% line coverage for `src/exec.js` when running:

```sh
$ nyc --reporter=text --reporter=lcov ava --serial test/exec.js`
```

Fixes #742

* Fix lint
2017-06-17 19:09:01 -07:00
Nate Fischer
f74e783890 chore: remove v0.12 and iojs support (#648)
Fixes #647
2017-06-06 21:10:27 -07:00
Nate Fischer
5318fdc43a docs: miscellaneous README changes (#661)
- Add @freitagbr to the bottom of the README
 - Remove docs about shjs (it's not well supported)
 - Remove docs about coffeescript (we don't do anything special for
   coffeescript anyway)
 - Modify the section about shelljs/global, since we strongly recommend
   avoiding this now
 - Rewrite the code example to use `require('shelljs')` instead of
   shelljs/global
 - Mention ESLint next to JSHint
 - Reformat sections with long lines to be 80 columns
2017-03-04 01:07:23 -08:00
Nate Fischer
84ffb386eb chore(lint): Enforce a trailing comma for multi-line (#646) 2017-01-16 12:45:14 -08:00
Nate Fischer
4c48631d74 refactor: create common.execPath (#636)
Switch to using common.execPath instead of process.execPath directly and warn
electron users if we were unable to find the correct path to NodeJS.
2017-01-08 13:52:39 -08:00
Nate Fischer
4a1bce8815 fix: handle code-less errors more carefully in exec (#554)
If an error exists, but has no error code, it defaults to 1 (a common code for
most Unix commands). Tests have been omitted since this is an edge case that is
difficult to reproduce.

Fixes #536
2016-11-16 21:51:08 -08:00
Nate Fischer
4975b54a4f feat: plugin.error() takes an options parameter (#535)
This implements the following options: `continue`, `code`, `prefix`, & `silent`.

Fixes #522, #523
2016-10-23 23:17:42 -07:00
Gyandeep Singh
93ea025755 Revert "refactor: replace fs.existsSync" (fixes #531) (#532)
This reverts commit ab8cf5a8e027b28fc7b784587e4339d2b6d0f08f.
2016-10-17 20:14:43 -07:00
Nate Fischer
ab8cf5a8e0 refactor: replace fs.existsSync (#509)
* refactor: replace fs.existsSync

* fix: add support for v0.10
2016-08-20 18:28:49 -07:00
Nate Fischer
a0c9032072 refactor: readFromPipe() requires no arguments (#506) 2016-08-13 15:50:31 -07:00
Nate Fischer
2395214fee chore: switch to eslint (#504)
* chore: switch to eslint

* fix: works on older versions of NodeJS now

* chore: fix curly braces

* chore: fix indents and remove jshint references
2016-08-07 12:16:29 -07:00
Nate Fischer
d4111763a9 refactor: glob by default for commands (#492) 2016-07-27 16:43:01 -07:00
Nate Fischer
11141a35ba refactor: switch from notUnix to unix in wrap() (#491) 2016-07-27 09:27:12 -07:00
Nate Fischer
3951a87913 refactor: commands now register themselves (#475) 2016-07-21 17:37:11 -07:00
Nate Fischer
497149cc23 docs(exec): explicitly mention the shell option (#449) 2016-05-27 08:31:40 -07:00
Nate Fischer
b162a2ffe6 Merge pull request #419 from shelljs/docs-exec-return-value
docs(exec): fix docs about exec return type
2016-04-05 21:23:19 -07:00
Nate Fischer
27a760299c refactor: more commands return ShellStrings, tests for code 2016-03-15 19:48:13 -07:00
Nate Fischer
5bcbc619e4 feat: adding error codes to ShellJS 2016-03-15 19:21:08 -07:00
Nate Fischer
db20acebfb Switch to process.execPath over 'node' 2016-03-10 17:06:32 -08:00
Nate Fischer
98fc7f48ef feat(pipe): add support for pipes between commands 2016-02-20 22:26:31 -08:00
Ari Porad
d0b7d0943f Merge pull request #360 from shelljs/refactor-shellstring
refactor(ShellString): refactor shellstring
2016-02-20 14:51:19 -08:00
Nate Fischer
6ebc2d3db7 refactor(shellstring): return consistent objects
- fix(string): no longer overrides string prototype
 - exec() now returns a ShellString object
2016-02-19 14:54:30 -08:00
Nate Fischer
951376b300 fix(exec): properly handles paths with spaces and quotes 2016-02-18 18:22:38 -08:00
Ari Porad
7531d3a0ee Merge pull request #354 from shelljs/fix-exec-temp-files
fix(exec): temp files are now cleaned up
2016-02-14 08:49:57 -08:00
Nate Fischer
b63dde5d1a fix(exec): now actually supports shell option 2016-02-13 20:45:32 -08:00
Nate Fischer
fed412ff1b fix(exec): temp files are now cleaned up 2016-02-11 15:20:32 -08:00
Nate Fischer
164a214e5a use common.extend 2016-02-04 12:17:01 -08:00
Nate Fischer
058bb679b0 feat(exec): allow all exec options to pass through 2016-02-03 20:54:41 -08:00
Nate Fischer
900384bda8 Now runs jshint on the src/ folder. This fixes the pre-existing lint issues 2016-01-19 00:25:21 -08:00
Martino Visintin
d520a340e8 update exec docs to match implemented behaviour 2016-01-14 12:44:05 +01:00
Nate Fischer
8a7f7ceec4 add exec.stdout
Change `exec.output` to `exec.stdout` and deprecate `output`.
2016-01-12 17:14:13 -08:00
Nate Fischer
74f1ff8748 Commands that have multiple errors now produce cleaner log output. Errors are
echoed to stderr. exec() supports a new stderr field.
2016-01-12 17:02:19 -08:00
Julian Laval
3d01d64385 Patched stream closing issue 2015-08-11 16:50:10 +01:00
Julian Laval
ab142f522f Manually closing streams 2015-08-11 09:53:37 +01:00
Charlie Rudolph
86e2d57cbc prevent internal error: write after end 2015-07-02 15:53:36 -07:00
Tristan Davies
4dca63ac33 100% more execSync, 99% less busywait 2015-02-25 09:28:06 -05:00
Artur Adib
8df40dcf10 exec: don't output error msg when exit code > 0 2013-09-11 18:50:25 -04:00
Nils Bunger
d97c34627c Make shell.exec() treat process error return codes as shelljs errors 2013-09-08 17:16:08 -07:00
Artur Adib
561b1ea99c factoring docs, sed.js fix 2013-08-25 18:09:31 -04:00
Artur Adib
e0855c3cff exec,tempdir 2013-08-25 16:48:44 -04:00