Skip to content

Commit 9e3e111

Browse files
committed
Revert "Add flag controlling creation of .packages file. (dart-lang#2757)"
This reverts commit a246141.
1 parent 3082796 commit 9e3e111

File tree

69 files changed

+364
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+364
-674
lines changed

lib/src/command/add.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class AddCommand extends PubCommand {
9292
help: 'Build executables in immediate dependencies.');
9393
argParser.addOption('directory',
9494
abbr: 'C', help: 'Run this in the directory <dir>.', valueHelp: 'dir');
95-
argParser.addFlag('legacy-packages-file',
96-
help: 'Generate the legacy ".packages" file', negatable: false);
9795
}
9896

9997
@override
@@ -169,8 +167,7 @@ class AddCommand extends PubCommand {
169167
.acquireDependencies(SolveType.get,
170168
dryRun: true,
171169
precompile: argResults['precompile'],
172-
analytics: analytics,
173-
generateDotPackages: false);
170+
analytics: analytics);
174171
} else {
175172
/// Update the `pubspec.yaml` before calling [acquireDependencies] to
176173
/// ensure that the modification timestamp on `pubspec.lock` and
@@ -185,7 +182,6 @@ class AddCommand extends PubCommand {
185182
SolveType.get,
186183
precompile: argResults['precompile'],
187184
analytics: analytics,
188-
generateDotPackages: argResults['legacy-packages-file'],
189185
);
190186

191187
if (argResults['example'] && entrypoint.example != null) {
@@ -194,7 +190,6 @@ class AddCommand extends PubCommand {
194190
precompile: argResults['precompile'],
195191
onlyReportSuccessOrFailure: true,
196192
analytics: analytics,
197-
generateDotPackages: argResults['legacy-packages-file'],
198193
);
199194
}
200195
}

lib/src/command/downgrade.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class DowngradeCommand extends PubCommand {
4242

4343
argParser.addOption('directory',
4444
abbr: 'C', help: 'Run this in the directory<dir>.', valueHelp: 'dir');
45-
argParser.addFlag('legacy-packages-file',
46-
help: 'Generate the legacy ".packages" file', negatable: false);
4745
}
4846

4947
@override
@@ -59,7 +57,6 @@ class DowngradeCommand extends PubCommand {
5957
unlock: argResults.rest,
6058
dryRun: dryRun,
6159
analytics: analytics,
62-
generateDotPackages: argResults['legacy-packages-file'],
6360
);
6461
var example = entrypoint.example;
6562
if (argResults['example'] && example != null) {
@@ -69,7 +66,6 @@ class DowngradeCommand extends PubCommand {
6966
dryRun: dryRun,
7067
onlyReportSuccessOrFailure: true,
7168
analytics: analytics,
72-
generateDotPackages: argResults['legacy-packages-file'],
7369
);
7470
}
7571

lib/src/command/get.dart

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class GetCommand extends PubCommand {
3333

3434
argParser.addFlag('packages-dir', hide: true);
3535

36-
argParser.addFlag('legacy-packages-file',
37-
help: 'Generate the legacy ".packages" file', negatable: false);
38-
3936
argParser.addFlag(
4037
'example',
4138
help: 'Also run in `example/` (if it exists).',
@@ -56,20 +53,16 @@ class GetCommand extends PubCommand {
5653
SolveType.get,
5754
dryRun: argResults['dry-run'],
5855
precompile: argResults['precompile'],
59-
generateDotPackages: argResults['legacy-packages-file'],
6056
analytics: analytics,
6157
);
6258

6359
var example = entrypoint.example;
6460
if (argResults['example'] && example != null) {
65-
await example.acquireDependencies(
66-
SolveType.get,
67-
dryRun: argResults['dry-run'],
68-
precompile: argResults['precompile'],
69-
generateDotPackages: argResults['legacy-packages-file'],
70-
analytics: analytics,
71-
onlyReportSuccessOrFailure: true,
72-
);
61+
await example.acquireDependencies(SolveType.get,
62+
dryRun: argResults['dry-run'],
63+
precompile: argResults['precompile'],
64+
onlyReportSuccessOrFailure: true,
65+
analytics: analytics);
7366
}
7467
}
7568
}

