commands/spm_utils library
SPM (Swift Package Manager) utilities for nitrogen CLI.
Provides helpers for detecting, validating, and managing SPM configuration in Flutter plugins. Used by init, link, doctor, and migrate commands.
Classes
- PackageSwiftValidation
- Validation result for a Package.swift file.
- SpmSourcesValidation
- Verifies SPM Sources directory structure is correct.
- SpmStatus
- Result of SPM detection for a plugin.
Functions
-
createSpmSourcesStructure(
String baseDir, String platform, String className, String pluginName) → void - Creates the SPM Sources directory structure for a platform.
-
detectSpmStatus(
String baseDir) → SpmStatus - Detects SPM and CocoaPods status for a plugin directory.
-
ensureFlutterFrameworkDependency(
String packageSwiftPath) → bool -
Ensures
packageSwiftPathdeclares FlutterFramework at both the package level (dependencies: [...]) and inside the Swift target's dependencies. Idempotent — does nothing when already present. -
ensureFlutterFrameworkSymlink(
String packageSwiftPath, String pluginBaseDir) → bool -
Attempts to ensure the FlutterFramework package referenced in
packageSwiftPathis resolvable by creating a symlink at the expected path. -
ensureModuleCppTargets(
String packageSwiftPath, {required String pluginName, required String pluginClass, required List< String> moduleClasses}) → bool -
Ensures
packageSwiftPathdeclares one<ModuleClass>Cpptarget per entry inmoduleClassesand that the Swift target (pluginName) depends on each of them. Idempotent: a module whosename: "<ModuleClass>Cpp"already appears anywhere in the manifest is left untouched, so hand-tuned target blocks survive re-runs. -
flutterFrameworkPathExists(
String packageSwiftPath) → bool -
Returns
truewhen the FlutterFramework path declared inpackageSwiftPathresolves to an existing directory on disk. -
getSpmSourcesDirs(
String packageSwiftPath) → List< String> - Gets the Sources directories from a Package.swift.
-
isNestedSpmLayout(
String packageSwiftPath) → bool - Checks if a Package.swift uses the Flutter 3.41+ nested layout.
-
isNestedSpmPath(
String packageSwiftPath) → bool -
Returns true if the given
packageSwiftPathis in a nested Flutter 3.41+ layout (ios/<name>/Package.swift) rather than the flatios/Package.swift. -
moduleCppTargetBlock(
String moduleClass, String pluginClass, {String indent = ' '}) → String -
The
.target(...)block for one module's SPM C++ target, named after the module's Dart class (<ModuleClass>Cpp). It depends on the plugin-level<pluginClass>Cpptarget, which ownsdart_api_dl.cand the shared nitro headers — compiled exactly once for the whole package (compilingdart_api_dl.cper target would duplicate its symbols at link time). -
toPascalCase(
String name) → String - Converts a plugin name to PascalCase class name.
-
validatePackageSwift(
String path, String platform) → PackageSwiftValidation - Validates a Package.swift file for correct Nitro configuration.
-
validateSpmSourcesStructure(
String baseDir, String platform, String className) → SpmSourcesValidation - Validates the SPM Sources directory structure for a platform.