Skip to content

Commit 079a52e

Browse files
Anna Gringauzeelliette
Anna Gringauze
andauthored
Migrate .packages to package_config (#1543)
* Migrate .packages * Update dependency override and changelog * Update changelog * Update expression compiler * Merge in master * Update changelog * Test changes * All test changes * Update frontend server test infrastructure to handle package_config.json * Remove verbose printing from tests * Fix webdev integration tests * Removed hiding directory Co-authored-by: Elliott Brooks <[email protected]>
1 parent bbf640b commit 079a52e

11 files changed

+123
-197
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
restart.
1313
- Remove verbose printing on receiving DevTools events.
1414
- Update `vm_service` version to `^8.2.0`.
15+
- Migrate .packages to package_config.json.
1516
- Update error message on expression evaluation using unloaded libraries.
1617

1718
**Breaking changes:**

dwds/lib/src/readers/frontend_server_asset_reader.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ class FrontendServerAssetReader implements AssetReader {
3737
/// Corresponding `.json` and `.map` files will be read relative to
3838
/// [outputPath].
3939
///
40-
/// [_packageRoot] is the path to the directory that contains a `.packages`
41-
/// file for the application.
40+
/// [_packageRoot] is the path to the directory that contains a
41+
/// `.dart_tool/package_config.json` file for the application.
4242
FrontendServerAssetReader(
4343
String outputPath,
4444
this._packageRoot,
4545
) : _mapOriginal = File('$outputPath.map'),
4646
_mapIncremental = File('$outputPath.incremental.map'),
4747
_jsonOriginal = File('$outputPath.json'),
4848
_jsonIncremental = File('$outputPath.incremental.json'),
49-
_packageConfig = loadPackageConfig(
50-
File(p.absolute(p.join(_packageRoot, '.packages'))));
49+
_packageConfig = loadPackageConfig(File(p
50+
.absolute(p.join(_packageRoot, '.dart_tool/package_config.json'))));
5151

5252
@override
5353
Future<String> dartSourceContents(String serverPath) async {

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class DartUri {
157157
/// Record library and script uris to enable resolving library and script paths.
158158
static Future<void> initialize(SdkConfiguration sdkConfiguration) async {
159159
_sdkConfiguration = sdkConfiguration;
160-
var packagesUri = p.toUri(p.join(currentDirectory, '.packages'));
160+
var packagesUri =
161+
p.toUri(p.join(currentDirectory, '.dart_tool/package_config.json'));
161162

162163
clear();
163164

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

193-
/// Load the .packages file associated with the running application so we can
194-
/// resolve file URLs into package: URLs appropriately.
194+
/// Load the .dart_tool/package_config.json file associated with the running
195+
/// application so we can resolve file URLs into package: URLs appropriately.
195196
static Future<void> _loadPackageConfig(Uri uri) async {
196197
_packageConfig = await loadPackageConfigUri(uri, onError: (e) {
197198
_logger.warning('Cannot read packages spec: $uri', e);

dwds/test/fixtures/context.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ class TestContext {
9898
.absolute(directory ?? p.relative(relativeDirectory, from: p.current)));
9999

100100
DartUri.currentDirectory = workingDirectory;
101-
_packagesFilePath = p.join(workingDirectory, '.packages');
101+
_packagesFilePath =
102+
p.join(workingDirectory, '.dart_tool/package_config.json');
102103

103-
_entryFile = File(p.normalize(
104-
p.absolute(entry ?? p.relative(relativeEntry, from: p.current))));
104+
var entryFilePath = p.normalize(
105+
p.absolute(entry ?? p.relative(relativeEntry, from: p.current)));
105106

107+
_logger.info('Serving: $pathToServe/$path');
108+
_logger.info('Packages: $_packagesFilePath');
109+
_logger.info('Entry: $entryFilePath');
110+
111+
_entryFile = File(entryFilePath);
106112
_entryContents = _entryFile.readAsStringSync();
107113
}
108114

@@ -241,15 +247,14 @@ class TestContext {
241247
case CompilationMode.frontendServer:
242248
{
243249
soundNullSafety ??= true;
244-
var fileSystemRoot = p.dirname(_packagesFilePath);
250+
var projectDirectory = p.dirname(p.dirname(_packagesFilePath));
245251
var entryPath =
246-
_entryFile.path.substring(fileSystemRoot.length + 1);
252+
_entryFile.path.substring(projectDirectory.length + 1);
247253
webRunner = ResidentWebRunner(
248254
'${Uri.file(entryPath)}',
249255
urlEncoder,
250-
fileSystemRoot,
251256
_packagesFilePath,
252-
[fileSystemRoot],
257+
[projectDirectory],
253258
'org-dartlang-app',
254259
_outputDir.path,
255260
verboseCompiler);

dwds/test/frontend_server_breakpoint_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:vm_service/vm_service.dart';
1515
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1616

1717
import 'fixtures/context.dart';
18+
import 'fixtures/logging.dart';
1819

1920
final context = TestContext(
2021
directory: p.join('..', 'fixtures', '_testPackage'),
@@ -27,10 +28,22 @@ ChromeProxyService get service =>
2728
WipConnection get tabConnection => context.tabConnection;
2829

2930
void main() {
31+
// Enable verbose logging for debugging.
32+
var debug = false;
33+
34+
// Change to 'true' to print expression compiler messages to console.
35+
//
36+
// Note: expression compiler runs in an isolate, so its output is not
37+
// currently redirected to a logger. As a result, it will be printed
38+
// regardless of the logger settings.
39+
var verboseCompiler = false;
40+
3041
group('shared context', () {
3142
setUpAll(() async {
43+
setCurrentLogWriter(debug: debug);
3244
await context.setUp(
3345
compilationMode: CompilationMode.frontendServer,
46+
verboseCompiler: verboseCompiler,
3447
);
3548
});
3649

@@ -46,6 +59,7 @@ void main() {
4659
Stream<Event> stream;
4760

4861
setUp(() async {
62+
setCurrentLogWriter(debug: debug);
4963
vm = await service.getVM();
5064
isolate = await service.getIsolate(vm.isolates.first.id);
5165
scripts = await service.getScripts(isolate.id);

frontend_server_common/lib/src/asset_server.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestAssetServer implements AssetReader {
2727
TestAssetServer(
2828
this._root,
2929
this._httpServer,
30-
this._packages,
30+
this._packageConfig,
3131
this.internetAddress,
3232
this._fileSystem,
3333
);
@@ -47,14 +47,12 @@ class TestAssetServer implements AssetReader {
4747
String hostname,
4848
int port,
4949
UrlEncoder urlTunneller,
50+
PackageConfig packageConfig,
5051
) async {
5152
var address = (await InternetAddress.lookup(hostname)).first;
5253
var httpServer = await HttpServer.bind(address, port);
53-
var packages = await loadPackageConfigUri(Uri.base.resolve('.packages'),
54-
loader: (Uri uri) => fileSystem.file(uri).readAsBytes());
5554
var server =
56-
TestAssetServer(root, httpServer, packages, address, fileSystem);
57-
55+
TestAssetServer(root, httpServer, packageConfig, address, fileSystem);
5856
return server;
5957
}
6058

@@ -64,8 +62,7 @@ class TestAssetServer implements AssetReader {
6462
final Map<String, Uint8List> _sourcemaps = <String, Uint8List>{};
6563
final Map<String, Uint8List> _metadata = <String, Uint8List>{};
6664
String _mergedMetadata;
67-
// ignore: deprecated_member_use
68-
final PackageConfig _packages;
65+
final PackageConfig _packageConfig;
6966
final InternetAddress internetAddress;
7067

7168
Uint8List getFile(String path) => _files[path];
@@ -241,7 +238,7 @@ class TestAssetServer implements AssetReader {
241238
// The file might have been a package file which is signaled by a
242239
// `/packages/<package>/<path>` request.
243240
if (segments.first == 'packages') {
244-
var packageFile = _fileSystem.file(_packages
241+
var packageFile = _fileSystem.file(_packageConfig
245242
.resolve(Uri(scheme: 'package', pathSegments: segments.skip(1))));
246243
if (packageFile.existsSync()) {
247244
return packageFile;

frontend_server_common/lib/src/devfs.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:dwds/dwds.dart';
1212
import 'package:file/file.dart';
1313
import 'package:logging/logging.dart';
1414
import 'package:meta/meta.dart';
15+
import 'package:package_config/package_config.dart';
1516
import 'package:path/path.dart' as p;
1617

1718
import 'asset.dart';
@@ -30,8 +31,7 @@ class WebDevFS {
3031
this.fileSystem,
3132
this.hostname,
3233
this.port,
33-
this.packagesFilePath,
34-
this.packagesPath,
34+
this.packageConfigPath,
3535
this.root,
3636
this.urlTunneller,
3737
});
@@ -40,24 +40,31 @@ class WebDevFS {
4040
TestAssetServer assetServer;
4141
final String hostname;
4242
final int port;
43-
final String packagesFilePath;
44-
final String packagesPath;
43+
final String packageConfigPath;
4544
final String root;
4645
final UrlEncoder urlTunneller;
4746
Directory _savedCurrentDirectory;
4847
List<Uri> sources;
48+
PackageConfig _packageConfig;
4949

5050
Future<Uri> create() async {
5151
_savedCurrentDirectory = fileSystem.currentDirectory;
52-
fileSystem.currentDirectory = packagesPath;
52+
// package_config.json is located in <project directory>/.dart_tool/package_config
53+
var projectDirectory = p.dirname(p.dirname(packageConfigPath));
54+
55+
fileSystem.currentDirectory = projectDirectory;
56+
57+
_packageConfig = await loadPackageConfigUri(Uri.file(packageConfigPath),
58+
loader: (Uri uri) => fileSystem.file(uri).readAsBytes());
59+
5360
assetServer = await TestAssetServer.start(
54-
fileSystem, root, hostname, port, urlTunneller);
61+
fileSystem, root, hostname, port, urlTunneller, _packageConfig);
5562
return Uri.parse('http://$hostname:$port');
5663
}
5764

5865
Future<void> dispose() {
5966
fileSystem.currentDirectory = _savedCurrentDirectory;
60-
return assetServer.close();
67+
return assetServer?.close();
6168
}
6269

6370
Future<UpdateFSReport> update({
@@ -102,11 +109,9 @@ class WebDevFS {
102109
generator.reset();
103110

104111
var compilerOutput = await generator.recompile(
105-
'org-dartlang-app:///$mainPath',
106-
invalidatedFiles,
107-
outputPath: p.join(dillOutputPath, 'app.dill'),
108-
packagesFilePath: packagesFilePath,
109-
);
112+
Uri.parse('org-dartlang-app:///$mainPath'), invalidatedFiles,
113+
outputPath: p.join(dillOutputPath, 'app.dill'),
114+
packageConfig: _packageConfig);
110115
if (compilerOutput == null || compilerOutput.errorCount > 0) {
111116
return UpdateFSReport(success: false);
112117
}

0 commit comments

Comments
 (0)