-
Notifications
You must be signed in to change notification settings - Fork 739
Migrating from v0.6 to v0.7
Nate Fischer edited this page Jan 17, 2022
·
8 revisions
Did we miss any features you like? Did we skip over any breaking changes you found? Feel free to document them below.
- We've dropped
v0.10
support. It should still work for now, but we'll only be fixing easy fixes for bugs on that platform. Some new features are not available onv0.10
. - All commands now return string-like objects (called
ShellStrings
), instead of regular JavaScript strings. The newShellString
type means we no longer have to modify the globalString.prototype
(See #159). If you need to pass the output of a ShellJS command to a non-ShellJS function, use.toString()
. Ex.if(fs.existsSync(which('git').toString())) { ... }
- Regular strings don't have the
.to()
and.toEnd()
methods anymore. You should convert them to theShellString
type:ShellString('this is a regular string').to('file1.txt')
. Using strings currently still works forrequire('shelljs/global')
, but this is deprecated, and we suggest you switch to usingShellStrings
instead. -
exec()
used to return an object with the.output
attribute.exec()
now returns aShellString
, so.output
has been permanently replaced with.stdout
. -
shell.exec(cmd).stdout.to('file.txt')
used to work. Now you should useshell.exec(cmd).to('file.txt')
instead.
- Regular strings don't have the
-
Bash compat:
cp()
has changed slightly when handling directories. It used to copy all the contents of a directory (not the directory itself), but now it copies the directory too. Socp('src/', 'dest/')
createsdest/src/
. If you need the old behavior back, trycp('src/*', 'dest/')
.
-
Support for pipes! Try out
grep('foo', 'file1.txt').sed(/o/g, 'a').to('file2.txt')
- Bash compat: Globbing available on all commands!
- Bash compat: Glob semantics and support are more consistent with Bash, now that we've switched the glob module
- Since all commands output
ShellString
objects, now you can check.stdout
,.stderr
, &.code
attributes on the return value just like you could do before withexec()
. Try:echo(cd('fake dir B71E ectory').stderr, ls('fake file').code)
-
Bash compat: More consistent handling of symlinks, along with the
-L
and-P
flags forcp()
.