On the latest version of Dart, dart pub global activate doesn't seem to work.
Example:
// bin/my_echo.dart
void main(List<String> args) {
for (final str in args) {
print(str);
}
}
// pubspec.yaml
name: my_echo
executables:
my_echo:
Then run:
dart pub global activate -s path .
my_echo "hello world"
This leads to:
/Users/remirousselet/.pub-cache/bin/my_echo: line 7: pub: command not found
Dart version:
Dart SDK version: 2.9.0-19.0.dev.flutter-f91547d6dd (be) (Sat Jun 27 19:14:41 2020 +0000) on "macos_x64"
I'm unable to reproduce on Linux or OSX at f91547d6dd or HEAD running directly from the Dart SDK. I'm also unable to reproduce on the latest Flutter beta channel on Linux so I'm going to close this for now.
If you're still running into this, it sounds like you might not have pub on your path.
@bkonyi the problem is that pub as a command line was removed. Instead we have dart pub.
But using dart pub global activate still tries to call the legacy pub cli.
As far as I know we haven't removed any of the legacy scripts for tooling, especially since this CLI isn't published on stable yet. We'll do eventually remove the standalone tool scripts, but not without an adequate deprecation warning. Building from HEAD still spits out a pub script when building the SDK.
That is not the case with the Flutter SDK
It ships only dart and flutter, as seen in its bin/ folder.
Ah, I see the problem here. It sounds like you have flutter/bin on your path but not flutter/bin/cache/dart-sdk/bin, which is where all the Dart tooling scripts live. We originally didn't expect people to be using the Dart SDK packaged with Flutter directly, so it's kind of buried in the artifacts (I think this is something changing in the future).
I see thanks!
Would it make sense to change the generated .pub-cache/bin/my_binary file to generate dart pub x instead of pub x instead?
That would fix the issue without exposing the raw pub cli
No problem!
Would it make sense to change the generated .pub-cache/bin/my_binary file to generate dart pub x instead of pub x instead?
That's not a bad idea. Thoughts @jwren?
No objection from me, but I am not familiar with all of the consequences of adding content to the generated .pub-cache. @bkonyi do you know who manages the generation of those files?
Maybe @jonasfj would know?
pub global activate manages the contents of $PUB_CACHE/bin/.
We are having a similar issue in https://github.com/dart-lang/pub/issues/2593
TL;DR: The contents of $PUB_CACHE/bin/ is generated when pub global activate <package> runs. But we might need to find a way to update scripts... especially given the changes happening with:
dart pub replacing pub (in particular, pub not shipping with Flutter, while dart pub does)./cc, @sigurdm we should talk about this tomorrow.
Just a reminder, I think flutter installation documentation leaves it easy to end up searching for this issue. It seems to suggest using the flutter/bin/dart, as read here: https://flutter.dev/docs/get-started/install/macos.
Note: As of Flutter鈥檚 1.19.0 dev release, the Flutter SDK contains the dart command alongside the flutter command so that you can more easily run Dart command-line programs.
...
After updating your shell for the change to take effect, running the which or where command again should show that the flutter and dart commands now come from the same directory.
But still, the solution above worked for me, adding flutter/bin/cache/dart-sdk/bin to PATH.
Most helpful comment
@bkonyi the problem is that
pubas a command line was removed. Instead we havedart pub.But using
dart pub global activatestill tries to call the legacypubcli.