UNPKG

4.46 kBMarkdownView Raw
1# :runner: fuzz-run
2
3[![NPM version](https://img.shields.io/npm/v/fuzz-run.svg)](https://www.npmjs.com/package/fuzz-run)
4[![Build Status](https://github.com/sinedied/fuzz-run/workflows/build/badge.svg)](https://github.com/sinedied/fuzz-run/actions)
5![Node version](https://img.shields.io/node/v/fuzz-run.svg)
6[![Install size](https://packagephobia.now.sh/badge?p=fuzz-run)](https://packagephobia.now.sh/result?p=fuzz-run)
7[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
8[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
10> Run all your NPM scripts more easily with fuzzy matching.
11
12![demo gif](https://user-images.githubusercontent.com/593151/156170977-c9cfa19f-40a2-40b5-8c17-23180fbbc79a.gif)
13
14**Features:**
15- Fuzzy matching of NPM script name, optimized for commands (see [alternatives](#alternatives))
16- Yarn and PNPM support: automatically detect the package manager used and adapt commands accordingly
17- No need for `--` to pass extra options when using NPM
18- Extra actions for common recurrent tasks
19
20## Installation
21
22```sh
23npm install -g fuzz-run
24```
25
26## CLI Usage
27
28```sh
29Usage: fr <fuzzy_script_name>|<action> [script_options]
30Actions:
31 -u, --update Show outdated packages and run an interactive update
32 -r, --refresh Delete node_modules and lockfile, and reinstall packages
33```
34
35If no arguments are provided, it will list all available scripts.
36
37As the name of the script to run is fuzzy matched, you can try:
38- typing only some letters of the script name, regardless of their position (first letters weights more), like `t` for `test` script
39- typing first letter of compound script names like `tc` for `test:ci` script
40- making some typos, like `ets` for `test` script
41
42Note that you can use the alias `nr` (for **n**pm **r**un) instead of `fr` (**f**uzz **r**un) if you prefer :wink:
43
44You can pass any arguments to your script if needed, like `fr t --coverage`. You don't need to use `--` to pass extra options to your script like when using `npm` directly.
45
46### Actions
47
48There are a few scripted actions you can use for common day-to-day tasks in your projects:
49
50- `-u` or `--update`: It will show outdated packages, then ask if you want to update. If you accept, it will first update all package within their allowed range according to your `package.json` using `npm update`, `pnpm update` or `yarn upgrade`. Then it will run an interactive update, using under the hood `npx npm-check -u` if NPM or PNPM is your package manager or `yarn upgrade-interactive` if you use Yarn.
51- `-r` or `--refresh`: It will delete `node_modules` folder and lockfile, and reinstall all your packages. I probably use that more than I should, but it's always a handy fix.
52
53### Package manager
54
55Supported package managers are [NPM](https://www.npmjs.com), [Yarn](https://yarnpkg.com) and [PNPM](https://pnpm.io).
56
57By default, your package manager will be autodetected based on your project's lockfile format, and corresponding commands will be used.
58
59You can also force a package manager by setting the `NODE_PACKAGE_MANAGER` environment variable.
60
61## API
62
63You can also integrate this script runner in your own CLI by using the function `fuzzyRun(args, packageManager)`:
64
65- `args`: array of arguments, the same you would use for the CLI usage
66- `packageManager`: *optional*, can be `'npm'`, `'yarn'` or `'pnpm'` to force a specific command to run the scripts. If `null` or `undefined`, it will be autodetected based on your project's lockfile format.
67
68Example:
69```js
70const fuzzyRun = require('fuzzy-run');
71fuzzyRun(process.argv.slice(2));
72```
73
74## Alternatives
75- [fuzzy-npm-run](https://www.npmjs.com/package/fuzzy-npm-run)
76- [fuzzy-run](https://www.npmjs.com/package/fuzzy-run)
77
78Why making a new tool when some other exists, you might ask?
79Both are based on [fuse.js](http://fusejs.io) for the fuzzy matching, which is not great for matching commands, as it doesn't weight properly specific features like subcommands separation (using characters like `-`, `_`, `:`) or first character of words :disappointed:
80
81Some examples:
82- if you have 2 scripts `test` and `test:ci`, typing `tc` matches `test` instead of `test:ci`
83- if you have 2 scripts `test:ci` and `other`, typing `t` matches `other`
84
85So I benchmarked many fuzzy matching libraries, and kept the best one I found suited for the job, [fuzzysort](https://www.npmjs.com/package/fuzzysort), that solves these issues.