Skip to content

Commit 6a26cd9

Browse files
committed
keep package in sync with migrated version in the sdk
1 parent 56642b7 commit 6a26cd9

12 files changed

+130
-42
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:analysis_config/analysis_options.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml

frontend_server_client/example/app/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Future<void> main() async {
88
print(message);
99
while (!message.contains('goodbye')) {
1010
print('waiting for hot reload to change message');
11-
await Future.delayed(const Duration(seconds: 1));
11+
await Future<void>.delayed(const Duration(seconds: 1));
1212
}
1313
print(message);
1414
}

frontend_server_client/example/vm_client.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ import 'package:vm_service/vm_service.dart';
1212
import 'package:vm_service/vm_service_io.dart';
1313

1414
void main(List<String> args) async {
15+
// Change to package root so relative paths work in CI
16+
final scriptDir = p.dirname(p.fromUri(Platform.script));
17+
final packageRoot = p.dirname(scriptDir);
18+
Directory.current = packageRoot;
19+
1520
try {
1621
watch.start();
1722
if (args.isNotEmpty) {
1823
throw ArgumentError('No command line args are supported');
1924
}
2025

26+
final packagesPath = findNearestPackageConfigPath();
2127
final client = await FrontendServerClient.start(
2228
'org-dartlang-root:///$app',
2329
outputDill,
2430
p.join(sdkDir, 'lib', '_internal', 'vm_platform_strong.dill'),
31+
packagesJson: packagesPath ?? '.dart_tool/package_config.json',
2532
target: 'vm',
26-
fileSystemRoots: [p.url.current],
33+
// Use an absolute filesystem root so org-dartlang-root:/// URIs resolve reliably in CI
34+
fileSystemRoots: [Directory.current.path],
2735
fileSystemScheme: 'org-dartlang-root',
2836
verbose: true,
2937
);
@@ -35,10 +43,10 @@ void main(List<String> args) async {
3543
Process appProcess;
3644
final vmServiceCompleter = Completer<VmService>();
3745
appProcess = await Process.start(Platform.resolvedExecutable, [
38-
'--enable-vm-service=0',
46+
'--enable-vm-service',
3947
result.dillOutput!,
4048
]);
41-
final sawHelloWorld = Completer();
49+
final sawHelloWorld = Completer<void>();
4250
appProcess.stdout
4351
.transform(utf8.decoder)
4452
.transform(const LineSplitter())
@@ -52,7 +60,9 @@ void main(List<String> args) async {
5260
)) {
5361
final observatoryUri =
5462
'${line.split(' ').last.replaceFirst('http', 'ws')}ws';
55-
vmServiceCompleter.complete(vmServiceConnectUri(observatoryUri));
63+
if (!vmServiceCompleter.isCompleted) {
64+
vmServiceCompleter.complete(vmServiceConnectUri(observatoryUri));
65+
}
5666
}
5767
});
5868
appProcess.stderr

frontend_server_client/example/web_client.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import 'package:shelf_packages_handler/shelf_packages_handler.dart';
1414
import 'package:shelf_static/shelf_static.dart';
1515

