Skip to content

Commit fd9cfb9

Browse files
claudekraenhansen
authored andcommitted
refactor: validate Info.plist with a zod schema
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RFTxhqB2yuMZU7AvpM5nvx
1 parent ded6da2 commit fd9cfb9

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

‎packages/node-addon-examples/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"node-addon-examples": "github:nodejs/node-addon-examples#4b7dd86a85644610e6de80154df9acac9329b509",
3636
"gyp-to-cmake": "workspace:*",
3737
"read-pkg": "^9.0.1",
38-
"weak-node-api": "workspace:*"
38+
"weak-node-api": "workspace:*",
39+
"zod": "^4.1.11"
3940
},
4041
"dependencies": {
4142
"assert": "^2.1.0",

‎packages/node-addon-examples/scripts/verify-prebuilds.mts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
33
import path from "node:path";
44

55
import plist from "@expo/plist";
6+
import * as z from "zod";
67

78
import { DIRS } from "./cmake-projects.mjs";
89

@@ -39,22 +40,21 @@ async function verifyAndroidPrebuild(dirent: fs.Dirent) {
3940
}
4041
}
4142

43+
const InfoPlistSchema = z.object({
44+
CFBundleExecutable: z.string(),
45+
CFBundleName: z.string(),
46+
CFBundleIdentifier: z.string().regex(/^[A-Za-z0-9-.]+$/),
47+
});
48+
4249
async function verifyInfoPlist(frameworkDir: string) {
4350
const libraryName = path.basename(frameworkDir, ".framework");
44-
const info: unknown = plist.default.parse(
45-
await fs.promises.readFile(path.join(frameworkDir, "Info.plist"), "utf8"),
46-
);
47-
assert(typeof info === "object" && info !== null, "Expected a plist dict");
48-
const CFBundleExecutable: unknown = Reflect.get(info, "CFBundleExecutable");
49-
const CFBundleName: unknown = Reflect.get(info, "CFBundleName");
50-
const CFBundleIdentifier: unknown = Reflect.get(info, "CFBundleIdentifier");
51-
assert.equal(CFBundleExecutable, libraryName);
52-
assert.equal(CFBundleName, libraryName);
53-
assert(
54-
typeof CFBundleIdentifier === "string" &&
55-
/^[A-Za-z0-9-.]+$/.test(CFBundleIdentifier),
56-
`Invalid CFBundleIdentifier in ${frameworkDir}: ${String(CFBundleIdentifier)}`,
51+
const info = InfoPlistSchema.parse(
52+
plist.default.parse(
53+
await fs.promises.readFile(path.join(frameworkDir, "Info.plist"), "utf8"),
54+
),
5755
);
56+
assert.equal(info.CFBundleExecutable, libraryName);
57+
assert.equal(info.CFBundleName, libraryName);
5858
assert(
5959
fs.existsSync(path.join(frameworkDir, libraryName)),
6060
`Missing executable ${libraryName} in ${frameworkDir}`,

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)