This adds an initial implementation of shell.cmd(), which is intended as
the eventual replacement for shell.exec(). This PR does not fully
implement the API, but demonstrates a simple and secure alternative, and
will allow further iteration to cover other use cases in follow-up PRs.
Design doc: https://shelljs.page.link/cmd-design
Issue #495
Test: automated test suite
No change to production logic.
This renames test cases with duplicate names, deletes a redundant test,
and uses the public `t.title` API in favor of `t._test.title`.
This is a prerequisite for updating ava.
Issue #969
This PR introduces a new boolean fatal option for the exec() function. Like the existing silent option, this new option allows you to override the global fatal configuration parameter on a per-command basis.
This updates `eslint-config-airbnb-base` and `eslint-plugin-import`.
This also addresses lint errors these updates raise, and excludes
several rules.
This also adds a minor simplification to the gendocs script.
Test: npm run lint
Test: npm run gendocs
This upgrades eslint to a new version to resolve a security warning.
This fixes a couple new lint errors, and disables some lint checks.
The current version of the airbnb lint config triggers
DeprecationWarnings in the new version of eslint. These warnings will be
resolved in a follow-up.
Test: npm run lint
* feat(options): initial support for long options
This adds initial support for long options. This integration tests them
with `shell.touch()` and unit tests them in `test/common.js`. This
documents the new syntax.
This also refactors some of the common internals:
* Creates a new CommandError type to replace the `'earlyExit'` hack
* Clearer Error types for `parseOptions()` exceptions
* Removes side effects from a test which modifies `common.config`
* Fixes appveyor and travis config to run lint (regressed in #920)
Issue #924
Test: touch.js, common.js
* small refactor for errorOptions
No change to production logic.
We never had coverage for `touch({'-d': ...})`, so this adds test
coverage. This also updates documentation to clarify the parameter
should be an instance of the `Date` type.
Test: `handles date argument` case
* fix(exec): consistent error message for maxBuffer
This explicitly checks for maxBuffer errors in exec-child.js and
provides a consistent error message. This modifies the test to verify
this.
This also supports the change in Node v10, which emits this as a
RangeError instead of a regular Error.
Although the error message is now explicit, this is not part of our API,
since it's just tacked onto the end of exec's stderr.
Fixes#915
* Remove debugging log, ignore uncovered lines
Previously, the cached `tempdir` value was stored in `common.state`.
Unlike the other `common.state` values, this isn't immediately useful to
other commands (they can just call the tempdir API). So, this moves the
cached value into `tempdir.js`.
This also adds a unit test for the caching behavior, and exposes
test-only helpers to verify this behavior.
Finally, this adds a note to `common.state` that values should generally
be considered read-only, since this can be important for customized
behavior. Although, I recognize our code base has one exception to this
rule (`echo()`), we should strive to maintain this.
Fixes#902
Test: Added a unit test.
Unconditionally apply `silent: true` when calling `common.error()` from
`exec()`. This is because errors are already printed to stderr, or are
intentionally silenced by `shell.config.silent`.
Based on #861Fixes#851
On Unix, this only matches files with the exec bit set. On Windows, this only
matches files which are readable (since Windows has different rules for
execution).
Fixes#657.
This fixes a conflict between mocks.init() and
utils.skipOnWin/skipOnUnix. mocks.init() mocks out process.stderr.write,
which utils.js implicitly depends on.
Instead, preserve stderr.write in a local variable to avoid polluting
mocked stdio and to correctly output warning messages.
Fixes#862
Test: locally apply mocks.init() inside test/which.js
* 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
This reworks the plugin API such that:
- Unable to register a command with unknown wrap-options
- `TypeError` raised for wrap-option type mistakes
- Remove the `overWrite` option (it's unused, probably safest to not
expose for now)
- `cmdOptions` defaults to `null` instead of `false` for type
consistency (no change to default behavior)
- Move `pipeMethods` logic into `_register`, since it makes more sense
there
This is not expected to have any effect on existing plugins.
Eslint rules can be configured either using words or number values:
* "off" or 0
* "warn" or 1
* "error" or 2
This switches our config to use the string values instead of the number
values, since the number values are too cryptic.
No change to our actual settings.
This adds the special option string `--`, which means "no options". This can be
passed if the first parameter looks like an option (starts with a `-` followed
by 1+ letters).
Fixes#778
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
Adds two new methods to src/common.js, common.statFollowLinks and common.statNoFollowLinks, which wrap fs.statSync and fs.lstatSync, respectively. This change is meant to improve readability and clarify intent.
* Add common.statFollowLinks and common.statNoFollowLinks
* Replace fs.statSync and fs.lstatSync in source files
* Added `-q` (quiet) option to `push`, `popd`, `dirs` functions.
* Added unit tests for pushd/popd quiet mode.
* Added tests for `pushd` and `popd` with quiet mode off.
* Updated docs for `pushd` and `popd` functions.
* Moved preliminary `pushd` commands for `popd` tests before disabling of silent flag.
This updates tests for `AVA` 19.0.0+.
`AVA` 0.18.0 has a breaking change which changes the current working directory
for tests. As a result, we need to change 'resources' -> 'test/resources' (and
similar path changes).
`AVA` 0.19.0 has a breaking change that all tests must run at least one assert.
This breaking change was already resolved by #746, so no change was necessary in
this PR.
This updates to `AVA` 0.21.0, since there are no other breaking changes.
This adds `skipOnWin` and `skipOnUnix` to help us manage our platform-dependent
tests. These methods give a nice warning message when we skip tests. We may also
consider adding warnings when running platform-dependent tests.
Part of the motivation for this is if we ever update to AVA v0.19. This version
requires at least one assertion per test case. While this could be disabled with
an AVA setting, we instead benefit from warnings for any case when we
unintentionally skip assertions.
This adds chalk as a dev dependency to enable colored messages.
* 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
This adds a test for `head()` on the right-hand side of a pipe. This also
removes the try-catch surrounding `fs.openSync()`, because it was unreachable
code. `fs.existsSync()` guarantees that the file exists, and `fs.openSync()`
only throws if the file does not exist, according to official documentation.
Fixes#671
* Add stdout/stderr test mocks
* Mock stdout/stderr during echo tests
* Fix lint issues
* Use 'use strict'
* Re-implement mocks as a prototype
* Implement mocks as a single-instance
* Remove redundant test
* Create mocked stdout/stderr.write methods once
* Add newline to output of echo (#557)
* Add newline to output of echo
* Add test
* Throw an error if the options string does not start with '-' (#615)
* Throw an error if the options string does not start with '-'
* Add test
* Change message grammar
* Add -n option to echo
* Fix null argument issue
* Add -n tests
* Add documentation
* Add -en escaped character test
* Add function to parse options for echo
* Use parseOptions to parse echo options
* Simplify control flow
* parseOptions throws now
* Allow null to be echoed
* Prevent echo stderr on unrecognized option
* Add test to check stderr of returned value
* Use consistent variable name
* Change test message, leave TODO about console output
* fix(mkdir): improve error handling around files
In particular, this fixes:
- if we try to overwrite a file with a mkdir
- if we try to create a subdirectory of a file
- adds `continue: true` in spots where we missed it
Fixes#720
* Fixing tests on Windows
* fix(cat): do not cat directories
Fixes#707
* fix(head): do not let head() read directories
Also fixes a typo
* fix(sort): do not sort directories
Also fixes a typo
* fix(tail): do not let tail() read directories
Also fixes a typo
* fix(uniq): do not let uniq() read directories
We also had a test which called sort() instead of uniq(), so we never
actually tested the missing-file case. This fixes that as well.
This also throws an error for using a directory as output.
* fix(pipe): fix breakages with piped commands
* cp: add error to not overwrite recently created files #631
* cp: add tests for errors not overwrite recently created files #631
* mv: show error when overwriting recently created file #631
* mv: add tests for error on recently created files #631
* mv: test remove unnecessary steps #631
* rm -rf on a symlink to a dir deletes contents
* Fix comment typo
* Clarify comments
* Pass symlink directly to rmdirSync
* Skip rm -rf symlink test on windows