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.
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
Pub already has a run command, so it might make more sense to support scripts via something like run-script.
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.In my head, the process would be something like the following:
pub get.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.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.
Duplicate of #1192.