Package detail

package-run

bconnorwhite100MIT3.0.1

Node API for running package.json scripts. Supports yarn, npm, and pnpm.

package, pkg, run, yarn

readme

package-run

npm typescript Coveralls Status


Node API for running package.json scripts. Supports yarn, npm, and pnpm.


If I should maintain this repo, please ⭐️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter Follow


Scripts will automatically run with the correct package manager (yarn, npm, or pnpm) if a lockfile is present.

For npm, if a the given script exists in packge.json it will be run using npm run.
Otherwise, npx --no-install will be used.

Installation

yarn add package-run
npm install package-run
pnpm install package-run

Usage

import run, { executableToString } from "package-run";

run({
  command: "babel",
  args: [
    "./src",
    {
      "out-dir": "./build",
      "config-file": "./babel.config.json",
      "watch": true
    }
  ]
}, {
  slient: false // If true, will not output from yarn/npm/npx.
});

// Equivalent of:
// yarn run babel ./src --out-dir ./build --config-file ./babel.config.json --watch
// npx --no-install babel ./src --out-dir ./build --config-file ./babel.config.json --watch
// pnpm run babel ./src --out-dir ./build --config-file ./babel.config.json --watch

executableToString({
  command: "babel",
  args: [
    "./src"
    {
      "out-dir": "./build",
      "config-file": "./babel.config.json",
      "watch": true
    }
  ]
});

// "yarn run babel ./src --out-dir ./build --config-file ./babel.config.json --watch"

Types

function run(executable: Executable, options?: RunOptions): Promise<ExecResult>;

function getString(executable: Executable, options?: RunOptions): Promise<string>;

type Executable = {
  command: string;
  args?: Args;
  cwd?: string;
  env?: NodeJS.ProcessEnv;
  silent?: boolean;
}

type Args = Arg | Arg[];

type Arg = string | Flags;

type Flags = {
  [flag: string]: string | number | boolean  | string[] | undefined;
}

type ExecResult = {
  output: string;
  error: string;
  textOutput: string; // output stripped on ANSI colors
  textError: string; // error stripped on ANSI colors
  jsonOutput: () => JSONObject | JSONArray | undefined; // First JSON object or array in output
  jsonError: () => JSONObject | JSONArray | undefined; // First JSON object or array in error
}

type RunOptions = {
  silent?: boolean | undefined;
}


Dependenciesdependencies


Dev Dependencies

  • @types/mock-fs: TypeScript definitions for mock-fs
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
  • mock-fs: A configurable mock file system. You know, for testing.


License license

MIT - The MIT License

changelog

3.0.1 (2023-01-08)

Bug Fixes

2.0.8 (2021-07-12)

Bug Fixes

2.0.7 (2021-06-26)

Bug Fixes

2.0.6 (2021-04-17)

Bug Fixes

2.0.5 (2021-04-17)

2.0.4 (2021-04-17)

2.0.3 (2020-09-26)

Bug Fixes

2.0.2 (2020-09-21)

Bug Fixes

  • set cli width correctly (c844b6a)

2.0.1 (2020-09-21)

Bug Fixes

2.0.0 (2020-09-21)

1.4.1 (2020-09-06)

1.4.0 (2020-09-06)

1.3.2 (2020-09-06)

1.3.1 (2020-09-06)

1.3.0 (2020-09-06)

1.2.4 (2020-09-06)

1.2.3 (2020-09-06)

1.2.2 (2020-09-06)

1.2.1 (2020-09-05)

1.2.0 (2020-09-05)

1.1.7 (2020-08-17)

1.1.6 (2020-08-17)

1.1.5 (2020-08-17)

1.1.4 (2020-08-10)

1.1.3 (2020-08-10)

1.1.2 (2020-08-10)

1.1.1 (2020-08-10)

1.1.0 (2020-08-10)

1.0.2 (2020-08-10)

1.0.1 (2020-08-09)