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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion op-sqlite.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ parent_folder_name = File.basename(__dir__)
app_package = nil
# When installed on user node_modules lives inside node_modules/@op-engineering/op-sqlite
if is_user_app
app_package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "package.json")))
current_dir = File.expand_path(__dir__)
package_json_path = nil

# 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
app_package = JSON.parse(File.read(File.join(__dir__, "example", "package.json")))
Expand Down
Loading