Skip to content

Commit d8f4c54

Browse files
authored
Remove all support for legacy .packages file (#3507)
1 parent 1722b6a commit d8f4c54

22 files changed

+166
-1139
lines changed

lib/src/command/add.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class AddCommand extends PubCommand {
9494
help: 'Build executables in immediate dependencies.');
9595
argParser.addOption('directory',
9696
abbr: 'C', help: 'Run this in the directory <dir>.', valueHelp: 'dir');
97-
argParser.addFlag('legacy-packages-file',
98-
help: 'Generate the legacy ".packages" file', negatable: false);
9997
}
10098

10199
@override
@@ -164,11 +162,12 @@ class AddCommand extends PubCommand {
164162

165163
await Entrypoint.inMemory(newRoot, cache,
166164
solveResult: solveResult, lockFile: entrypoint.lockFile)
167-
.acquireDependencies(SolveType.get,
168-
dryRun: true,
169-
precompile: argResults['precompile'],
170-
analytics: analytics,
171-
generateDotPackages: false);
165+
.acquireDependencies(
166+
SolveType.get,
167+
dryRun: true,
168+
precompile: argResults['precompile'],
169+
analytics: analytics,
170+
);
172171
} else {
173172
/// Update the `pubspec.yaml` before calling [acquireDependencies] to
174173
/// ensure that the modification timestamp on `pubspec.lock` and
@@ -183,7 +182,6 @@ class AddCommand extends PubCommand {
183182
SolveType.get,
184183
precompile: argResults['precompile'],
185184
analytics: analytics,
186-
generateDotPackages: argResults['legacy-packages-file'],
187185
);
188186

189187
if (argResults['example'] && entrypoint.example != null) {
@@ -192,7 +190,6 @@ class AddCommand extends PubCommand {
192190
precompile: argResults['precompile'],
193191
onlyReportSuccessOrFailure: true,
194192
analytics: analytics,
195-
generateDotPackages: argResults['legacy-packages-file'],
196193
);
197194
}
198195
}

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: 0 additions & 5 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,7 +53,6 @@ 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

@@ -66,7 +62,6 @@ class GetCommand extends PubCommand {
6662
SolveType.get,
6763
dryRun: argResults['dry-run'],
6864
precompile: argResults['precompile'],
69-
generateDotPackages: argResults['legacy-packages-file'],
7065
analytics: analytics,
7166
onlyReportSuccessOrFailure: true,
7267
);

lib/src/command/remove.dart

Lines changed: 6 additions & 10 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
@@ -69,11 +66,12 @@ class RemoveCommand extends PubCommand {
6966
final newRoot = Package.inMemory(newPubspec);
7067

7168
await Entrypoint.inMemory(newRoot, cache, lockFile: entrypoint.lockFile)
72-
.acquireDependencies(SolveType.get,
73-
precompile: argResults['precompile'],
74-
dryRun: true,
75-
analytics: null,
76-
generateDotPackages: false);
69+
.acquireDependencies(
70+
SolveType.get,
71+
precompile: argResults['precompile'],
72+
dryRun: true,
73+
analytics: null,
74+
);
7775
} else {
7876
/// Update the pubspec.
7977
_writeRemovalToPubspec(packages);
@@ -85,7 +83,6 @@ class RemoveCommand extends PubCommand {
8583
SolveType.get,
8684
precompile: argResults['precompile'],
8785
analytics: analytics,
88-
generateDotPackages: argResults['legacy-packages-file'],
8986
);
9087

9188
var example = entrypoint.example;
@@ -95,7 +92,6 @@ class RemoveCommand extends PubCommand {
9592
precompile: argResults['precompile'],
9693
onlyReportSuccessOrFailure: true,
9794
analytics: analytics,
98-
generateDotPackages: argResults['legacy-packages-file'],
9995
);
10096
}
10197
}

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();
@@ -243,7 +237,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
243237
dryRun: true,
244238
precompile: _precompile,
245239
analytics: null, // No analytics for dry-run
246-
generateDotPackages: false,
247240
);
248241
} else {
249242
if (changes.isNotEmpty) {
@@ -256,7 +249,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
256249
SolveType.get,
257250
precompile: _precompile,
258251
analytics: analytics,
259-
generateDotPackages: argResults['legacy-packages-file'],
260252
);
261253
}
262254

