Skip to content
Merged
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
3 changes: 3 additions & 0 deletions apps/cli/lib/src/compiler/api/local_api_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class LocalApiRunner {
VmService? _vmService;
late final String _vmIsolateId;

/// The WebSocket URI of the running Celest server.
String get wsUri => _vmService!.wsUri!;

late final StreamSubscription<String> _stdoutSub;
late final StreamSubscription<String> _stderrSub;

Expand Down
11 changes: 10 additions & 1 deletion apps/cli/lib/src/frontend/celest_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ final class CelestFrontend {
'Celest is running and watching for updates',
);
cliLogger.detail('Local API running at: $localUri');
if (verbose) {
cliLogger.detail(
'VM Service URI: ${_localApiRunner!.wsUri}',
);
}
} else {
currentProgress!.complete('Reloaded project');
}
Expand All @@ -358,7 +363,11 @@ final class CelestFrontend {
if (childProcess case final childProcess?
when !childProcess.isStarted) {
logger.info('Running command: ${childProcess.command.join(' ')}');
await childProcess.start();
await childProcess.start(
dartDefines: {
'CELEST_SERVICE_WS_URI': _localApiRunner!.wsUri,
},
);
unawaited(
_stopSignal.future.then(childProcess.stop),
);
Expand Down
27 changes: 27 additions & 0 deletions apps/cli/lib/src/frontend/child_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,39 @@ final class ChildProcess {
}

/// Starts the process and streams stdout/stderr to the console.
///
/// If [environment] is not null, it is passed to [Process.start].
///
/// If [dartDefines] are specified and the [command] is a `dart` or `flutter`
/// command, then the given values are passed to the command via the respective
/// flag.
Future<void> start({
Map<String, String>? environment,
Map<String, String>? dartDefines,
}) async {
if (_process != null) {
return;
}

var command = this.command;
if (dartDefines != null) {
switch (command.first) {
case 'dart':
command = [
'dart',
for (final MapEntry(:key, :value) in dartDefines.entries)
'-D$key=$value',
...command.sublist(1),
];
case 'flutter':
command = [
...command,
for (final MapEntry(:key, :value) in dartDefines.entries)
'--dart-define=$key=$value'
];
}
}

final process = _process = await processManager.start(
command,
environment: environment,
Expand Down