Skip to content
npm scripts viewer

npm scripts Flow Diagram (see the run order)

Paste the `scripts` of a package.json to see how scripts call each other (`npm run x`, `run-s`, `run-p`, `concurrently`), the `pre` / `post` hooks and the lifecycle scripts that `npm install` and `publish` trigger, as a diagram.
It also lists what runs in what order when you run a script, with the hooks and calls expanded.
It checks for things that break on Windows (a leading `NODE_ENV=production`, `rm -rf`…), calls to scripts that do not exist, cycles and hooks without a matching script. Everything is processed in your browser and never sent to a server.

Everything is processed in your browser and never sent to a server.

Overview

Arrows mean "calls when run". Dotted lines are hooks (pre / post) and "∥" is a call that runs in parallel. Under each node is the start of its command. Click a node for details and drag to move it.

Run order

The order in which things run for `npm run <name>`: pre → the body (each part joined by `&&` in turn; called scripts are expanded, including their own pre / post) → post.

    Things worth a look

    A mechanical check of how it is written. Shell syntax is not fully parsed, so some things can be missed and some findings may be intended.

    Guide

    How to use & features

    • Paste the contents of a package.json, or just the `scripts` object, into the box. A sample is loaded at first.
    • Scripts are nodes and "calls when run" are arrows. Dotted lines are `pre` / `post` hooks and "∥" marks calls that run in parallel (`run-p`, `concurrently`, `&`). Under each node is the start of its command.
    • Pick a script in "Run order" to list what runs in what order for `npm run <name>`, with hooks and calls expanded.
    • Click a node to see its command, what it calls, what calls it and the target of a hook. Drag nodes to move them and use "Save SVG" for an image.
    • "Things worth a look" lists calls to missing scripts, cycles, hooks without a matching script, the deprecated `prepublish` and syntax that breaks on Windows.
    FAQ

    FAQ

    • How do `pre` / `post` hooks run?

      `npm run build` runs `prebuild` → `build` → `postbuild`. A hook runs only when the matching script exists. The tool shows this with dotted arrows from `build` to `prebuild` and `postbuild`, and in the "Run order" list. Hooks themselves are not expanded with further hooks.
    • Does it show the scripts run by `npm install` or `npm publish`?

      Yes. For `npm ci` / `npm install` it expands `preinstall`, `install`, `postinstall`, `prepare` and so on; for `npm publish` it expands `prepublishOnly`, `prepack`, `prepare`, `publish` and so on; `npm pack` and `npm version` lifecycles too, **only when those scripts actually exist**, as things called from the script. Scripts that npm runs automatically get their own color.
    • Can it read `run-s`, `run-p` and `concurrently`?

      Yes. It reads `run-s a b` (in order), `run-p a b` (in parallel), `npm-run-all` (parallel with `--parallel`) and `concurrently "npm:watch-*" "npm run lint"`. Patterns such as `build:*` are expanded to the scripts that exist (`*` does not cross a colon).
    • Does it parse shell syntax completely?

      No. It splits on `&&`, `||`, `;` and `&` and reads only the call at the start of each part (such as `npm run x`). Variable expansion, control syntax such as `if`, and calls inside subshells are not read. Things can be missed, so treat the diagram as the rough structure.
    • Is my package.json sent to a server?

      No. Everything is processed in your browser and nothing is sent to a server.
    Use cases

    Common use cases

    • Check "what runs on `npm run build`?"

      See the run order, with `prebuild`, `postbuild` and other scripts called through `npm run` expanded, without running anything.
    • Read the scripts of an inherited package.json

      Even dozens of scripts become clear in a diagram: which calls which, and which are entry points.
    • Check that it works on Windows too

      Find a leading `NODE_ENV=production`, `rm -rf` and other Windows-breaking syntax before switching to `cross-env` or `rimraf`.
    • Before tidying up or refactoring scripts

      Find hooks that are never used, calls to missing scripts and cycles as a starting point for cleanup.
    Notes

    Notes & limitations

    • Shell syntax is not fully parsed

      It splits on `&&`, `||`, `;` and `&` and reads only the call at the start of each part. Variables, control syntax, subshells and calls inside `xargs` or `find -exec` are not read.
    • It does not run anything

      It does not run scripts or inspect what the commands do (what they write or delete). It only looks at the structure of calls.
    • Short forms of `yarn` / `pnpm` / `bun` only for existing scripts

      A call that is just a script name, like `yarn build`, is read only when a script of that name exists. Calls across workspaces (such as `--filter`) are not told apart.

    Articles for this tool

    Recent Articles