From 56499cfbd70a3de610071b553c8001a4ac212592 Mon Sep 17 00:00:00 2001 From: rachitsrivastava07 Date: Wed, 4 Nov 2026 18:13:44 +0530 Subject: [PATCH 1/3] fix(ios): read the app's package.json first, as Android does 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 --- op-sqlite.podspec | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/op-sqlite.podspec b/op-sqlite.podspec index 905d8e95..e8fac96d 100644 --- a/op-sqlite.podspec +++ b/op-sqlite.podspec @@ -32,6 +32,32 @@ if is_user_app end raise "package.json not found" if package_json_path.nil? + + # Under pnpm, or when hoisted to a monorepo root, the search above ends at + # the workspace root and skips the app. Prefer the app, the folder above the + # Podfile (the same package.json Android reads): walk up from it, no further + # than the folder found above, and take the first package.json with an + # "op-sqlite" key. `pod install` finds the Podfile before evaluating any + # podspec; when none was found, podfile_path is nil. + podfile_path = defined?(Pod::Config) ? Pod::Config.instance.podfile_path : nil + if podfile_path + stop_dir = File.dirname(package_json_path) + current_dir = File.dirname(File.dirname(podfile_path.to_s)) + while current_dir == stop_dir || current_dir.start_with?(File.join(stop_dir, "")) + package_path = File.join(current_dir, "package.json") + has_config = File.exist?(package_path) && begin + JSON.parse(File.read(package_path)).key?("op-sqlite") + rescue JSON::ParserError + false + end + if has_config + package_json_path = package_path + break + end + break if current_dir == stop_dir + current_dir = File.dirname(current_dir) + end + end else package_json_path = File.join(__dir__, "example", "package.json") end From 08f4d7babf6189cbbc8a27559d27ab0b341bfcd7 Mon Sep 17 00:00:00 2001 From: rachitsrivastava07 Date: Thu, 5 Nov 2026 12:17:46 +0530 Subject: [PATCH 2/3] fix(ios): Package.swift reads the app's package.json too 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 --- Package.swift | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index dd89ddc5..04fcf3da 100644 --- a/Package.swift +++ b/Package.swift @@ -42,15 +42,21 @@ func readJSONObject(atPath path: String) -> [String: Any] { // searching up through parent directories (starting one level above this // package, i.e. outside node_modules/@op-engineering/op-sqlite). In the // monorepo/dev checkout it's simply example/package.json. +// #filePath keeps the autolinker's symlink path (see the header), which is not +// inside node_modules, so the search starts from the real directory. +let resolvedPackageRoot = packageRoot.resolvingSymlinksInPath() + let appPackageJSONPath: String = { - guard isUserApp else { + guard resolvedPackageRoot.path.contains("node_modules") else { return packageRoot.appendingPathComponent("example/package.json").path } - var currentDir = packageRoot.deletingLastPathComponent() + var packageJSONPath: String + var currentDir = resolvedPackageRoot.deletingLastPathComponent() while true { let candidate = currentDir.appendingPathComponent("package.json").path if FileManager.default.fileExists(atPath: candidate) { - return candidate + packageJSONPath = candidate + break } let parentDir = currentDir.deletingLastPathComponent() if parentDir.path == currentDir.path { @@ -58,6 +64,30 @@ let appPackageJSONPath: String = { } currentDir = parentDir } + + // Under pnpm, or when hoisted to a monorepo root, the search above ends at + // the workspace root and skips the app. Prefer the app, the folder above the + // one holding build/generated/autolinking (the same package.json Android + // reads): walk up from it, no further than the folder found above, and take + // the first package.json with an "op-sqlite" key. Without the autolinker's + // symlink the app is unknown and the search above stands. + guard let marker = packageRoot.path.range(of: "/build/generated/autolinking/libs/") else { + return packageJSONPath + } + let stopDir = URL(fileURLWithPath: packageJSONPath).deletingLastPathComponent().path + var appDir = URL(fileURLWithPath: String(packageRoot.path[.. Date: Wed, 4 Nov 2026 18:13:44 +0530 Subject: [PATCH 3/3] docs: monorepo config lives in the app's package.json Co-Authored-By: Claude Opus 5.5 --- docs/docs/installation.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/docs/installation.md b/docs/docs/installation.md index 3ec9cb8e..a5c1f074 100644 --- a/docs/docs/installation.md +++ b/docs/docs/installation.md @@ -49,10 +49,9 @@ Required response headers (for worker/OPFS setup): SQLite is very customizable on compilation level. op-sqlite also allows you add extensions or even change the base implementation. You can do this by adding the following to your `package.json`: > [!IMPORTANT] -> When using a monorepo, be sure to add the "op-sqlite" config to the monorepo root `package.json` file. -> This is necessary because the `node_modules/@op-engineering/op-sqlite/op-sqlite.podspec` will search for first the `package.json` file in a parent directory. -> Alternative, you may be able to solve this by blocking this package from being hoisted to the root `node_modules`. -> Check your ios/Podfile.lock to see where it's being installed. +> In a monorepo, put the "op-sqlite" config in your app's `package.json` (the folder above `ios/` and `android/`). +> On iOS (CocoaPods and SwiftPM) the build walks up from that folder and uses the first `package.json` with an "op-sqlite" key, so a config in the monorepo root `package.json` is still picked up. +> The build prints which file it used (`[OP-SQLITE] Configuration found at ...` from `pod install`, `[OP-SQLITE] SPM configuration found at ...` from SwiftPM). ```json {