3.0.1 • Published 1 year ago

package-run v3.0.1

Weekly downloads
17
License
MIT
Repository
github
Last release
1 year ago

If I should maintain this repo, please ⭐️

DM me on Twitter if you have questions or suggestions.


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;
}
  • @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.

MIT - The MIT License

3.0.1

1 year ago

3.0.0

1 year ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.4

4 years ago

1.3.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago