Skip to content

Commit cd970af

Browse files
sigurdmcommit-bot@chromium.org
authored andcommitted
[Dart CLI] Embed pub in dartdev
This includes the following pub commits: git log --format="%C(auto) %h %s" 5b4df5a6f931c63622ac349602d6ef0367e8070f..fb72c1f774ca27556225b207185c0b6b6ab1c274 fb72c1f7 Make `run` available (but deprecated) in the embedding (#2698) 63b56ea4 Return the exit-code from commands (#2689) 7fc4e273 Deprecate top level (#2694) Change-Id: I5842b1ecb15fc7844d628e2ad5fb00e3f627dbff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168347 Commit-Queue: Sigurd Meldgaard <[email protected]> Reviewed-by: Sigurd Meldgaard <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Reviewed-by: Jonas Jensen <[email protected]>
1 parent 35d8386 commit cd970af

File tree

12 files changed

+51
-176
lines changed

12 files changed

+51
-176
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ Updated the Linter to `0.1.123`, which includes:
9191
* New option `dart pub outdated mode=null-safety` that will analyze your
9292
dependencies for null-safety.
9393
* `dart pub publish` will now check your pubspec keys for likely typos.
94-
* `pub get` will print a warning if the resolution is in mixed-mode requiring
94+
* `dart pub get` will print a warning if the resolution is in mixed-mode requiring
9595
the code to run with `dart --no-sound-null-safety`.
96+
* New command `dart pub login` that logs in to pub.dev.
9697

9798
## 2.10.3 - 2020-10-29
9899

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ vars = {
132132
"ply_rev": "604b32590ffad5cbb82e4afef1d305512d06ae93",
133133
"pool_rev": "eedbd5fde84f9a1a8da643b475305a81841da599",
134134
"protobuf_rev": "3746c8fd3f2b0147623a8e3db89c3ff4330de760",
135-
"pub_rev": "5b4df5a6f931c63622ac349602d6ef0367e8070f",
135+
"pub_rev": "900e796a37fd9f68de9dd183cf4798fe5f055eaa",
136136
"pub_semver_tag": "v1.4.4",
137137
"resource_rev": "6b79867d0becf5395e5819a75720963b8298e9a7",
138138
"root_certificates_rev": "7e5ec82c99677a2e5b95ce296c4d68b0d3378ed8",

pkg/dartdev/lib/dartdev.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import 'package:cli_util/cli_logging.dart';
1212
import 'package:dart_style/src/cli/format_command.dart';
1313
import 'package:nnbd_migration/migration_cli.dart';
1414
import 'package:pedantic/pedantic.dart';
15+
import 'package:pub/pub.dart';
1516
import 'package:usage/usage.dart';
1617

1718
import 'src/analytics.dart';
1819
import 'src/commands/analyze.dart';
1920
import 'src/commands/compile.dart';
2021
import 'src/commands/create.dart';
2122
import 'src/commands/fix.dart';
22-
import 'src/commands/pub.dart';
2323
import 'src/commands/run.dart';
2424
import 'src/commands/test.dart';
2525
import 'src/core.dart';
@@ -194,7 +194,7 @@ class DartdevRunner extends CommandRunner<int> {
194194
addCommand(FixCommand());
195195
addCommand(FormatCommand(verbose: verbose));
196196
addCommand(MigrateCommand(verbose: verbose));
197-
addCommand(PubCommand());
197+
addCommand(pubCommand());
198198
addCommand(RunCommand(verbose: verbose));
199199
addCommand(TestCommand());
200200
}

pkg/dartdev/lib/src/commands/pub.dart

Lines changed: 0 additions & 88 deletions
This file was deleted.

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:io';
99

1010
import 'package:args/args.dart';
1111
import 'package:path/path.dart';
12+
import 'package:pub/pub.dart';
1213

1314
import '../core.dart';
1415
import '../experiments.dart';
@@ -153,69 +154,27 @@ class RunCommand extends DartdevCommand {
153154

154155
@override
155156
FutureOr<int> run() async {
156-
// The command line arguments after 'run'
157-
var args = argResults.arguments.toList();
157+
var mainCommand = '';
158+
var runArgs = <String>[];
159+
if (argResults.rest.isNotEmpty) {
160+
mainCommand = argResults.rest.first;
161+
// The command line arguments after the command name.
162+
runArgs = argResults.rest.skip(1).toList();
163+
}
158164
// --launch-dds is provided by the VM if the VM service is to be enabled. In
159165
// that case, we need to launch DDS as well.
160-
bool launchDds = false;
166+
String launchDdsArg = argResults['launch-dds'];
161167
String ddsHost = '';
162168
String ddsPort = '';
163-
164-
final launchDdsArg = args.singleWhere(
165-
(element) => element.startsWith('--launch-dds'),
166-
orElse: () => null,
167-
);
169+
bool launchDds = false;
168170
if (launchDdsArg != null) {
169171
launchDds = true;
170-
final ddsUrl = (launchDdsArg.split('=')[1]).split(':');
172+
final ddsUrl = launchDdsArg.split(':');
171173
ddsHost = ddsUrl[0];
172174
ddsPort = ddsUrl[1];
173175
}
174176

175-
var argsContainFile = false;
176-
for (var arg in args) {
177-
// The arg.contains('.') matches a file name pattern, i.e. some 'foo.dart'
178-
if (arg.contains('.')) {
179-
argsContainFile = true;
180-
} else if (!argsContainFile &&
181-
(arg == '--help' || arg == '-h' || arg == 'help')) {
182-
// Only print usage if a help flag is provided before the script name.
183-
printUsage();
184-
return 0;
185-
}
186-
}
187-
188-
var disableServiceAuthCodes =
189-
argResults['disable-service-auth-codes'] ?? false;
190-
191-
final cwd = Directory.current;
192-
if (!argsContainFile && cwd.existsSync()) {
193-
var foundImplicitFileToRun = false;
194-
var cwdName = cwd.name;
195-
for (var entity in cwd.listSync(followLinks: false)) {
196-
if (entity is Directory && entity.name == 'bin') {
197-
var filesInBin =
198-
entity.listSync(followLinks: false).whereType<File>();
199-
200-
// Search for a dart file in bin/ with the pattern foo/bin/foo.dart
201-
for (var fileInBin in filesInBin) {
202-
if (fileInBin.isDartFile && fileInBin.name == '$cwdName.dart') {
203-
args.add('bin/${fileInBin.name}');
204-
foundImplicitFileToRun = true;
205-
break;
206-
}
207-
}
208-
// break here, no actions taken on any entities that are not bin/
209-
break;
210-
}
211-
}
212-
213-
if (!foundImplicitFileToRun) {
214-
// This throws.
215-
usageException('Could not find the implicit file to run: '
216-
'bin$separator$cwdName.dart.');
217-
}
218-
}
177+
bool disableServiceAuthCodes = argResults['disable-service-auth-codes'];
219178

220179
// If the user wants to start a debugging session we need to do some extra
221180
// work and spawn a Dart Development Service (DDS) instance. DDS is a VM
@@ -231,20 +190,14 @@ class RunCommand extends DartdevCommand {
231190
}
232191
}
233192

234-
var path = args.firstWhere((e) => !e.startsWith('-'));
235-
final pathIndex = args.indexOf(path);
236-
final runArgs = (pathIndex + 1 == args.length)
237-
? <String>[]
238-
: args.sublist(pathIndex + 1);
193+
String path;
239194
try {
240-
path = Uri.parse(path).toFilePath();
241-
} catch (_) {
242-
// Input path will either be a valid path or a file uri
243-
// (e.g /directory/file.dart or file:///directory/file.dart). We will try
244-
// parsing it as a Uri, but if parsing failed for any reason (likely
245-
// because path is not a file Uri), `path` will be passed without
246-
// modification to the VM.
195+
path = await getExecutableForCommand(mainCommand);
196+
} on CommandResolutionFailedException catch (e) {
197+
log.stderr(e.message);
198+
return errorExitCode;
247199
}
200+
248201
VmInteropHandler.run(path, runArgs);
249202
return 0;
250203
}

pkg/dartdev/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies:
2121
path: ../nnbd_migration
2222
path: ^1.0.0
2323
pedantic: ^1.9.0
24+
pub:
25+
path: ../../third_party/pkg/pub
2426
stagehand: 3.3.7
2527
telemetry:
2628
path: ../telemetry

pkg/dartdev/test/analytics_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ void main() {
8686
expect(extractAnalytics(result), [
8787
{
8888
'hitType': 'screenView',
89-
// TODO(sigurdm): this should be pub/get
90-
'message': {'viewName': 'pub'}
89+
'message': {'viewName': 'pub/get'}
9190
},
9291
{
9392
'hitType': 'event',
9493
'message': {
9594
'category': 'dartdev',
96-
'action': 'pub',
95+
'action': 'pub/get',
9796
'label': null,
9897
'value': null,
9998
'cd1': '0',
99+
'cd3': ' dry-run '
100100
}
101101
},
102102
{
103103
'hitType': 'timing',
104104
'message': {
105-
'variableName': 'pub',
105+
'variableName': 'pub/get',
106106
'time': isA<int>(),
107107
'category': 'commands',
108108
'label': null

pkg/dartdev/test/commands/flag_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void command() {
4242
command.name != 'pub') {
4343
expect(command.argParser.usageLineLength,
4444
stdout.hasTerminal ? stdout.terminalColumns : null);
45+
} else if (command.name == 'pub') {
46+
// TODO(sigurdm): Avoid special casing here.
47+
// https://github.com/dart-lang/pub/issues/2700
48+
expect(command.argParser.usageLineLength,
49+
stdout.hasTerminal ? stdout.terminalColumns : 80);
4550
} else {
4651
expect(command.argParser.usageLineLength, isNull);
4752
}

pkg/dartdev/test/commands/help_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ void help() {
3737
}
3838
});
3939

40-
test('(help pub == pub help)', () {
40+
test('(help pub == pub --help)', () {
4141
p = project();
4242
var result = p.runSync('help', ['pub']);
43-
var pubHelpResult = p.runSync('pub', ['help']);
43+
var pubHelpResult = p.runSync('pub', ['--help']);
4444

4545
expect(result.stdout, contains(pubHelpResult.stdout));
4646
expect(result.stderr, contains(pubHelpResult.stderr));

pkg/dartdev/test/commands/pub_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ void pub() {
2020
void _assertPubHelpInvoked(ProcessResult result) {
2121
expect(result, isNotNull);
2222
expect(result.exitCode, 0);
23-
expect(result.stdout, contains('Pub is a package manager for Dart'));
24-
expect(result.stdout, contains('Available commands:'));
23+
expect(result.stdout, contains('Work with packages'));
24+
expect(result.stdout, contains('Available subcommands:'));
2525
expect(result.stderr, isEmpty);
2626
}
2727

2828
test('implicit --help', () {
29-
_assertPubHelpInvoked(project().runSync('pub', []));
29+
final result = project().runSync('pub', []);
30+
expect(result, isNotNull);
31+
expect(result.exitCode, 64);
32+
expect(result.stderr, contains('Missing subcommand for "dart pub".'));
33+
expect(result.stderr, contains('Available subcommands:'));
34+
expect(result.stdout, isEmpty);
3035
});
3136

3237
test('--help', () {
@@ -39,7 +44,7 @@ void pub() {
3944

4045
test('help cache', () {
4146
p = project();
42-
var result = p.runSync('pub', ['help', 'cache']);
47+
var result = p.runSync('help', ['pub', 'cache']);
4348
var result2 = p.runSync('pub', ['cache', '--help']);
4449

4550
expect(result.exitCode, 0);
@@ -53,7 +58,7 @@ void pub() {
5358

5459
test('help publish', () {
5560
p = project();
56-
var result = p.runSync('pub', ['help', 'publish']);
61+
var result = p.runSync('help', ['pub', 'publish']);
5762
var result2 = p.runSync('pub', ['publish', '--help']);
5863

5964
expect(result.exitCode, 0);

pkg/dartdev/test/commands/run_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ void run() {
6565
ProcessResult result = p.runSync('run', []);
6666

6767
expect(result.stdout, isEmpty);
68-
expect(result.stderr,
69-
contains('Could not find the implicit file to run: bin'));
70-
expect(result.exitCode, 64);
68+
expect(
69+
result.stderr,
70+
contains(
71+
'Could not find `bin/dartdev_temp.dart` in package `dartdev_temp`.'));
72+
expect(result.exitCode, 255);
7173
});
7274

7375
test('arguments are properly passed', () {

pkg/dartdev/test/core_test.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:dartdev/src/commands/analyze.dart';
99
import 'package:dartdev/src/commands/compile.dart';
1010
import 'package:dartdev/src/commands/create.dart';
1111
import 'package:dartdev/src/commands/fix.dart';
12-
import 'package:dartdev/src/commands/pub.dart';
1312
import 'package:dartdev/src/commands/run.dart';
1413
import 'package:dartdev/src/commands/test.dart';
1514
import 'package:dartdev/src/core.dart';
@@ -81,10 +80,6 @@ void _dartdevCommand() {
8180
_assertDartdevCommandProperties(FixCommand(), 'fix', 'fix');
8281
});
8382

84-
test('pub', () {
85-
_assertDartdevCommandProperties(PubCommand(), 'pub', 'pub');
86-
});
87-
8883
test('run', () {
8984
_assertDartdevCommandProperties(RunCommand(verbose: false), 'run', 'run');
9085
});

0 commit comments

Comments
 (0)