Skip to content

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.

Breaking changes

  • 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 on v0.10.
  • All commands now return string-like objects (called ShellStrings), instead of regular JavaScript strings. The new ShellString type means we no longer have to modify the global String.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 the ShellString type: ShellString('this is a regular string').to('file1.txt'). Using strings currently still works for require('shelljs/global'), but this is deprecated, and we suggest you switch to using ShellStrings instead.
    • exec() used to return an object with the .output attribute. exec() now returns a ShellString, so .output has been permanently replaced with .stdout.
    • shell.exec(cmd).stdout.to('file.txt') used to work. Now you should use shell.exec(cmd).to('file.txt') instead.
  • 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. So cp('src/', 'dest/') creates dest/src/. If you need the old behavior back, try cp('src/*', 'dest/').

Awesome features

  • 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 with exec(). Try: echo(cd('fake directory').stderr, ls('fake file').code)
  • Bash compat: More consistent handling of symlinks, along with the -L and -P flags for cp().
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy