Skip to content

Commit 3d797e9

Browse files
committed
fix: handle spm packages internal to cli
Swap third party trapeze dependency with cli internal handling.
1 parent 1eae2f6 commit 3d797e9

8 files changed

Lines changed: 1317 additions & 1540 deletions

File tree

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ injector.require("iOSProvisionService", "./services/ios-provision-service");
6060
injector.require("xcconfigService", "./services/xcconfig-service");
6161
injector.require("iOSSigningService", "./services/ios/ios-signing-service");
6262
injector.require("spmService", "./services/ios/spm-service");
63+
injector.require("spmPbxprojService", "./services/ios/spm-pbxproj-service");
6364
injector.require(
6465
"xcodebuildArgsService",
6566
"./services/ios/xcodebuild-args-service",

lib/definitions/ios.d.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,42 @@ declare global {
4141
): Promise<string>;
4242
}
4343

44-
type IosSPMPackage = IosSPMPackageDefinition & { targets?: string[] };
44+
interface IosSPMPackageBase {
45+
name: string;
46+
/** Swift product names to link from the package. */
47+
libs: string[];
48+
/**
49+
* Optional: if the project has additional targets (widgets, watch apps,
50+
* extensions...) list their names here to link the package with them too.
51+
*/
52+
targets?: string[];
53+
}
54+
55+
/** A package resolved from a git remote at a version, range, branch or revision. */
56+
interface IosRemoteSPMPackage extends IosSPMPackageBase {
57+
repositoryURL: string;
58+
version: string;
59+
}
60+
61+
/** A package resolved from a directory on disk. */
62+
interface IosLocalSPMPackage extends IosSPMPackageBase {
63+
path: string;
64+
}
65+
66+
type IosSPMPackage = IosRemoteSPMPackage | IosLocalSPMPackage;
67+
68+
/** One package linked into one target of the Xcode project. */
69+
interface IosSPMPackageAssignment {
70+
targetName: string;
71+
package: IosSPMPackage;
72+
}
73+
74+
interface ISPMPbxprojService {
75+
addPackages(
76+
projectRoot: string,
77+
assignments: IosSPMPackageAssignment[],
78+
): boolean;
79+
}
4580

4681
interface ISPMService {
4782
applySPMPackages(

lib/services/ios-watch-app-service.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import { IPlatformData } from "../definitions/platform";
2020
import { IFileSystem } from "../common/declarations";
2121
import { injector } from "../common/yok";
22-
import { MobileProject } from "@nstudio/trapezedev-project";
2322
import { Minimatch } from "minimatch";
2423

2524
const sourceExtensions = [
@@ -77,6 +76,7 @@ export class IOSWatchAppService implements IIOSWatchAppService {
7776
protected $xcode: IXcode,
7877
private $iOSNativeTargetService: IIOSNativeTargetService,
7978
private $logger: ILogger,
79+
private $spmPbxprojService: ISPMPbxprojService,
8080
) {}
8181

8282
private addResourceFile(
@@ -1416,20 +1416,8 @@ export class IOSWatchAppService implements IIOSWatchAppService {
14161416
`Applying ${watchSPMPackages.length} SPM package(s) to targets:${targetNames}`,
14171417
);
14181418

1419-
const project = new MobileProject(platformData.projectRoot, {
1420-
ios: {
1421-
path: ".",
1422-
},
1423-
enableAndroid: false,
1424-
});
1425-
await project.load();
1426-
1427-
if (!project.ios) {
1428-
this.$logger.debug("No iOS project found via trapeze");
1429-
return;
1430-
}
1431-
14321419
// Add SPM packages to each watch target
1420+
const assignments: IosSPMPackageAssignment[] = [];
14331421
for (const pkg of watchSPMPackages) {
14341422
if ("path" in pkg) {
14351423
pkg.path = path.resolve(basedir, pkg.path);
@@ -1439,11 +1427,22 @@ export class IOSWatchAppService implements IIOSWatchAppService {
14391427
`Adding SPM package ${JSON.stringify(pkg)} to targets ${targetNames}`,
14401428
);
14411429
for (const targetName of targetNames) {
1442-
project.ios.addSPMPackage(targetName, pkg);
1430+
assignments.push({ targetName, package: pkg });
14431431
}
14441432
}
14451433

1446-
await project.commit();
1434+
if (
1435+
!this.$spmPbxprojService.addPackages(
1436+
platformData.projectRoot,
1437+
assignments,
1438+
)
1439+
) {
1440+
this.$logger.debug(
1441+
`No SPM packages were applied to targets ${targetNames}`,
1442+
);
1443+
return;
1444+
}
1445+
14471446
this.$logger.debug(
14481447
`Successfully applied SPM packages to targets ${targetNames}`,
14491448
);

0 commit comments

Comments
 (0)