Skip to content

[codex] Rewrite pnpm SPM node_modules paths#2003

Merged
riderx merged 2 commits into
mainfrom
codex/pnpm-spm-node-modules-rewrite
May 1, 2026
Merged

[codex] Rewrite pnpm SPM node_modules paths#2003
riderx merged 2 commits into
mainfrom
codex/pnpm-spm-node-modules-rewrite

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 1, 2026

Summary (AI generated)

  • Rewrite deep pnpm Swift Package Manager node_modules paths back to project-root relative paths.
  • Add a regression fixture matching a pnpm workspace Package.swift dependency path.

Motivation (AI generated)

The native build archive already included the pnpm package contents, but Package.swift could still point at ../../../../../node_modules/... after .pnpm path flattening, so Xcode looked for packages outside the uploaded layout.

Business Impact (AI generated)

This unblocks native iOS cloud builds for pnpm workspace customers using Capacitor SPM dependencies, reducing build failures for monorepo apps.

Test Plan (AI generated)

  • Confirmed the new regression fails before the fix.
  • bun run test:build-zip-filter
  • bun run lint
  • bun run build

Generated with AI

Summary by CodeRabbit

  • Bug Fixes

    • Improved path handling logic for iOS builds to correctly normalize relative references to dependencies in monorepo setups, ensuring consistent path rewriting across different dependency locations.
  • Tests

    • Extended test coverage to validate Swift Package Manager metadata files are properly included in builds and that relative paths are correctly normalized in monorepo environments.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 23 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12608f65-fd54-41b7-aa4a-ea2a05858dff

📥 Commits

Reviewing files that changed from the base of the PR and between 255e201 and a37ed9b.

📒 Files selected for processing (2)
  • cli/src/build/request.ts
  • cli/test/test-build-zip-filter.mjs
📝 Walkthrough

Walkthrough

Updated pnpm path-rewriting logic in the build process to normalize excessive relative path references (../) for both iOS and node_modules prefixes in Swift Package Manager metadata files. Extended corresponding test coverage to validate the rewritten paths are correctly generated in the build output.

Changes

Cohort / File(s) Summary
Path Rewriting Logic
cli/src/build/request.ts
Broadened the iOS-only ../ collapsing behavior in zipDirectory to also handle deep relative references pointing to node_modules/, normalizing both prefixes to 3-level relative form (../../../). Updated comments to reflect expanded scope.
Test Coverage for SPM Metadata
cli/test/test-build-zip-filter.mjs
Extended pnpm workspace test to create and validate Package.swift files for both the app and workspace plugins, asserting correct inclusion in zip and verifying rewritten relative paths replace explicit pnpm paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Paths now hop both ways, iOS and node_modules too,
No more tangled ../ chains, just clean ../../../ through,
Swift packages bundled tight, tests proving every dance,
The pnpm workspace waltz—a rabbit's second chance! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: rewriting pnpm Swift Package Manager node_modules paths, which is the primary objective of the PR.
Description check ✅ Passed The description includes Summary, Motivation, Business Impact, and Test Plan sections with substantive details, closely matching the required template structure despite some AI-generated phrasing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pnpm-spm-node-modules-rewrite

Review rate limit: 0/5 reviews remaining, refill in 8 minutes and 23 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 1, 2026

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing codex/pnpm-spm-node-modules-rewrite (a37ed9b) with main (b581d9f)

Open in CodSpeed

@riderx riderx marked this pull request as ready for review May 1, 2026 12:25
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 255e201960

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cli/src/build/request.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cli/test/test-build-zip-filter.mjs (1)

453-494: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add coverage for a nested ios.path layout.

This regression only exercises the flat ios/ case, so it won’t catch the path-depth bug above. A second fixture with a deeper ios.path (for example apps/native/ios) would verify that Package.swift keeps the correct number of ../ segments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/test/test-build-zip-filter.mjs` around lines 453 - 494, Add a second test
case in the same file that exercises a nested ios.path (e.g., 'apps/native/ios')
to catch the path-depth bug: create a project fixture with the deeper ios
layout, write the same Package.swift and plugin files under that nested ios
path, call zipDirectory with ios.path set to the deeper path, then assert the
zip contains the workspace plugin files (using entries.includes checks) and that
zip.readAsText for the generated CapApp-SPM/Package.swift uses the correct
number of ../ segments for the deeper layout; update assertions to match the
expected relative path (more ../ segments) so the test fails until the
path-depth bug is fixed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/src/build/request.ts`:
- Around line 1089-1096: The current ios-path rewrite unconditionally reduces
any run of four-or-more "../" to exactly "../../../", which breaks deeply nested
ios layouts; in the platform === 'ios' block that mutates rewritten, change the
replace call to use a replacement function (not a fixed string) that counts how
many "../" segments were matched and reduces them to at most three but preserves
fewer if the original needed fewer — i.e. compute the match length, decide the
number of "../" to keep (min(originalCount, 3)), and return that repeated
segment plus the captured "ios/" or "node_modules/" suffix so nested ios paths
that legitimately need more hops aren't truncated incorrectly. Ensure you update
the call that references rewritten.replace and keep the same regex but provide a
callback replacement.

---

Outside diff comments:
In `@cli/test/test-build-zip-filter.mjs`:
- Around line 453-494: Add a second test case in the same file that exercises a
nested ios.path (e.g., 'apps/native/ios') to catch the path-depth bug: create a
project fixture with the deeper ios layout, write the same Package.swift and
plugin files under that nested ios path, call zipDirectory with ios.path set to
the deeper path, then assert the zip contains the workspace plugin files (using
entries.includes checks) and that zip.readAsText for the generated
CapApp-SPM/Package.swift uses the correct number of ../ segments for the deeper
layout; update assertions to match the expected relative path (more ../
segments) so the test fails until the path-depth bug is fixed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6e86a0b-aaef-49c3-b699-16860e781a86

📥 Commits

Reviewing files that changed from the base of the PR and between ebc8338 and 255e201.

📒 Files selected for processing (2)
  • cli/src/build/request.ts
  • cli/test/test-build-zip-filter.mjs

Comment thread cli/src/build/request.ts Outdated
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@riderx riderx merged commit 335484d into main May 1, 2026
50 checks passed
@riderx riderx deleted the codex/pnpm-spm-node-modules-rewrite branch May 1, 2026 13:07
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.

1 participant