No change to logic. This updates some test cases to create the files
they need inside the temp directory instead of in the repo itself. This
is helpful in case the test case fails early, that way we don't leave
this file behind.
This contributes toward #828, since the change to fast-glob made it
clear that this test was mishandling link files and leaving side effects
in the git repo. However this change is desirably independent of
fast-glob.
This adds test coverage for the shell.exit() function. This also
refactors how we mock stdout/stderr and adds support for mocking
process.exit() (which was needed for this change).
While I was writing these tests, I realized there was an edge case I
missed in PR #1122. This change fixes that edge case.
Issue #1013
No change to logic. This expands on the `touch()` command documentation
to make it more obvious how to use multiple options, long options, etc.
This also renames a variable in a test case to make the usage more
obvious.
This fixes several issues with the cp -Ru test cases:
* Originally, I noticed the touch syntax looked wrong
* After fixing that, I was trying to figure out how the test case was
even passing before. I realized one of the assertions was wrong (it
was asserting sourceFile contents, but should have asserted destFile
contents)
* I realized the test should have created a nested destination
directory; without proper nesting, the sourceFile never actually
collided with destFile during the copy
* Lastly, I swapped touch() usage to use hardcoded timestamps for test
consistency
No change to logic. This adds a test case to make sure the caret
character ('^') is passed through to the command. This is to make sure
the character is not treated specially on Windows, where it's an escape
character in the shell.
Fixes#1015
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.