Skip to content

Migrate .packages to package_config #1537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
restart.
- Remove verbose printing on receiving DevTools events.
- Update `vm_service` version to `^8.2.0`.

- Migrate .packages to package_config.json.

**Breaking changes:**
- `Dwds.start` and `ExpressionCompilerService` now take
Expand Down
8 changes: 4 additions & 4 deletions dwds/lib/src/readers/frontend_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ class FrontendServerAssetReader implements AssetReader {
/// Corresponding `.json` and `.map` files will be read relative to
/// [outputPath].
///
/// [_packageRoot] is the path to the directory that contains a `.packages`
/// file for the application.
/// [_packageRoot] is the path to the directory that contains a
/// `.dart_tool/package_config.json` file for the application.
FrontendServerAssetReader(
String outputPath,
this._packageRoot,
) : _mapOriginal = File('$outputPath.map'),
_mapIncremental = File('$outputPath.incremental.map'),
_jsonOriginal = File('$outputPath.json'),
_jsonIncremental = File('$outputPath.incremental.json'),
_packageConfig = loadPackageConfig(
File(p.absolute(p.join(_packageRoot, '.packages'))));
_packageConfig = loadPackageConfig(File(p
.absolute(p.join(_packageRoot, '.dart_tool/package_config.json'))));

@override
Future<String> dartSourceContents(String serverPath) async {
Expand Down
7 changes: 4 additions & 3 deletions dwds/lib/src/utilities/dart_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class DartUri {
/// Record library and script uris to enable resolving library and script paths.
static Future<void> initialize(SdkConfiguration sdkConfiguration) async {
_sdkConfiguration = sdkConfiguration;
var packagesUri = p.toUri(p.join(currentDirectory, '.packages'));
var packagesUri =
p.toUri(p.join(currentDirectory, '.dart_tool/package_config.json'));

clear();

Expand Down Expand Up @@ -190,8 +191,8 @@ class DartUri {
/// Returns the dirname for the server URI.
static String _dirForServerUri(String uri) => p.dirname(Uri.parse(uri).path);

/// Load the .packages file associated with the running application so we can
/// resolve file URLs into package: URLs appropriately.
/// Load the .dart_tool/package_config.json file associated with the running
/// application so we can resolve file URLs into package: URLs appropriately.
static Future<void> _loadPackageConfig(Uri uri) async {
_packageConfig = await loadPackageConfigUri(uri, onError: (e) {
_logger.warning('Cannot read packages spec: $uri', e);
Expand Down
3 changes: 2 additions & 1 deletion dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class TestContext {
.absolute(directory ?? p.relative(relativeDirectory, from: p.current)));

DartUri.currentDirectory = workingDirectory;
_packagesFilePath = p.join(workingDirectory, '.packages');
_packagesFilePath =
p.join(workingDirectory, '.dart_tool/package_config.json');

_entryFile = File(p.normalize(
p.absolute(entry ?? p.relative(relativeEntry, from: p.current))));
Expand Down
9 changes: 7 additions & 2 deletions frontend_server_common/lib/src/asset_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:dwds/dwds.dart';
import 'package:file/file.dart';
import 'package:file/file.dart' hide Directory;
import 'package:logging/logging.dart';
import 'package:mime/mime.dart' as mime;
import 'package:package_config/package_config.dart'; // ignore: deprecated_member_use
Expand Down Expand Up @@ -50,8 +50,13 @@ class TestAssetServer implements AssetReader {
) async {
var address = (await InternetAddress.lookup(hostname)).first;
var httpServer = await HttpServer.bind(address, port);
var packages = await loadPackageConfigUri(Uri.base.resolve('.packages'),
print('ROOT IS $root');
print('URI IS ${Uri.base}');
// var packages = await findPackageConfig(Directory.fromUri(Uri.base));
var packages = await loadPackageConfigUri(
Uri.base.resolve('package_config.json'),
loader: (Uri uri) => fileSystem.file(uri).readAsBytes());
print('======== PACKAGE VERSION IS ${packages.version}');
var server =
TestAssetServer(root, httpServer, packages, address, fileSystem);

Expand Down
2 changes: 1 addition & 1 deletion frontend_server_common/lib/src/devfs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class WebDevFS {

Future<void> dispose() {
fileSystem.currentDirectory = _savedCurrentDirectory;
return assetServer.close();
// return assetServer.close();
}

Future<UpdateFSReport> update({
Expand Down
4 changes: 3 additions & 1 deletion webdev/test/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ void main() {

await process.shouldExit(0);

await d.file('.packages', isNotEmpty).validate(exampleDirectory);
await d
.file('.dart_tool/package_config.json', isNotEmpty)
.validate(exampleDirectory);
await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory);
});

Expand Down
12 changes: 6 additions & 6 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ name: sample
))
.create();

await d.file('.packages', '''
await d.file('.dart_tool/package_config.json', '''
''').create();
await d.dir('.dart_tool', [d.file('package_config.json', '')]).create();

Expand Down Expand Up @@ -84,7 +84,7 @@ name: sample
.file('pubspec.lock', _pubspecLock(runnerVersion: null))
.create();

await d.file('.packages', '''
await d.file('.dart_tool/package_config.json', '''
''').create();
await d
.dir('.dart_tool', [d.file('package_config.json', '')]).create();
Expand All @@ -107,7 +107,7 @@ name: sample
.file('pubspec.lock', _pubspecLock(webCompilersVersion: null))
.create();

await d.file('.packages', '''
await d.file('.dart_tool/package_config.json', '''
''').create();
await d
.dir('.dart_tool', [d.file('package_config.json', '')]).create();
Expand All @@ -132,7 +132,7 @@ name: sample
.file('pubspec.lock', _pubspecLock(webCompilersVersion: null))
.create();

await d.file('.packages', '''
await d.file('.dart_tool/package_config.json', '''
''').create();
await d
.dir('.dart_tool', [d.file('package_config.json', '')]).create();
Expand Down Expand Up @@ -184,7 +184,7 @@ name: sample
daemonVersion: buildDaemonVersion))
.create();

await d.file('.packages', '''
await d.file('.dart_tool/package_config.json', '''
''').create();
await d.dir(
'.dart_tool', [d.file('package_config.json', '')]).create();
Expand Down Expand Up @@ -240,7 +240,7 @@ name: sample
test('should fail if there has been a dependency change', () async {
await d.file('pubspec.lock', _pubspecLock()).create();

await d.file('.packages', '').create();
await d.file('.dart_tool/package_config.json', '').create();
await d.dir('.dart_tool', [d.file('package_config.json', '')]).create();

// Ensure there is a noticeable delta in the creation times
Expand Down