Socket
Socket
Sign inDemoInstall

yarn-or-npm

Package Overview
Dependencies
2
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    yarn-or-npm

Use Yarn or npm to execute a command


Version published
Weekly downloads
169K
increased by3.01%
Maintainers
1
Install size
178 kB
Created
Weekly downloads
 

Readme

Source

yarn-or-npm

Execute scripts with Yarn or npm.

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
  2. package-lock.json file is in the nearest package directory - npm
  3. yarn is installed - yarn
  4. Fallback - npm

Module

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:

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

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

Package

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

{
  "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"
  }
}

Keywords

FAQs

Last updated on 21 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc