@@ -607,4 +607,89 @@ void main() {
607607 );
608608 }
609609 }, skip: ! platform.isMacOS); // [intended] Swift Package Manager only works on macos.
610+
611+ test ('Removing the last plugin updates the generated Swift package' , () async {
612+ final Directory workingDirectory = fileSystem.systemTempDirectory
613+ .createTempSync ('swift_package_manager_remove_last_plugin.' );
614+ final String workingDirectoryPath = workingDirectory.path;
615+ try {
616+ await SwiftPackageManagerUtils .enableSwiftPackageManager (
617+ flutterBin,
618+ workingDirectoryPath,
619+ );
620+
621+ // Create an app with a plugin.
622+ final String appDirectoryPath = await SwiftPackageManagerUtils .createApp (
623+ flutterBin,
624+ workingDirectoryPath,
625+ iosLanguage: 'swift' ,
626+ platform: 'ios' ,
627+ usesSwiftPackageManager: true ,
628+ options: < String > ['--platforms=ios' ],
629+ );
630+
631+ final SwiftPackageManagerPlugin integrationTestPlugin =
632+ SwiftPackageManagerUtils .integrationTestPlugin ('ios' );
633+
634+ SwiftPackageManagerUtils .addDependency (
635+ appDirectoryPath: appDirectoryPath,
636+ plugin: integrationTestPlugin,
637+ );
638+
639+ // Build the app to generate the Swift package.
640+ await SwiftPackageManagerUtils .buildApp (
641+ flutterBin,
642+ appDirectoryPath,
643+ options: < String > ['ios' , '--config-only' , '-v' ],
644+ );
645+
646+ // Verify the generated Swift package depends on the plugin.
647+ final File generatedManifestFile = fileSystem
648+ .directory (appDirectoryPath)
649+ .childDirectory ('ios' )
650+ .childDirectory ('Flutter' )
651+ .childDirectory ('ephemeral' )
652+ .childDirectory ('Packages' )
653+ .childDirectory ('FlutterGeneratedPluginSwiftPackage' )
654+ .childFile ('Package.swift' );
655+
656+ expect (generatedManifestFile.existsSync (), isTrue);
657+
658+ String generatedManifest = generatedManifestFile.readAsStringSync ();
659+ final String generatedSwiftDependency = '''
660+ dependencies: [
661+ .package(name: "integration_test", path: "${integrationTestPlugin .swiftPackagePlatformPath }")
662+ ],
663+ ''' ;
664+
665+ expect (generatedManifest.contains (generatedSwiftDependency), isTrue);
666+
667+ // Remove the plugin and rebuild the app to re-generate the Swift package.
668+ SwiftPackageManagerUtils .removeDependency (
669+ appDirectoryPath: appDirectoryPath,
670+ plugin: integrationTestPlugin,
671+ );
672+
673+ await SwiftPackageManagerUtils .buildApp (
674+ flutterBin,
675+ appDirectoryPath,
676+ options: < String > ['ios' , '--config-only' , '-v' ],
677+ );
678+
679+ // Verify the generated Swift package does not depend on the plugin.
680+ expect (generatedManifestFile.existsSync (), isTrue);
681+
682+ generatedManifest = generatedManifestFile.readAsStringSync ();
683+ const String emptyDependencies = 'dependencies: [\n \n ],\n ' ;
684+
685+ expect (generatedManifest.contains (generatedSwiftDependency), isFalse);
686+ expect (generatedManifest.contains (emptyDependencies), isTrue);
687+ } finally {
688+ await SwiftPackageManagerUtils .disableSwiftPackageManager (flutterBin, workingDirectoryPath);
689+ ErrorHandlingFileSystem .deleteIfExists (
690+ workingDirectory,
691+ recursive: true ,
692+ );
693+ }
694+ }, skip: ! platform.isMacOS); // [intended] Swift Package Manager only works on macos.
610695}
0 commit comments