Inside my script I want to use some functionality from yarn/npm
Like get results of yarn info packageName. I could spawn command and get output, but I believe there should be more correct way to do that.
Can't find any documentation about usage of yarn as package. Any ideas?
NPM and Yarn were designed as CLI tools. It's possible to load them with require but since executable script does a lot of work on options processing, this isn't practical.
The most straightforward and predictable way is to run them with child_process spawn or exec. There are npm-programmatic and yarn-programmatic third-party packages that do this internally. Since their APIs don't necessarily cover 100% of CLI functionality, it may still be beneficial to run commands directly.
There are open issues for NPM and Yarn regarding programmatic use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With