Skip to content

feat(trace): auto-detect and copy optionalDependencies#35

Merged
pi0 merged 1 commit intomainfrom
feat/trace-optional
Apr 2, 2026
Merged

feat(trace): auto-detect and copy optionalDependencies#35
pi0 merged 1 commit intomainfrom
feat/trace-optional

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Apr 2, 2026

Summary

  • After tracing packages, scans each package's optionalDependencies and resolves them via exsolve
  • If the optional dep is installed but wasn't traced by @vercel/nft, full-copies all its files into the output
  • Fixes tracing for packages that dynamically load platform-specific native bindings at runtime

Fixed packages

✓ lightningcss                             4 packages
✓ @parcel/watcher                          7 packages
✓ msgpackr-extract                         4 packages
✓ @napi-rs/snappy                          5 packages
✓ cbor-extract                             4 packages
✓ lmdb                                     9 packages
✓ couchbase                                42 packages

Test plan

  • All fixed packages trace and import successfully
  • All existing tests pass (pnpm vitest run test/ — 30/30)

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced module tracing to automatically detect and register optional dependencies, improving dependency resolution accuracy and completeness.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a272ef48-639c-4b48-983c-a9a99018fb7e

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8093e and a82e8ec.

📒 Files selected for processing (1)
  • src/trace.ts

📝 Walkthrough

Walkthrough

The change extends the package tracing logic in src/trace.ts to detect and register optional dependencies of already-traced packages. For each detected package, the code resolves its optional dependencies, reads their package.json files, enumerates their directory contents (excluding node_modules paths), and registers them as fully traced package versions.

Changes

Cohort / File(s) Summary
Optional Dependency Tracing
src/trace.ts
Extended traceNodeModules to iterate over detected packages and resolve their optional dependencies. For each untraced optional dependency, the code resolves its package.json, builds a complete files list by recursively enumerating directory contents (excluding node_modules parents), and registers it as a traced package version prior to the tracedPackages hook execution.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • feat: add fullTraceInclude option #4 — Also modifies src/trace.ts to enumerate and add package files to traced package versions while excluding node_modules, sharing similar logic patterns for file enumeration and package registration.

Poem

🐰 Hop through packages, left and right,
Optional deps now traced just right,
Files enumerated, node_modules skipped with care,
Dependencies registered everywhere!
The dependency tree grows more aware. 🌳

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/trace-optional

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.11%. Comparing base (3c8093e) to head (a82e8ec).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/trace.ts 20.00% 14 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
- Coverage   76.67%   73.11%   -3.57%     
==========================================
  Files           5        5              
  Lines         373      398      +25     
  Branches      116      123       +7     
==========================================
+ Hits          286      291       +5     
- Misses         60       74      +14     
- Partials       27       33       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Platform-specific native bindings (e.g. lightningcss-linux-x64-gnu) are
listed as optionalDependencies but not traced by @vercel/nft since they
are loaded dynamically. After collecting traced packages, scan each
package's optionalDependencies and full-copy any that exist on disk.
Uses exsolve for proper module resolution instead of assuming sibling
node_modules layout.
@pi0 pi0 force-pushed the feat/trace-optional branch from 05b758d to a82e8ec Compare April 2, 2026 13:05
@pi0 pi0 marked this pull request as ready for review April 2, 2026 13:08
@pi0 pi0 merged commit 1bb2070 into main Apr 2, 2026
6 of 9 checks passed
@pi0 pi0 deleted the feat/trace-optional branch April 2, 2026 13:09
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