# yarn-or-npm

> Use Yarn or npm to execute a command

Latest version **3.0.1** (published 2019-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install yarn-or-npm
pnpm add yarn-or-npm
yarn add yarn-or-npm
bun add yarn-or-npm
```

Provides the commands `yon`, `yarn-or-npm`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-08-21 |
| First published | 2016-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.6.0 |
| Dependencies | 2 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Patrick Camacho |
| Maintainers | camacho |
| Keywords | yarn, npm, spawn, command |

## Links

- npm: https://www.npmjs.com/package/yarn-or-npm
- Repository: git@github.com:camacho/yarn-or-npm
- npm.io page: https://npm.io/package/yarn-or-npm

## Dependencies (2)

- [pkg-dir](https://npm.io/package/pkg-dir.md) ^4.2.0
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^6.0.5

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2019-08-21
- 3.0.0 — 2019-07-24
- 2.0.4 — 2017-04-19
- 2.0.3 — 2017-01-26
- 2.0.2 — 2016-11-02
- 2.0.1 — 2016-11-02
- 2.0.0 — 2016-11-02
- 1.2.0 — 2016-11-02
- 1.1.0 — 2016-11-02

## README

# yarn-or-npm

Execute scripts with Yarn or npm.

```sh
yarn add -D yarn-or-npm
# or
npm i --save-dev yarn-or-npm
```

The client is determined by a series of ordered checks:

1. `yarn.lock` file is in the nearest package directory - **yarn**
1. `package-lock.json` file is in the nearest package directory - **npm**
1. `yarn` is installed - **yarn**
1. Fallback - **npm**

## Module

```js
import yarnOrNpm, { spawn, hasYarn, hasNpm } from 'yarn-or-npm';

// String of `yarn` or `npm` returned
console.log(yarnOrNpm());

// Boolean values for hasYarn, hasNpm
console.log(hasYarn());

// Spawn yarn or npm command
spawn(['init']);

// Spawn sync option
spawn.sync(['init'], { stdio: 'inherit' });
```

Under the covers, there are cached lookup values being used for efficiency. These can be manually cleared:

```js
import yarnOrNpm from 'yarn-or-npm';
import { spawnSync } from 'child_process';

console.log(yarnOrNpm.hasYarn()); // false

spawnSync('npm', ['i', '-g', 'yarn'], { stdio: 'inherit' });

console.log(yarnOrNpm.hasYarn()); // false (cached)

yarnOrNpm.clearCache();
console.log(yarnOrNpm.hasYarn()); // true
```

## CLI

```sh
yarn-or-npm <command>
# Can also use `yon` shorthand
yon <command>
```

## Package

Modules with bin files can be called directly in `package.json` scripts:

```json
{
  "devDependencies": {
    ...
    "yarn-or-npm": "^1.0.0"
  },
  "scripts": {
    "compile": "babel src --out-dir dist",
    "lint": "eslint .",
    "prepublish": "yarn-or-npm run lint && yarn-or-npm run compile"
  }
}
```

---
_Source: https://npm.io/package/yarn-or-npm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
