Nico Rodsevich Nico Rodsevich - 3 years ago 191
Dart Question

How to customize pub global executables

When I see my $HOME/.pub-cache/bin executables the normal template is:

#!/usr/bin/env sh
# This file was created by pub v1.24.2.
# Package: <package>
# Version: <package_version>
# Executable: <package>
# Script: <package>
pub global run <package>:<package> "$@"

However things go different with stagehand

#!/usr/bin/env sh
# This file was created by pub v1.24.2.
# Package: stagehand
# Version: 1.1.6
# Executable: stagehand
# Script: stagehand
dart "$HOME/.pub-cache/global_packages/stagehand/bin/stagehand.dart.snapshot" "$@"

# The VM exits with code 253 if the snapshot version is out-of-date.
# If it is, we need to delete it and run "pub global" manually.
if [ $exit_code != 253 ]; then
exit $exit_code

pub global run stagehand:stagehand "$@"

I would like to know how to achieve this customization without post-install hacks

Answer Source

The difference is that stagehand registers an executable.


This means you can just run stagehand and it works.

It also means that a snapshot is created for that executable (as you noticed).

See also

Add an executables section to your pubspec and you should be golden!

Edit: also, you won't get this with path-activated packages. The idea: ensure you keep running from your local source.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download