Skip to content

find package.json in parent directories in podspec file #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

bviebahn
Copy link

Sorry about the last one, this time this should properly fix #172

I created 2 repositories that include patches with this change to test this.
A non-monorepo project:

git clone https://github.com/bviebahn/op-sqlite-expo.git
cd op-sqlite-expo
npm i
npm run prebuild

And a monorepo project:

git clone https://github.com/bviebahn/op-sqlite-monorepo.git
cd op-sqlite-monorepo
pnpm i
cd apps/mobile
pnpm prebuild

prebuild will run pod install, you should see ✔ Installed CocoaPods at the end.
In the monorepo project, you can also remove the patch from the root package.json, to verify that installing pods fails without the patch.

Let me know if I missed something @ospfranco

@ospfranco
Copy link
Contributor

ospfranco commented May 4, 2025

Oh, sorry, I completely missed this PR. I just copied and pasted the snippet for recursively navigating and it was not working on the non-monorepo version. Because it starts in node_modules/@op-engineering/op-sqlite, the first loop detects the node_modules/@op-engineering/op-sqlite/package.json and sees no configuration at all, so it completely ignores the correct package.json, I solved it by moving one level up before starting the loop:

if is_user_app
  current_dir = File.expand_path(__dir__)
  # Move one level up to the parent directory
  current_dir = File.dirname(current_dir)
  
  # Find the package.json by searching up through parent directories
  loop do
    package_path = File.join(current_dir, "package.json")
    if File.exist?(package_path)
      package_json_path = package_path
      break
    end

    parent_dir = File.dirname(current_dir)
    break if parent_dir == current_dir  # reached filesystem root
    current_dir = parent_dir
  end
  
  raise "package.json not found" if package_json_path.nil?
  
  app_package = JSON.parse(File.read(package_json_path))
# When running on the example app
else
  package_json_path = File.join(__dir__, "example", "package.json")
  app_package = JSON.parse(File.read(File.join(__dir__, "example", "package.json")))
end

Did you test setting a different configuration and seeing if it is correctly picked up?

@ospfranco
Copy link
Contributor

Also, this should close #264

@ospfranco
Copy link
Contributor

Yeah, just tested your monorepo example and without moving one level up the configuration is not picked up. I will close this and open my own PR with the fixed version, but your solution seems to work, thanks!

@ospfranco ospfranco closed this May 4, 2025
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.

pod install fails when using pnpm
2 participants