lib/src/command/remove.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class RemoveCommand extends PubCommand {
5050

5151
argParser.addOption('directory',
5252
abbr: 'C', help: 'Run this in the directory<dir>.', valueHelp: 'dir');
53-
54-
argParser.addFlag('legacy-packages-file',
55-
help: 'Generate the legacy ".packages" file', negatable: false);
5653
}
5754

5855
@override
@@ -72,8 +69,7 @@ class RemoveCommand extends PubCommand {
7269
.acquireDependencies(SolveType.get,
7370
precompile: argResults['precompile'],
7471
dryRun: true,
75-
analytics: null,
76-
generateDotPackages: false);
72+
analytics: null);
7773
} else {
7874
/// Update the pubspec.
7975
_writeRemovalToPubspec(packages);
@@ -85,7 +81,6 @@ class RemoveCommand extends PubCommand {
8581
SolveType.get,
8682
precompile: argResults['precompile'],
8783
analytics: analytics,
88-
generateDotPackages: argResults['legacy-packages-file'],
8984
);
9085

9186
var example = entrypoint.example;
@@ -95,7 +90,6 @@ class RemoveCommand extends PubCommand {
9590
precompile: argResults['precompile'],
9691
onlyReportSuccessOrFailure: true,
9792
analytics: analytics,
98-
generateDotPackages: argResults['legacy-packages-file'],
9993
);
10094
}
10195
}

lib/src/command/upgrade.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ class UpgradeCommand extends PubCommand {
5656

5757
argParser.addFlag('packages-dir', hide: true);
5858

59-
argParser.addFlag('legacy-packages-file',
60-
help: 'Generate the legacy ".packages" file', negatable: false);
61-
6259
argParser.addFlag(
6360
'major-versions',
6461
help: 'Upgrades packages to their latest resolvable versions, '
@@ -83,8 +80,6 @@ class UpgradeCommand extends PubCommand {
8380

8481
bool get _precompile => argResults['precompile'];
8582

86-
bool get _packagesFile => argResults['legacy-packages-file'];
87-
8883
bool get _upgradeNullSafety =>
8984
argResults['nullsafety'] || argResults['null-safety'];
9085

@@ -131,7 +126,6 @@ class UpgradeCommand extends PubCommand {
131126
dryRun: _dryRun,
132127
precompile: _precompile,
133128
onlyReportSuccessOrFailure: onlySummary,
134-
generateDotPackages: _packagesFile,
135129
analytics: analytics,
136130
);
137131
_showOfflineWarning();
@@ -241,7 +235,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
241235
dryRun: true,
242236
precompile: _precompile,
243237
analytics: null, // No analytics for dry-run
244-
generateDotPackages: false,
245238
);
246239
} else {
247240
if (changes.isNotEmpty) {
@@ -254,7 +247,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
254247
SolveType.get,
255248
precompile: _precompile,
256249
analytics: analytics,
257-
generateDotPackages: argResults['legacy-packages-file'],
258250
);
259251
}
260252

@@ -339,7 +331,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
339331
dryRun: true,
340332
precompile: _precompile,
341333
analytics: null,
342-
generateDotPackages: false,
343334
);
344335
} else {
345336
if (changes.isNotEmpty) {
@@ -352,7 +343,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
352343
SolveType.upgrade,
353344
precompile: _precompile,
354345
analytics: analytics,
355-
generateDotPackages: argResults['legacy-packages-file'],
356346
);
357347
}
358348