1616
void main(List<String> args) async {
17+
// Change to package root so relative paths work in CI
18+
final scriptDir = p.dirname(p.fromUri(Platform.script));
19+
final packageRoot = p.dirname(scriptDir);
20+
Directory.current = packageRoot;
21+
1722
try {
1823
watch.start();
1924
if (args.isNotEmpty) {
@@ -41,12 +46,15 @@ void main(List<String> args) async {
4146
}
4247

4348
_print('starting frontend server');
49+
final packagesPath = findNearestPackageConfigPath();
4450
final client = await DartDevcFrontendServerClient.start(
4551
'org-dartlang-root:///$app',
4652
outputDill,
47-
fileSystemRoots: [p.current],
53+
// Use an absolute filesystem root so org-dartlang-root:/// URIs resolve reliably in CI
54+
fileSystemRoots: [Directory.current.path],
4855
fileSystemScheme: 'org-dartlang-root',
4956
platformKernel: p.toUri(sdkKernelPath).toString(),
57+
packagesJson: packagesPath ?? '.dart_tool/package_config.json',
5058
verbose: true,
5159
);
5260

@@ -58,7 +66,7 @@ void main(List<String> args) async {
5866
_print('starting shelf server');
5967
final cascade = Cascade()
6068
.add(_clientHandler(client))
61-
.add(createStaticHandler(p.current))
69+
.add(createStaticHandler(Directory.current.path))
6270
.add(createFileHandler(dartSdkJs, url: 'example/app/dart_sdk.js'))
6371
.add(
6472
createFileHandler(

frontend_server_client/lib/frontend_server_client.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export 'src/dartdevc_frontend_server_client.dart'
66
show DartDevcFrontendServerClient;
77
export 'src/frontend_server_client.dart'
88
show CompileResult, FrontendServerClient;
9+
export 'src/package_config_utils.dart' show findNearestPackageConfigPath;

frontend_server_client/lib/src/dartdevc_bootstrap_amd.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ document.head.appendChild(requireEl);
4141
/// method.
4242
///
4343
/// RE: Object.keys usage in app.main:
44-
/// This attaches the main entrypoint and hot reload functionality to the window.
45-
/// The app module will have a single property which contains the actual application
46-
/// code. The property name is based off of the entrypoint that is generated, for example
47-
/// the file `foo/bar/baz.dart` will generate a property named approximately
48-
/// `foo__bar__baz`. Rather than attempt to guess, we assume the first property of
49-
/// this object is the module.
44+
/// This attaches the main entrypoint and hot reload functionality to the
45+
/// window. The app module will have a single property which contains the
46+
/// actual application code. The property name is based off of the entrypoint
47+
/// that is generated, for example the file `foo/bar/baz.dart` will generate
48+
/// a property named approximately `foo__bar__baz`. Rather than attempt to
49+
/// guess, we assume the first property of this object is the module.
5050
String generateAmdMainModule({required String entrypoint}) {
5151
return '''/* ENTRYPOINT_EXTENTION_MARKER */
5252
// Create the main module loaded below.

frontend_server_client/lib/src/frontend_server_client.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ class FrontendServerClient {
227227
removedSources.add(diffUri);
228228
} else {
229229
throw StateError(
230-
'unrecognized diff line, should start with a + or - but got: $line',
230+
'unrecognized diff line, should start with a + or - '
231+
'but got: $line',
231232
);
232233
}
233234
continue;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Utility functions to locate a package_config.json for pub/workspace setups.
2+
3+
import 'dart:io';
4+
5+
import 'package:package_config/package_config.dart';
6+
import 'package:path/path.dart' as p;
7+
8+
/// Walks up from [start] (or the current directory if omitted) to find the
9+
/// nearest `.dart_tool/package_config.json`.
10+
///
11+
/// Returns the absolute file path, or `null` if none is found.
12+
String? findNearestPackageConfigPath([Directory? start]) {
13+
var dir = (start ?? Directory.current).absolute;
14+
while (true) {
15+
final file = File(p.join(dir.path, '.dart_tool', 'package_config.json'));
16+
if (file.existsSync()) return file.path;
17+
final parent = dir.parent;
18+
if (parent.path == dir.path) return null;
19+
dir = parent;
20+
}
21+
}
22+
23+
/// Returns an absolute path under the given [packageName]'s root directory,
24+
/// resolving using the nearest workspace `.dart_tool/package_config.json`.
25+
///
26+
/// This is robust for pub workspace monorepos where the nearest package
27+
/// config lives at the repo root and contains individual entries for each
28+
/// package with its own root.
29+
Future<String> pathFromNearestPackageConfig(
30+
String relativePath, {
31+
String packageName = 'frontend_server_client',
32+
}) async {
33+
final configPath = findNearestPackageConfigPath();
34+
if (configPath == null) {
35+
throw StateError('Could not locate .dart_tool/package_config.json');
36+
}
37+
final config = await loadPackageConfigUri(Uri.file(configPath));
38+
final pkg = config.packages.firstWhere(
39+
(p0) => p0.name == packageName,
40+
orElse: () => throw StateError(
41+
'Package $packageName not found in package config at $configPath',
42+
),
43+
);
44+
final packageRootDir = p.fromUri(pkg.root);
45+
return p.normalize(p.join(packageRootDir, relativePath));
46+
}

frontend_server_client/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ environment:
99

1010
dependencies:
1111
async: ^2.5.0
12+
package_config: ^2.1.0
1213
path: ^1.8.0
1314

1415
dev_dependencies:
15-
analysis_config:
16-
path: ../_analysis_config
17-
package_config: ^2.0.0
16+
dart_flutter_team_lints: ^3.5.2
1817
shelf: ^1.0.0
1918
shelf_packages_handler: ^3.0.0
2019
shelf_static: ^1.1.0

frontend_server_client/test/example/vm_client_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ library;
88

99
import 'dart:io';
1010

11+
import 'package:frontend_server_client/src/package_config_utils.dart';
1112
import 'package:test/test.dart';
1213
import 'package:test_process/test_process.dart';
1314

1415
void main() {
1516
test('vm client example can build and rebuild an app', () async {
17+
// Resolve the example script path based on the package root.
18+
final exampleFilePath = await pathFromNearestPackageConfig(
19+
'example/vm_client.dart',
20+
);
1621
final process = await TestProcess.start(Platform.resolvedExecutable, [
1722
'run',
18-
'example/vm_client.dart',
23+
exampleFilePath,
1924
]);
2025
await expectLater(
2126
process.stdout,

0 commit comments

Comments
 (0)