Add "pub run --list" command to show all available executables #2#1680
Add "pub run --list" command to show all available executables #2#1680jakemac53 merged 3 commits intodart-lang:masterfrom
Conversation
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
test/run/list_test.dart
Outdated
|
|
||
| await pubGet(); | ||
| var pub = await pubRun(args: ['--list']); | ||
| expect(await pub.stdoutStream().isEmpty, isTrue); |
There was a problem hiding this comment.
Not sure if this is the best way
jakemac53
left a comment
There was a problem hiding this comment.
Some additional small nits, it looks like the following still needs to be addressed from previous comments:
- move to the
pub depscommand - add support for
--dev, or add tests if it works
lib/src/command/run.dart
Outdated
| ..addAll(entrypoint.root.immediateDependencies | ||
| .map((dep) => entrypoint.packageGraph.packages[dep.name])); | ||
|
|
||
| packages.forEach((Package package) { |
There was a problem hiding this comment.
nit: prefer for (var package in packages) { ... } (see here).
lib/src/command/run.dart
Outdated
| return package | ||
| .listFiles(beneath: 'bin', recursive: false) | ||
| .where((executable) => p.extension(executable) == '.dart') | ||
| .map(p.basenameWithoutExtension); |
There was a problem hiding this comment.
Technically we should also check if these dart files have a top level main. You should be able to use parseDartFile from the analyzer to get the CompilationUnit, and then isEntrypoint from pub to do the check.
lib/src/command/run.dart
Outdated
| // If executable matches the package name omit the name of executable in | ||
| // the output. | ||
| return executables.first != packageName | ||
| ? '${log.bold(packageName)}:${executables.first}' |
lib/src/command/run.dart
Outdated
| return e1.compareTo(e2); | ||
| }); | ||
|
|
||
| return '${log.bold(packageName)}: ${executables.join(', ')}'; |
There was a problem hiding this comment.
ditto, probably don't bold the commas though so you will need to wrap each executable in bold and join
lib/src/command/run.dart
Outdated
| RunCommand() { | ||
| argParser.addFlag("checked", | ||
| abbr: "c", help: "Enable runtime type checks and assertions."); | ||
| argParser.addFlag('list', |
There was a problem hiding this comment.
To me once this moves to the deps command then --list is no longer descriptive enough (I would expect it to just list deps not executables). Maybe --list-executables?
There was a problem hiding this comment.
Actually it looks like @nex3 suggested just --executables, that sounds good to me as well and is a bit less verbose.
|
I've addressed small issues. Moving command as flag to |
|
looking good so far :) |
3cd5470 to
0976e90
Compare
|
While I have some code to cleanup and tests to fix before review, I have some open questions. Thanks in advance. |
lib/src/command/deps.dart
Outdated
| } | ||
|
|
||
| /// The immediate non-dev dependencies this package specifies in its pubspec. | ||
| List<PackageRange> _nonDevDependencies(Package package) { |
There was a problem hiding this comment.
Should I move this to a public API of Package? E.g. here: https://github.com/dart-lang/pub/blob/master/lib/src/package.dart#L78 right after immediateDependencies?
There was a problem hiding this comment.
I think that the dependencies getter is actually identical to this, so I would just use that.
There was a problem hiding this comment.
It does not include dependencyOverrides. Should I not care about them in such a case? (As they have the same binaries names)
There was a problem hiding this comment.
Yes the dependencyOverrides are not relevant here. I don't think you can use that to add additional dependencies, or at least its not a supported use of that field afaik.
lib/src/command/deps.dart
Outdated
| /// | ||
| /// Returns file names without extensions. | ||
| List<String> _getExecutablesFor(Package package) => package | ||
| .listFiles(beneath: 'bin', recursive: false) |
There was a problem hiding this comment.
There is already such a method in Package - executableIds. While I'm going to adapt _getExecutablesFor to use it, should _isDartExecutable be a part of executableIds?
There was a problem hiding this comment.
Hmm, good question. To me it seems like executableIds should already be doing an equivalent _isDartExecutable check, but technically changing it to do that would be a breaking change.
The actual isEntrypoint check for instance doesn't actually catch all cases, so technically we could break existing packages so you could no longer run their executable. In reality my guess is it would not break anything, but its possible it would.
cc @kevmoo @munificent what do you think?
|
|
||
| const _validMain = 'main() {}'; | ||
|
|
||
| main() { |
There was a problem hiding this comment.
I haven't found a good way to test the same things.
I was choosing between:
- for loop
- current approach
- even more test-fn-generators
There was a problem hiding this comment.
You could consider wrapping multiple calls to test in _testExecutablesOutput, something like this:
_testExecutablesOutput(String name, output, {devOutput}) {
devOutput ??= output;
for (var dev in [true, false]) {
test(name + dev ? ' --dev' : ' --no-dev', () async {
await pubGet();
await runPub(
args: ['deps', '--executables']
..addAll(dev ? ['--dev'] : ['--no-dev']),
output: dev ? devOutput : output);
});
}
}Up to you though, that pattern can make it hard to support the named args to test methods etc.
|
|
||
| const _validMain = 'main() {}'; | ||
|
|
||
| main() { |
There was a problem hiding this comment.
You could consider wrapping multiple calls to test in _testExecutablesOutput, something like this:
_testExecutablesOutput(String name, output, {devOutput}) {
devOutput ??= output;
for (var dev in [true, false]) {
test(name + dev ? ' --dev' : ' --no-dev', () async {
await pubGet();
await runPub(
args: ['deps', '--executables']
..addAll(dev ? ['--dev'] : ['--no-dev']),
output: dev ? devOutput : output);
});
}
}Up to you though, that pattern can make it hard to support the named args to test methods etc.
test/deps/executables_test.dart
Outdated
| setUp(() async { | ||
| await d.dir(appPath, [ | ||
| d.appPubspec(), | ||
| d.dir('binn', [d.file('foo.dart', 'main() {')]) |
test/deps/executables_test.dart
Outdated
| test("are skipped if --no-dev flag is set", _testNonDevDepsOutput('\n')); | ||
| }); | ||
|
|
||
| group("lists dependencies overrides", () { |
There was a problem hiding this comment.
One thing that would probably be worth adding is a test where you have two versions of foo in different directories with different files under bin. Make the original dep be a path dep to one of them, and override it to the other one. You should get a list of the binaries in the overridden one not the original (pretty sure this would pass today).
There was a problem hiding this comment.
I think it should still pass, the name of the dependencies doesn't change which is all we actually use, then we look up the package in the PackageGraph which should be overridden version.
If it doesn't pass, then I was wrong and we will need to do some more work to support this.
|
So I think that PR is ready for a review, while I still do not like how tests are done. By the way, thank you for your review time and suggestions. P.S. should I squash commit or you'll do it in case of merge? |
3172790 to
6d2f9c7
Compare
|
@antonmoiseev can you please confirm here that you are ok with your original commit being contributed to this project? |
|
@gagoman I can do the squash/merge if you don't mind, I will retain the original author information though (otherwise if you squash and force push I have to re-review everything since its really a new commit and github doesn't handle the diffs well in that case). |
|
Actually I changed my mind, since this PR isn't very large and I can't push to your branch it makes sense for you to just do the squash of your commits, feel free to do that at any time. |
* removed "run --list" command * buffer is used to output executables * tests were adapted to verify --dev/--no-dev flag
6d2f9c7 to
9c3d6e0
Compare
|
@jakemac53 done |
|
Everything LGTM, but unfortunately we have to wait for @antonmoiseev to respond here with his approval to merge the initial commit before this can be submitted :(. |
|
Sorry for the delay. Sure, please feel free to merge it if it's good enough.
On Mon, 14 Aug 2017 at 18:51, Jacob MacDonald ***@***.***> wrote:
Everything LGTM, but unfortunately we have to wait for @antonmoiseev
<https://github.com/antonmoiseev> to respond here with his approval to
merge the initial commit before this can be submitted :(.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1680 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AALKRTmRX5NzMzhxu6ZLy0DrqHrjhCgVks5sYF7dgaJpZM4Oql66>
.
--
Sent from iPhone
|
|
Thanks @antonmoiseev! |
Good day.
This is a new iteration of #1323 based of #1427 as I was not able to push to that PR.
For now I've performed a merge with
origin/masterand updated the tests.I'm going to address #1427 (comment)