npm / npm/rfcs

[RRFC] Build Google Wireit's script runner into npm

Open
#706 7 comments 52 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
777
Forks
267
PR merge metrics
No merged PRs in 30d

Description

Motivation ("The Why")

There are a number of tools, and RRFCs (https://github.com/npm/rfcs/issues/190, https://github.com/npm/rfcs/issues/610 and https://github.com/npm/rfcs/issues/548, https://github.com/npm/rfcs/issues/691) that relate to running scripts in series, parallel, etc.

I opened https://github.com/npm/rfcs/issues/691 as a proposal to add pluggable script runners to npm to make using tools like Wireit easier. While I think that is a good idea, I honestly think that an even better solution is to build Wireit directly into npm, giving all npm uses the ability to define a graph of scripts and utilize caching, watch mode, and long-running services.

Wireit has a very robust feature set and implementation at this point, and has been designed to fit very seamlessly with the npm CLI's interface, configuration and workflow. It is not a tool that takes over and works over-top of npm, but one that tries to be as much of a part of npm as possible. As such, I think it should be quite easy to integrate with npm compared to tools that have their own CLI, config, and implementation (sometimes in non-JS languages).

Adding a full script graph with caching would solve all of the open issues around more powerful script running, and several issues that third-party tools cover now. For example, output caching can save significant build time for developers and CI. Services with watch mode make rebuilding and restarting servers on code changes (similar to nodemon) fast and seamless.

Example

It's probably best to view the Wireit repo for many examples of its features.

A basic Wireite configuration with dependencies between scripts looks like:

{
  "scripts": {
    "build": "wireit",
    "bundle": "wireit"
  },
  "wireit": {
    "build": {
      "command": "tsc"
    },
    "bundle": {
      "command": "rollup -c",
      "dependencies": ["build"]
    }
  }
}

Integrated into npm, this could look like:

{
  "scripts": {
    "build": "tsc",
    "bundle": {
      "command": "rollup -c",
      "dependencies": ["build"]
    }
  }
}
How
Current Behaviour

Currently, scripts are just strings with the command to run.

Desired Behaviour

I propose making scripts objects that describe their command, dependencies, inputs and output files (for caching) and more.

References

cc @aomarks, the author of Wireit

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the referenced npm RFCs (190, 610, 548, and 691) and the Google Wireit repository to compare the proposed script-runner capabilities. Done would require an agreed scope for integrating script objects, dependency graphs, caching, watch mode, and long-running services into npm.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.