lib/src/entrypoint.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,13 @@ class Entrypoint {
213213
Entrypoint? _example;
214214

215215
/// Writes .packages and .dart_tool/package_config.json
216-
Future<void> writePackagesFiles({bool generateDotPackages = false}) async {
216+
Future<void> writePackagesFiles() async {
217217
final entrypointName = isGlobal ? null : root.name;
218-
if (generateDotPackages) {
219-
writeTextFile(
220-
packagesFile,
221-
lockFile.packagesFile(cache,
222-
entrypoint: entrypointName,
223-
relativeFrom: isGlobal ? null : root.dir));
224-
} else {
225-
tryDeleteEntry(packagesFile);
226-
}
218+
writeTextFile(
219+
packagesFile,
220+
lockFile.packagesFile(cache,
221+
entrypoint: entrypointName,
222+
relativeFrom: isGlobal ? null : root.dir));
227223
ensureDir(p.dirname(packageConfigFile));
228224
writeTextFile(
229225
packageConfigFile,
@@ -261,7 +257,6 @@ class Entrypoint {
261257
Iterable<String>? unlock,
262258
bool dryRun = false,
263259
bool precompile = false,
264-
required bool generateDotPackages,
265260
required PubAnalytics? analytics,
266261
bool onlyReportSuccessOrFailure = false,
267262
}) async {
@@ -330,7 +325,7 @@ class Entrypoint {
330325
/// have to reload and reparse all the pubspecs.
331326
_packageGraph = PackageGraph.fromSolveResult(this, result);
332327

333-
await writePackagesFiles(generateDotPackages: generateDotPackages);
328+
await writePackagesFiles();
334329

335330
try {
336331
if (precompile) {

lib/src/executable.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ Future<DartExecutableWithPackageConfig> getExecutableForCommand(
308308
() => entrypoint.acquireDependencies(
309309
SolveType.get,
310310
analytics: analytics,
311-
generateDotPackages: false,
312311
),
313312
);
314313
} on ApplicationException catch (e) {

lib/src/global_packages.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ class GlobalPackages {
150150
var entrypoint = Entrypoint(path, cache);
151151

152152
// Get the package's dependencies.
153-
await entrypoint.acquireDependencies(
154-
SolveType.get,
155-
analytics: analytics,
156-
generateDotPackages: false,
157-
);
153+
await entrypoint.acquireDependencies(SolveType.get, analytics: analytics);
158154
var name = entrypoint.root.name;
159155
_describeActive(name, cache);
160156

lib/src/package_config.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:convert';
6-
75
import 'package:pub_semver/pub_semver.dart';
86

97
import 'language_version.dart';
@@ -162,6 +160,8 @@ class PackageConfigEntry {
162160
/// Given as `<major>.<minor>` version, similar to the `// @dart = X.Y`
163161
/// comment. This is derived from the lower-bound on the Dart SDK requirement
164162
/// in the `pubspec.yaml` for the given package.
163+
///
164+
/// `null` if not given.
165165
LanguageVersion? languageVersion;
166166

167167
/// Additional properties not in the specification for the
@@ -173,8 +173,10 @@ class PackageConfigEntry {
173173
required this.rootUri,
174174
this.packageUri,
175175
this.languageVersion,
176-
this.additionalProperties = const {},
177-
});
176+
this.additionalProperties,
177+
}) {
178+
additionalProperties ??= {};
179+
}
178180

179181
/// Create [PackageConfigEntry] from JSON [data].
180182
///
@@ -247,13 +249,7 @@ class PackageConfigEntry {
247249
Map<String, Object?> toJson() => {
248250
'name': name,
249251
'rootUri': rootUri.toString(),
250-
if (packageUri != null) 'packageUri': packageUri.toString(),
252+
if (packageUri != null) 'packageUri': packageUri?.toString(),
251253
if (languageVersion != null) 'languageVersion': '$languageVersion',
252254
}..addAll(additionalProperties ?? {});
253-
254-
@override
255-
String toString() {
256-
// TODO: implement toString
257-
return JsonEncoder.withIndent(' ').convert(toJson());
258-
}
259255
}

test/add/common/add_test.dart

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ void main() {
4646
await pubAdd(args: ['foo:1.2.3']);
4747

4848
await d.cacheDir({'foo': '1.2.3'}).validate();
49-
await d.appPackageConfigFile([
50-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
51-
]).validate();
49+
await d.appPackagesFile({'foo': '1.2.3'}).validate();
5250
await d.appDir({'foo': '1.2.3'}).validate();
5351
});
5452

@@ -64,11 +62,8 @@ void main() {
6462

6563
await d.cacheDir(
6664
{'foo': '1.2.3', 'bar': '1.1.0', 'baz': '2.5.3'}).validate();
67-
await d.appPackageConfigFile([
68-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
69-
d.packageConfigEntry(name: 'bar', version: '1.1.0'),
70-
d.packageConfigEntry(name: 'baz', version: '2.5.3'),
71-
]).validate();
65+
await d.appPackagesFile(
66+
{'foo': '1.2.3', 'bar': '1.1.0', 'baz': '2.5.3'}).validate();
7267
await d
7368
.appDir({'foo': '1.2.3', 'bar': '1.1.0', 'baz': '2.5.3'}).validate();
7469
});
@@ -95,9 +90,7 @@ void main() {
9590
await pubAdd(args: ['foo:1.2.3']);
9691

9792
await d.cacheDir({'foo': '1.2.3'}).validate();
98-
await d.appPackageConfigFile([
99-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
100-
]).validate();
93+
await d.appPackagesFile({'foo': '1.2.3'}).validate();
10194

10295
await d.dir(appPath, [
10396
d.pubspec({
@@ -143,9 +136,7 @@ void main() {
143136
await pubAdd(args: ['foo:1.2.3']);
144137

145138
await d.cacheDir({'foo': '1.2.3'}).validate();
146-
await d.appPackageConfigFile([
147-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
148-
]).validate();
139+
await d.appPackagesFile({'foo': '1.2.3'}).validate();
149140
await d.appDir({'foo': '1.2.3'}).validate();
150141
});
151142

@@ -226,9 +217,7 @@ environment:
226217
'adding it to dependencies instead.'));
227218

228219
await d.cacheDir({'foo': '1.2.3'}).validate();
229-
await d.appPackageConfigFile([
230-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
231-
]).validate();
220+
await d.appPackagesFile({'foo': '1.2.3'}).validate();
232221

233222
await d.dir(appPath, [
234223
d.pubspec({
@@ -255,9 +244,7 @@ environment:
255244
await pubAdd(args: ['foo']);
256245

257246
await d.cacheDir({'foo': '1.2.2'}).validate();
258-
await d.appPackageConfigFile([
259-
d.packageConfigEntry(name: 'foo', version: '1.2.2'),
260-
]).validate();
247+
await d.appPackagesFile({'foo': '1.2.2'}).validate();
261248
await d.dir(appPath, [
262249
d.pubspec({
263250
'name': 'myapp',
@@ -469,9 +456,7 @@ environment:
469456

470457
await pubAdd(args: ['--dev', 'foo:1.2.3']);
471458

472-
await d.appPackageConfigFile([
473-
d.packageConfigEntry(name: 'foo', version: '1.2.3'),
474-
]).validate();
459+
await d.appPackagesFile({'foo': '1.2.3'}).validate();
475460

476461
await d.dir(appPath, [
477462
d.pubspec({
@@ -581,9 +566,7 @@ environment:
581566
await pubAdd(args: ['foo', '--dev']);
582567

583568
await d.cacheDir({'foo': '1.2.2'}).validate();
584-
await d.appPackageConfigFile([
585-
d.packageConfigEntry(name: 'foo', version: '1.2.2'),
586-
]).validate();
569+
await d.appPackagesFile({'foo': '1.2.2'}).validate();
587570
await d.dir(appPath, [
588571
d.pubspec({
589572
'name': 'myapp',

0 commit comments

Comments
 (0)