All Projects → BendingBender → Yarpm

BendingBender / Yarpm

Licence: mit
CLI tool to run npm scripts with either npm or yarn, depending on how it was started

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Yarpm

Np
A better `npm publish`
Stars: ✭ 6,401 (+49138.46%)
Mutual labels:  cli, npm, npm-package, yarn
Nls
Missing inspector for npm packages.
Stars: ✭ 44 (+238.46%)
Mutual labels:  npm-scripts, cli, npm, npm-package
Npm Run All
A CLI tool to run multiple npm-scripts in parallel or sequential.
Stars: ✭ 4,496 (+34484.62%)
Mutual labels:  npm-scripts, cli, npm, npm-package
Synp
Convert yarn.lock to package-lock.json and vice versa
Stars: ✭ 510 (+3823.08%)
Mutual labels:  npm, npm-package, yarn
Ni
💡 Use the right package manager
Stars: ✭ 179 (+1276.92%)
Mutual labels:  cli, npm, yarn
Jsonexport
{} → 📄 it's easy to convert JSON to CSV
Stars: ✭ 208 (+1500%)
Mutual labels:  cli, npm, npm-package
Getme
CLI utility for everyday tasks. With getme you get weather, forecast, currency rate, upload files, IP address, word definitions, text translations, internet speed, do google searches, get inspirational quotes and get Chuck Norris jokes
Stars: ✭ 118 (+807.69%)
Mutual labels:  cli, npm, npm-package
Awesome Node Utils
some useful npm packages for nodejs itself
Stars: ✭ 51 (+292.31%)
Mutual labels:  npm-scripts, npm, npm-package
Redrun
✨🐌 🐎✨ fastest npm scripts runner
Stars: ✭ 85 (+553.85%)
Mutual labels:  npm-scripts, cli, npm
Syncpack
Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces
Stars: ✭ 356 (+2638.46%)
Mutual labels:  cli, npm, yarn
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (+1869.23%)
Mutual labels:  npm, npm-package, yarn
Install Self Peers
Stars: ✭ 26 (+100%)
Mutual labels:  cli, npm, yarn
Script Progress
Estimate script execution time
Stars: ✭ 175 (+1246.15%)
Mutual labels:  cli, npm, yarn
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+1192.31%)
Mutual labels:  cli, npm, npm-package
Singlespotify
🎵 Create Spotify playlists based on one artist through the command line
Stars: ✭ 254 (+1853.85%)
Mutual labels:  cli, npm, npm-package
Ohshitgit
⁉️Oh shit! A cli tool to help you unfuck your git mistakes
Stars: ✭ 135 (+938.46%)
Mutual labels:  cli, npm, npm-package
Typac
install npm packages along with corresponding typings
Stars: ✭ 29 (+123.08%)
Mutual labels:  cli, npm, yarn
Emma Cli
📦 Terminal assistant to find and install node packages.
Stars: ✭ 1,201 (+9138.46%)
Mutual labels:  cli, npm, yarn
Nps
NPM Package Scripts -- All the benefits of npm scripts without the cost of a bloated package.json and limits of json
Stars: ✭ 1,285 (+9784.62%)
Mutual labels:  npm-scripts, cli, npm
Cpx
A cli tool to watch and copy file globs.
Stars: ✭ 394 (+2930.77%)
Mutual labels:  cli, npm, npm-package

yarpm

A CLI tool to run npm scripts with either npm or yarn, depending on how it was started. Useful for setups where some team members use npm while others use yarn, especially when Windows and Unix-like systems are used across the team.

This tool is a helper to run scripts from package.json. Just substitute all npm or yarn calls with yarpm and you're good to go:

{
  "scripts": {
    "start": "yarpm run build",
    "build": "tsc index.ts"
  }
}

When running the start script with yarn start, the dependent build script will be spawned with yarn:

~/test$ yarn start
yarn start v0.21.3
$ yarpm run build
yarn run v0.21.3
$ tsc index.ts
Done in 1.92s.
Done in 2.27s.

Running the same script with npm start will result in the dependent build being run with npm:

~/test$ npm start

> test@0.0.1 start /home/me/test
> yarpm run build


> test@0.0.1 build /home/me/test
> tsc index.ts

What this tool is not

This tool is not meant to be an abstraction layer for calling npm or yarn. It will pass all arguments it receives unfiltered to the chosen package manager. So you could create the following package.json and pass the -s flag to yarpm to silence npm output:

{
  "scripts": {
    "start": "yarpm run -s build",
    "build": "tsc index.ts"
  }
}

This will work if you invoke the script with npm start. Running the script with yarn start will result in the following error:

yarn run v0.21.3
error No command specified.
....

This is due to the fact that yarn doesn't understand the -s option. This is up to you to write your scripts so that only commands and options available to both npm and yarn are used.

Installation

$ npm install yarpm --save-dev
# or
$ yarn add yarpm --dev

CLI Commands

The yarpm package provides 2 CLI commands:

The main command is yarpm.

yarpm

This command is an in-place substitute for places in package.json where npm or yarn is being used explicitly. It reads the npm_execpath environment variable to determine the path to the currently used package manager. This env var is only set when running yarpm as a script. If yarpm is used without being embedded in a script, it will always choose npm.

yarpm-yarn

This command can be used in places where you are not in control of how your script is being started, for example when using husky to run a script as a git hook. This script will always prefer yarn over npm unless yarn is not available. Only then will it fall back to npm.

Node API

The yarpm package provides a node API.

const yarpm = require('yarpm');
const promise = yarpm(argv, options);
  • argv string[] -- The argument list to pass to npm/yarn.
  • options object|undefined
    • options.npmPath string - The path to npm/yarn. Default is process.env.npm_execpath if set, npm otherwise.
    • options.env object - Sets the environment key-value pairs, replaces the default usage of process.env to spawn child process.
    • options.stdin stream.Readable|null -- A readable stream to send messages to stdin of child process. If this is null or undefined, ignores it. If this is process.stdin, inherits it. Otherwise, makes a pipe. Default is null. Set to process.stdin in order to send from stdin.
    • options.stdout stream.Writable|null -- A writable stream to receive messages from stdout of child process. If this is null or undefined, cannot send. If this is process.stdout, inherits it. Otherwise, makes a pipe. Default is null. Set to process.stdout in order to print to stdout.
    • options.stderr stream.Writable|null -- A writable stream to receive messages from stderr of child process. If this is null or undefined, cannot send. If this is process.stderr, inherits it. Otherwise, makes a pipe. Default is null. Set to process.stderr in order to print to stderr.

yarpm returns a promise will be resolved when the spawned process exits, regardless of the exit code. The promise will be rejected in case of an internal error inside of yarpm.

The promise is resolved with an object with the following 2 properties: spawnArgs and code. The spawnArgs property contains the array of parameters that were passed to spawn the sub-process. The code property is the exit code of the sub-process.

yarpm(['install']).then(result => {
  console.log(`${result.spawnArgs} -- ${result.code}`);
  // if executed as a package.json script via yarn: /usr/share/yarn/bin/yarn.js,install -- 0
});

Changelog

https://github.com/BendingBender/yarpm/blob/master/CHANGELOG.md

Contributing

Thank you for contributing!

Bug Reports or Feature Requests

Please use GitHub Issues.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].