Pub: Pub should support build scripts

Created on 26 Jul 2017  路  1Comment  路  Source: dart-lang/pub

This isn't a high-priority issue, or even an issue at all, but a suggestion for feature that I feel would be helpful.

The idea: Just like how NPM supports scripts, i.e. postinstall, prepublish, it would be nice if Pub did as well. This would make it possible to do things such as compiling native extensions after installing them from Pub.

Pubspec Change

IMO, it would be best to just include scripts in the pubspec.yaml file:

name: my_package
scripts:
  greet: echo Hello World
  install: 
    - echo This is a postinstall script!!!
    - pub run-script greet

Command

Pub already has a run command, so it might make more sense to support scripts via something like run-script.

Supported Scripts

I think that Pub would only need to support about three scenarios:

  • install - Runs after a new version of the current package is installed, whether after the initial pub get, or a pub upgrade. Since Pub packages are cached, users wouldn't have to re-run the scripts each time they used a cache version of the package.
  • get - Runs after pub get. This script will only be run when developing the package; not if it is downloaded from Pub or another source.
  • upgrade - Same as get, except for that it would run after pub upgrade. Personally, I don't think it would even be necessary.

How it Works

In my head, the process would be something like the following:

  1. User runs pub get.
  2. For each package with an install script, the script is run. It might make sense to show the user the commands that will run, and allow them to opt out.
  3. If the local package has a get script, it is run as well. There probably won't need to be an opt-out feature here.

It might also be a good idea to include a flag to automatically run all scripts, i.e. --run-all-scripts.

Anyways, hopefully this is considered. I'm more than willing to send in a PR.

>All comments

Duplicate of #1192.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevmoo picture kevmoo  路  53Comments

sanjidtt picture sanjidtt  路  36Comments

crajygemer picture crajygemer  路  24Comments

goderbauer picture goderbauer  路  57Comments

devoncarew picture devoncarew  路  30Comments