@@ -341,7 +333,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
341333
dryRun: true,
342334
precompile: _precompile,
343335
analytics: null,
344-
generateDotPackages: false,
345336
);
346337
} else {
347338
if (changes.isNotEmpty) {
@@ -354,7 +345,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
354345
SolveType.upgrade,
355346
precompile: _precompile,
356347
analytics: analytics,
357-
generateDotPackages: argResults['legacy-packages-file'],
358348
);
359349
}
360350

lib/src/entrypoint.dart

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import 'package_config.dart';
2727
import 'package_config.dart' show PackageConfig;
2828
import 'package_graph.dart';
2929
import 'package_name.dart';
30-
import 'packages_file.dart' as packages_file;
3130
import 'pub_embeddable_command.dart';
3231
import 'pubspec.dart';
3332
import 'sdk.dart';
@@ -225,25 +224,18 @@ class Entrypoint {
225224
Entrypoint? _example;
226225

227226
/// Writes .packages and .dart_tool/package_config.json
228-
Future<void> writePackagesFiles({bool generateDotPackages = false}) async {
227+
Future<void> writePackageConfigFile() async {
229228
final entrypointName = isGlobal ? null : root.name;
230-
if (generateDotPackages) {
231-
writeTextFile(
232-
packagesFile,
233-
lockFile.packagesFile(cache,
234-
entrypoint: entrypointName,
235-
relativeFrom: isGlobal ? null : root.dir));
236-
} else {
237-
tryDeleteEntry(packagesFile);
238-
}
239229
ensureDir(p.dirname(packageConfigFile));
240230
writeTextFile(
241-
packageConfigFile,
242-
await lockFile.packageConfigFile(cache,
243-
entrypoint: entrypointName,
244-
entrypointSdkConstraint:
245-
root.pubspec.sdkConstraints[sdk.identifier],
246-
relativeFrom: isGlobal ? null : root.dir));
231+
packageConfigFile,
232+
await lockFile.packageConfigFile(
233+
cache,
234+
entrypoint: entrypointName,
235+
entrypointSdkConstraint: root.pubspec.sdkConstraints[sdk.identifier],
236+
relativeFrom: isGlobal ? null : root.dir,
237+
),
238+
);
247239
}
248240

249241
/// Gets all dependencies of the [root] package.
@@ -273,7 +265,6 @@ class Entrypoint {
273265
Iterable<String>? unlock,
274266
bool dryRun = false,
275267
bool precompile = false,
276-
required bool generateDotPackages,
277268
required PubAnalytics? analytics,
278269
bool onlyReportSuccessOrFailure = false,
279270
}) async {
@@ -347,7 +338,7 @@ class Entrypoint {
347338
/// have to reload and reparse all the pubspecs.
348339
_packageGraph = PackageGraph.fromSolveResult(this, result);
349340

350-
await writePackagesFiles(generateDotPackages: generateDotPackages);
341+
await writePackageConfigFile();
351342

352343
try {
353344
if (precompile) {
@@ -568,16 +559,6 @@ class Entrypoint {
568559
}
569560
}
570561

571-
if (fileExists(packagesFile)) {
572-
var packagesModified = File(packagesFile).lastModifiedSync();
573-
if (packagesModified.isBefore(lockFileModified)) {
574-
_checkPackagesFileUpToDate();
575-
touch(packagesFile);
576-
} else if (touchedLockFile) {
577-
touch(packagesFile);
578-
}
579-
}
580-
581562
var packageConfigModified = File(packageConfigFile).lastModifiedSync();
582563
if (packageConfigModified.isBefore(lockFileModified) ||
583564
hasPathDependencies) {
@@ -731,39 +712,6 @@ class Entrypoint {
731712
});
732713
}
733714

734-
/// Checks whether or not the `.packages` file is out of date with respect
735-
/// to the [lockfile].
736-
///
737-
/// This will throw a [DataError] if [lockfile] contains dependencies that
738-
/// are not in the `.packages` or that don't match what's in there.
739-
void _checkPackagesFileUpToDate() {
740-
void outOfDate() {
741-
dataError('The $lockFilePath file has changed since the .packages file '
742-
'was generated, please run "$topLevelProgram pub get" again.');
743-
}
744-
745-
var packages = packages_file.parse(
746-
File(packagesFile).readAsBytesSync(), p.toUri(packagesFile));
747-
748-
final packagePathsMapping = <String, String>{};
749-
for (final package in packages.keys) {
750-
final packageUri = packages[package]!;
751-
752-
// Pub only generates "file:" and relative URIs.
753-
if (packageUri.scheme != 'file' && packageUri.scheme.isNotEmpty) {
754-
outOfDate();
755-
}
756-
757-
// Get the dirname of the .packages path, since it's pointing to lib/.
758-
final packagePath = p.dirname(p.join(root.dir, p.fromUri(packageUri)));
759-
packagePathsMapping[package] = packagePath;
760-
}
761-
762-
if (!_isPackagePathsMappingUpToDateWithLockfile(packagePathsMapping)) {
763-
outOfDate();
764-
}
765-
}
766-
767715
/// Checks whether or not the `.dart_tool/package_config.json` file is
768716
/// out of date with respect to the lockfile.
769717
///

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ class GlobalPackages {
162162
await entrypoint.acquireDependencies(
163163
SolveType.get,
164164
analytics: analytics,
165-
generateDotPackages: false,
166165
);
167166
var name = entrypoint.root.name;
168167
_describeActive(name, cache);
@@ -253,7 +252,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam
253252
solveResult: result,
254253
);
255254

256-
await entrypoint.writePackagesFiles();
255+
await entrypoint.writePackageConfigFile();
257256

258257
await entrypoint.precompileExecutables();
259258

lib/src/lock_file.dart

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'io.dart';
1414
import 'language_version.dart';
1515
import 'package_config.dart';
1616
import 'package_name.dart';
17-
import 'packages_file.dart' as packages_file;
1817
import 'sdk.dart' show sdk;
1918
import 'system_cache.dart';
2019
import 'utils.dart';
@@ -214,41 +213,6 @@ class LockFile {
214213
_devDependencies, _overriddenDependencies);
215214
}
216215

217-
/// Returns the contents of the `.packages` file generated from this lockfile.
218-
///
219-
/// If [entrypoint] is passed, a relative entry is added for its "lib/"
220-
/// directory.
221-
String packagesFile(
222-
SystemCache cache, {
223-
String? entrypoint,
224-
String? relativeFrom,
225-
}) {
226-
var header = '''
227-
This file is deprecated. Tools should instead consume
228-
`.dart_tool/package_config.json`.
229-
230-
For more info see: https://dart.dev/go/dot-packages-deprecation
231-
232-
Generated by pub on ${DateTime.now()}.''';
233-
234-
var map = Map<String, Uri>.fromIterable(ordered<String>(packages.keys),
235-
value: (name) {
236-
var id = packages[name]!;
237-
return p.toUri(
238-
p.join(
239-
cache.getDirectory(id, relativeFrom: relativeFrom),
240-
'lib',
241-
),
242-
);
243-
});
244-
245-
if (entrypoint != null) map[entrypoint] = Uri.parse('lib/');
246-
247-
var text = StringBuffer();
248-
packages_file.write(text, map, comment: header);
249-
return text.toString();
250-
}
251-
252216
/// Returns the contents of the `.dart_tool/package_config` file generated
253217
/// from this lockfile.
254218
///

0 commit comments

Comments
 (0)