Skip to content

feat: return traced output layout and hoist rootDir-resolvable version - #76

Merged
pi0 merged 2 commits into
mainfrom
feat/traced-layout
Oct 6, 2026
Merged

pi0 merged 2 commits into
mainfrom
feat/traced-layout

Conversation

@pi0x

@pi0x pi0x commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Context: nitrojs/nitro#4731. Bundled code can import two versions of the same external package, for example app code using root [email protected] and a bundled workspace package using its nested [email protected]. Neither version has a traced parent, so nf3 always hoisted the newest one. The other version was copied into .nf3/ but nothing could reach it, and callers had no way to find out where each version ended up.

Changes

  • Hoisting: when parent counts tie (including all 0), hoist the version Node resolves from rootDir (<rootDir>/node_modules/<name>, compared by version, since the same version can be installed in more than one place). Newest is now only the last fallback, and the result doesn't depend on input order.
  • Layout: traceNodeModules now returns a TracedLayout (it returned nothing before), and a new hooks.tracedLayout hook receives it once all files are written:
    • packages[name]: { name, hoisted, versions: { [v]: { path, outPath, hoisted } } }, with outPath relative to outDir (e.g. node_modules/.nf3/[email protected])
    • files: maps each input file (as passed) to its output path relative to outDir
  • writePackageJson: each dependency version is now the hoisted version. Before, it was the first version key, which could disagree with the node_modules/<name> symlink.
  • README: new "Output Layout" section.

Tests

  • New fixture: @fixture/hoist-dep 1.0.0 at the root and 2.0.0 under packages/composition/node_modules, passed only as direct inputs and tested in both orders. Checks the hoisted version, the layout and hook, files, that every reported path can be imported, and package.json.
  • The existing multi-version test now also checks the nitro-lib layout and that the nested parent node_modules symlink is still created.

🤖 Generated with AI assistant

Summary by CodeRabbit

  • New Features
    • Tracing now returns a layout showing package output locations, hoisted versions, and mappings from input files to output files.
    • A new callback lets you access the completed layout after tracing.
    • When package versions have equal dependant counts, the version resolvable from the project root is selected for hoisting.
  • Documentation
    • Added guidance on output layouts, multiple package versions, and accessing versions not available through the bare package name.

- prefer the version resolvable from rootDir when hoisting ties
- return `TracedLayout` from `traceNodeModules` and add `tracedLayout` hook
- write hoisted versions in generated package.json

ref nitrojs/nitro#4731
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0a86588-5e09-4bdf-9497-189f9c02aa95
📥 Commits

Reviewing files that changed from the base of the PR and between 1081182 and 5c10bf4.

⛔ Files ignored due to path filters (4)
  • test/fixture/node_modules/@fixture/hoist-dep/index.mjs is excluded by !**/node_modules/**
  • test/fixture/node_modules/@fixture/hoist-dep/package.json is excluded by !**/node_modules/**
  • test/fixture/packages/composition/node_modules/@fixture/hoist-dep/index.mjs is excluded by !**/node_modules/**
  • test/fixture/packages/composition/node_modules/@fixture/hoist-dep/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (6)
  • README.md
  • src/index.ts
  • src/trace.ts
  • src/types.ts
  • test/fixture/packages/composition/package.json
  • test/trace.test.ts
 ___________________________________________________________
< Finding disturbances in the code before the Jedi Masters. >
 -----------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.51%. Comparing base (1081182) to head (e160bd3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/trace.ts 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   80.70%   81.51%   +0.80%     
==========================================
  Files           5        5              
  Lines         596      622      +26     
  Branches      172      181       +9     
==========================================
+ Hits          481      507      +26     
  Misses         84       84              
  Partials       31       31              

☔ View full report in Codecov by Harness.
📢 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.

- compare root-resolvable version by version, not path (same version may be installed twice)
- relink hoisted version over a stale top-level link so it matches the layout
- resolve relative inputs against cwd (like nft) for `layout.files`
- fix windows path assertion in tests; clarify layout JSDoc
@pi0
pi0 merged commit 6fa712b into main Oct 6, 2026
8 checks passed
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.

2 participants