Skip to content

fix(ios): read the app's package.json first, as Android does - #479

Merged
ospfranco merged 3 commits into
OP-Engineering:mainfrom
rachitsrivastava07:fix/podspec-app-package-json
Nov 5, 2026
Merged

ospfranco merged 3 commits into
OP-Engineering:mainfrom
rachitsrivastava07:fix/podspec-app-package-json

Conversation

@rachitsrivastava07

@rachitsrivastava07 rachitsrivastava07 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On iOS, op-sqlite.podspec walks up from its own folder and uses the first package.json it finds. Under pnpm, that folder is in the store (<repo>/node_modules/.pnpm/@op-engineering+op-sqlite@…/node_modules/@op-engineering/op-sqlite), so in a monorepo the walk skips the app and stops at the workspace root. The app's "op-sqlite" block is never read, and nothing fails: an app that asks for SQLCipher builds plain SQLite, and the encryptionKey it passes is ignored.

Package.swift (SwiftPM) has the same walk, and a second problem in front of it. The autolinker gives SwiftPM this package through a symlink inside the app (<app>/ios/build/generated/autolinking/libs/OpSqlite), and #filePath keeps that symlink path. The path has no node_modules in it, so isUserApp is false and the manifest reads example/package.json, which the published package doesn't ship. In any app, pnpm or not, the config is read as empty.

Android doesn't have this problem, because build.gradle reads the app's package.json ($rootDir/../package.json).

Related: #172, #264, #268.

Change

  • The old lookup stays as it is. After it, if CocoaPods found a Podfile (Pod::Config.instance.podfile_path; pod install looks it up before it evaluates any podspec), the podspec walks up from the app, the folder above the Podfile. It goes no higher than the folder the old lookup found, and uses the first package.json on the way with an "op-sqlite" key.
  • If there is none, the old result stands. A config kept in a monorepo root package.json, which the docs recommend today, is still picked up, and nothing above the workspace is read.
  • Package.swift does the same. It runs the old walk from the symlink's real directory (resolvingSymlinksInPath()), so node_modules is found. Then, when it was reached through the autolinker's symlink, it walks up from the app, the folder above the one holding build/generated/autolinking, with the same bound and the same "op-sqlite" key rule. Without the symlink it keeps the old result. isUserApp itself, and everything else that uses it, is unchanged.
  • One behaviour change: when both the app's and the root's package.json have an "op-sqlite" block, iOS now uses the app's. Android already does.
  • The monorepo note in docs/docs/installation.md now says to put the config in the app's package.json.

Tested

I ran the old and new podspec under a stub of the CocoaPods calls the podspec makes (Pod::Spec.new, Pod::Config.instance.podfile_path), with "sqlcipher": true wherever a config is present unless the row says otherwise:

Layout Old New
pnpm store, config in apps/mobile/package.json only root package.json, pure SQLite apps/mobile/package.json, SQLCipher
Hoisted to the root node_modules, config in the root package.json only root, SQLCipher root, SQLCipher
Single app, config in its package.json app, SQLCipher app, SQLCipher
Single app, no config app, pure SQLite app, pure SQLite
Pod::Config not defined root, pure SQLite root, pure SQLite
pnpm store, config in the root package.json only root, SQLCipher root, SQLCipher
pnpm store, root asks for SQLCipher, app has a block without it root, SQLCipher app, pure SQLite
Config only in a package.json above the workspace workspace root, pure SQLite workspace root, pure SQLite
op-sqlite installed outside the app's folder its parent's package.json, pure SQLite same

Only the first row and the both-configs row change.

For Package.swift I built each layout on disk with the autolinker's symlink, plus a root package that depends on ../build/generated/autolinking/libs/OpSqlite, and ran swift package resolve (Swift 6.3.3) with the old and the new manifest. The table shows the package.json each one printed in [OP-SQLITE] SPM configuration found at:

Layout Old New
Single app (npm), config in the app …/OpSqlite/example/package.json (missing, so no config) app
pnpm store, config in the app only same missing file app
pnpm store, config in the root only same missing file root
pnpm store, no config same missing file root
npm workspaces hoisted to the root, config in the app same missing file app
pnpm store, both configured same missing file app
pnpm store, app package.json isn't valid JSON, root configured same missing file root
This repo's example/ (the symlink points at the repo root) example/package.json example/package.json
No symlink, evaluated in the pnpm store directly root root

I also loaded both versions of the podspec through real CocoaPods 1.17.0 (Pod::Specification.from_file), run from the ios/ folder of a pnpm monorepo app (React Native 0.86.3) with the Podfile already looked up, as pod install does first. The old podspec read the root package.json and used pure SQLite. The new one reported Configuration found at …/apps/mobile/package.json, using SQLCipher and Performance mode enabled, and its GCC_PREPROCESSOR_DEFINITIONS include SQLITE_HAS_CODEC. Without the Podfile lookup, both versions give the old result.

I haven't run a full pod install, an Xcode build, or react-native spm update with this branch; the fixtures stand in for the autolinker's symlink.

Not in this PR

isUserApp in Package.swift is still false under the symlink, and the tokenizers step uses it to find c_sources. I left that alone because I haven't run a tokenizers build.

🤖 Generated with Claude Code

The podspec walked up from its own folder to the first package.json. Under
pnpm that folder is in the store, so in a monorepo the walk ended at the
workspace root and ignored the app's "op-sqlite" config: a SQLCipher app
built plain SQLite. Android already reads the app's package.json.

The old lookup stays as it was. After it, when CocoaPods found a Podfile, the
podspec walks up from the app (the folder above the Podfile), no higher than
the folder the old lookup found, and uses the first package.json with an
"op-sqlite" key. A config in a monorepo root package.json still works, and
nothing above the workspace is read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ospfranco

Copy link
Copy Markdown
Contributor

Fix the swift version too please

rachitsrivastava07 and others added 2 commits November 5, 2026 12:17
The autolinker hands SwiftPM this package through a symlink inside the app,
and #filePath keeps that path. It is not inside node_modules, so isUserApp was
false and the manifest read example/package.json, which the published package
does not ship: the app's "op-sqlite" config was ignored. Search from the real
directory instead, then prefer the app's package.json as the podspec does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rachitsrivastava07
rachitsrivastava07 force-pushed the fix/podspec-app-package-json branch from d82ab1c to 1eef2a7 Compare November 5, 2026 07:28
@rachitsrivastava07

rachitsrivastava07 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Fix the swift version too please

Done in 08f4d7b. Testing it showed SwiftPM had a second problem in front of the pnpm one: the autolinker hands the package over through a symlink inside the app, #filePath keeps that path, and with no node_modules in it the manifest read example/package.json, which the published package doesn't ship. So the app's config was ignored in every SwiftPM app. The description has the fixture results for both manifests.

@ospfranco
ospfranco merged commit 1eef2a7 into OP-Engineering:main Nov 5, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants