diff --git a/apps/cli/lib/src/compiler/api/local_api_runner.dart b/apps/cli/lib/src/compiler/api/local_api_runner.dart index a9c2cb13b..e4a10ea7e 100644 --- a/apps/cli/lib/src/compiler/api/local_api_runner.dart +++ b/apps/cli/lib/src/compiler/api/local_api_runner.dart @@ -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 _stdoutSub; late final StreamSubscription _stderrSub; diff --git a/apps/cli/lib/src/frontend/celest_frontend.dart b/apps/cli/lib/src/frontend/celest_frontend.dart index d2dc5fe8e..cdfc9d823 100644 --- a/apps/cli/lib/src/frontend/celest_frontend.dart +++ b/apps/cli/lib/src/frontend/celest_frontend.dart @@ -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'); } @@ -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), ); diff --git a/apps/cli/lib/src/frontend/child_process.dart b/apps/cli/lib/src/frontend/child_process.dart index 3be61f327..cfc568c9c 100644 --- a/apps/cli/lib/src/frontend/child_process.dart +++ b/apps/cli/lib/src/frontend/child_process.dart @@ -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 start({ Map? environment, + Map? 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,