Support `--source` in kernel compilation commands (#3613)

diff --git a/lib/src/dart.dart b/lib/src/dart.dart
index 5c3828e..d922de0 100644
--- a/lib/src/dart.dart
+++ b/lib/src/dart.dart
@@ -145,12 +145,17 @@
 /// for `package:` uri resolution.
 ///
 /// The [name] is used to describe the executable in logs and error messages.
+///
+/// The [additionalSources], if provided, instruct the compiler to include
+/// additional source files into compilation even if they are not referenced
+/// from the main library.
 Future<void> precompile({
   required String executablePath,
   required String incrementalDillPath,
   required String name,
   required String outputPath,
   required String packageConfigPath,
+  List<String> additionalSources = const [],
 }) async {
   ensureDir(p.dirname(outputPath));
   ensureDir(p.dirname(incrementalDillPath));
@@ -181,6 +186,7 @@
       platformDill,
       sdkRoot: sdkRoot,
       packagesJson: packageConfigPath,
+      additionalSources: additionalSources,
       printIncrementalDependencies: false,
     );
     final result = await client.compile();
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index 937d830..76bcdcd 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -447,23 +447,39 @@
   }
 
   /// Precompiles executable .dart file at [path] to a snapshot.
-  Future<void> precompileExecutable(Executable executable) async {
+  ///
+  /// The [additionalSources], if provided, instruct the compiler to include
+  /// additional source files into compilation even if they are not referenced
+  /// from the main library.
+  Future<void> precompileExecutable(
+    Executable executable, {
+    List<String> additionalSources = const [],
+  }) async {
     await log.progress('Building package executable', () async {
       ensureDir(p.dirname(pathOfExecutable(executable)));
-      return waitAndPrintErrors([_precompileExecutable(executable)]);
+      return waitAndPrintErrors([
+        _precompileExecutable(
+          executable,
+          additionalSources: additionalSources,
+        )
+      ]);
     });
   }
 
-  Future<void> _precompileExecutable(Executable executable) async {
+  Future<void> _precompileExecutable(
+    Executable executable, {
+    List<String> additionalSources = const [],
+  }) async {
     final package = executable.package;
 
     await dart.precompile(
-        executablePath: resolveExecutable(executable),
-        outputPath: pathOfExecutable(executable),
-        incrementalDillPath: incrementalDillPathOfExecutable(executable),
-        packageConfigPath: packageConfigPath,
-        name:
-            '$package:${p.basenameWithoutExtension(executable.relativePath)}');
+      executablePath: resolveExecutable(executable),
+      outputPath: pathOfExecutable(executable),
+      incrementalDillPath: incrementalDillPathOfExecutable(executable),
+      packageConfigPath: packageConfigPath,
+      name: '$package:${p.basenameWithoutExtension(executable.relativePath)}',
+      additionalSources: additionalSources,
+    );
   }
 
   /// The location of the snapshot of the dart program at [path] in [package]
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index d926023..b3d8be6 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -267,12 +267,17 @@
 ///
 /// Throws an [CommandResolutionFailedException] if the command is not found or
 /// if the entrypoint is not up to date (requires `pub get`) and a `pub get`.
+///
+/// The [additionalSources], if provided, instructs the compiler to include
+/// additional source files into compilation even if they are not referenced
+/// from the main library that [descriptor] resolves to.
 Future<DartExecutableWithPackageConfig> getExecutableForCommand(
   String descriptor, {
   bool allowSnapshot = true,
   String? root,
   String? pubCacheDir,
   PubAnalytics? analytics,
+  List<String> additionalSources = const [],
 }) async {
   root ??= p.current;
   var asPath = descriptor;
@@ -363,7 +368,10 @@
         entrypoint.packageGraph.isPackageMutable(package)) {
       try {
         await warningsOnlyUnlessTerminal(
-          () => entrypoint.precompileExecutable(executable),
+          () => entrypoint.precompileExecutable(
+            executable,
+            additionalSources: additionalSources,
+          ),
         );
       } on ApplicationException catch (e) {
         throw CommandResolutionFailedException._(
diff --git a/pubspec.yaml b/pubspec.yaml
index f7c1077..00c9829 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -13,7 +13,7 @@
   collection: ^1.15.0
   convert: ^3.0.2
   crypto: ^3.0.1
-  frontend_server_client: ^3.0.0
+  frontend_server_client: ^3.1.0
   http: ^0.13.3
   http_multi_server: ^3.0.1
   http_parser: ^4.0.1