Skip to content

Commit 7a4eacc

Browse files
committed
Fixing tests
1 parent 35e3160 commit 7a4eacc

File tree

3 files changed

+84
-65
lines changed

3 files changed

+84
-65
lines changed

packages/host/src/node/cli/apple.ts

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
LinkModuleResult,
1616
ModuleLinker,
1717
} from "./link-modules.js";
18-
import { findXcodeProject } from "./xcode-helpers.js";
18+
import {
19+
determineFrameworkSlice,
20+
ExpectedFrameworkSlice,
21+
findXcodeProject,
22+
} from "./xcode-helpers.js";
1923

2024
const PACKAGE_ROOT = path.resolve(__dirname, "..", "..", "..");
2125
const CLI_PATH = path.resolve(PACKAGE_ROOT, "bin", "react-native-node-api.mjs");
@@ -408,10 +412,13 @@ export async function createAppleLinker(): Promise<ModuleLinker> {
408412
CODE_SIGNING_ALLOWED: signingAllowed,
409413
} = process.env;
410414

415+
const expectedSlice = determineFrameworkSlice();
416+
411417
return (options: LinkModuleOptions) => {
412418
return linkXcframework({
413419
...options,
414420
outputPath,
421+
expectedSlice,
415422
signingIdentity:
416423
signingRequired !== "NO" && signingAllowed !== "NO"
417424
? signingIdentity
@@ -420,74 +427,15 @@ export async function createAppleLinker(): Promise<ModuleLinker> {
420427
};
421428
}
422429

423-
/**
424-
* Maps Xcode PLATFORM_NAME to SupportedPlatform / SupportedPlatformVariant
425-
* as used in xcframework Info.plist (e.g. hello.apple.node/Info.plist).
426-
* PLATFORM_NAME values: iphoneos, iphonesimulator, macosx, appletvos,
427-
* appletvsimulator, xros, xrsimulator.
428-
*/
429-
export function determineFrameworkSlice(): {
430-
platform: string;
431-
platformVariant?: string;
432-
architectures: string[];
433-
} {
434-
const {
435-
PLATFORM_NAME: platformName,
436-
EFFECTIVE_PLATFORM_NAME: effectivePlatformName,
437-
ARCHS: architecturesJoined,
438-
} = process.env;
439-
440-
assert(platformName, "Expected PLATFORM_NAME to be set by Xcodebuild");
441-
assert(architecturesJoined, "Expected ARCHS to be set by Xcodebuild");
442-
const architectures = architecturesJoined.split(" ");
443-
444-
switch (platformName) {
445-
case "iphoneos":
446-
return { platform: "ios", architectures };
447-
case "iphonesimulator":
448-
return {
449-
platform: "ios",
450-
platformVariant: "simulator",
451-
architectures,
452-
};
453-
case "macosx":
454-
return {
455-
platform: "macos",
456-
architectures,
457-
platformVariant: effectivePlatformName?.endsWith("maccatalyst")
458-
? "maccatalyst"
459-
: undefined,
460-
};
461-
case "appletvos":
462-
return { platform: "tvos", architectures };
463-
case "appletvsimulator":
464-
return {
465-
platform: "tvos",
466-
platformVariant: "simulator",
467-
architectures,
468-
};
469-
case "xros":
470-
return { platform: "xros", architectures };
471-
case "xrsimulator":
472-
return {
473-
platform: "xros",
474-
platformVariant: "simulator",
475-
architectures,
476-
};
477-
default:
478-
throw new Error(
479-
`Unsupported platform: ${effectivePlatformName ?? platformName}`,
480-
);
481-
}
482-
}
483-
484430
export async function linkXcframework({
485431
modulePath,
486432
naming,
487433
outputPath: outputParentPath,
434+
expectedSlice,
488435
signingIdentity,
489436
}: LinkModuleOptions & {
490437
outputPath: string;
438+
expectedSlice: ExpectedFrameworkSlice;
491439
signingIdentity?: string;
492440
}): Promise<LinkModuleResult> {
493441
// Copy the xcframework to the output directory and rename the framework and binary
@@ -500,8 +448,6 @@ export async function linkXcframework({
500448
await fs.promises.rm(frameworkOutputPath, { recursive: true, force: true });
501449

502450
const info = await readXcframeworkInfo(path.join(modulePath, "Info.plist"));
503-
504-
const expectedSlice = determineFrameworkSlice();
505451
const framework = info.AvailableLibraries.find((framework) => {
506452
return (
507453
expectedSlice.platform === framework.SupportedPlatform &&

packages/host/src/node/cli/bin.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33
import cp from "node:child_process";
44
import path from "node:path";
5+
import { setupTempDirectory } from "../test-utils";
56

67
const PACKAGE_ROOT = path.join(__dirname, "../../..");
78
const BIN_PATH = path.join(PACKAGE_ROOT, "bin/react-native-node-api.mjs");
@@ -32,13 +33,22 @@ describe("bin", () => {
3233
});
3334

3435
describe("link command", () => {
35-
it("should succeed with a mention of Node-API modules", () => {
36+
it("should succeed with a mention of Node-API modules", (context) => {
37+
const targetBuildDir = setupTempDirectory(context, {});
38+
3639
const { status, stdout, stderr } = cp.spawnSync(
3740
process.execPath,
3841
[BIN_PATH, "link", "--android", "--apple"],
3942
{
4043
cwd: PACKAGE_ROOT,
4144
encoding: "utf8",
45+
env: {
46+
...process.env,
47+
TARGET_BUILD_DIR: targetBuildDir,
48+
FRAMEWORKS_FOLDER_PATH: "Frameworks",
49+
PLATFORM_NAME: "iphonesimulator",
50+
ARCHS: "arm64",
51+
},
4252
},
4353
);
4454

packages/host/src/node/cli/xcode-helpers.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,66 @@ export async function findXcodeProject(fromPath: string) {
8787
throw new Error(`Unexpected scheme: ${scheme}`);
8888
}
8989
}
90+
91+
export type ExpectedFrameworkSlice = {
92+
platform: string;
93+
platformVariant?: string;
94+
architectures: string[];
95+
};
96+
97+
/**
98+
* Maps Xcode PLATFORM_NAME to SupportedPlatform / SupportedPlatformVariant
99+
* as used in xcframework Info.plist (e.g. hello.apple.node/Info.plist).
100+
* PLATFORM_NAME values: iphoneos, iphonesimulator, macosx, appletvos,
101+
* appletvsimulator, xros, xrsimulator.
102+
*/
103+
export function determineFrameworkSlice(): ExpectedFrameworkSlice {
104+
const {
105+
PLATFORM_NAME: platformName,
106+
EFFECTIVE_PLATFORM_NAME: effectivePlatformName,
107+
ARCHS: architecturesJoined,
108+
} = process.env;
109+
110+
assert(platformName, "Expected PLATFORM_NAME to be set by Xcodebuild");
111+
assert(architecturesJoined, "Expected ARCHS to be set by Xcodebuild");
112+
const architectures = architecturesJoined.split(" ");
113+
114+
switch (platformName) {
115+
case "iphoneos":
116+
return { platform: "ios", architectures };
117+
case "iphonesimulator":
118+
return {
119+
platform: "ios",
120+
platformVariant: "simulator",
121+
architectures,
122+
};
123+
case "macosx":
124+
return {
125+
platform: "macos",
126+
architectures,
127+
platformVariant: effectivePlatformName?.endsWith("maccatalyst")
128+
? "maccatalyst"
129+
: undefined,
130+
};
131+
case "appletvos":
132+
return { platform: "tvos", architectures };
133+
case "appletvsimulator":
134+
return {
135+
platform: "tvos",
136+
platformVariant: "simulator",
137+
architectures,
138+
};
139+
case "xros":
140+
return { platform: "xros", architectures };
141+
case "xrsimulator":
142+
return {
143+
platform: "xros",
144+
platformVariant: "simulator",
145+
architectures,
146+
};
147+
default:
148+
throw new Error(
149+
`Unsupported platform: ${effectivePlatformName ?? platformName}`,
150+
);
151+
}
152+
}

0 commit comments

Comments
 (0)