-
Notifications
You must be signed in to change notification settings - Fork 742
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.10support. 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 newShellStringtype 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 theShellStringtype: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 usingShellStringsinstead. -
exec()used to return an object with the.outputattribute.exec()now returns aShellString, so.outputhas 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
ShellStringobjects, now you can check.stdout,.stderr, &.codeattributes on the return value just like you could do before withexec(). Try:echo(cd('fake directory').stderr, ls('fake file').code) -
Bash compat: More consistent handling of symlinks, along with the
-Land-Pflags forcp().