Skip to content
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

feat(externals): support aliasing traced packages #1553

Merged
merged 6 commits into from
Aug 8, 2023
Merged

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 8, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Normally when using the resolutions field to use an aliased package (say original name is a and aliased from npm:b), the package manager downloads b with and copies all contents into node_modules/a (while node_modules/a/package.json is package with name: b.). We use "directory" name as authentic package name to copy into .output/server/node_modules

pnpm also does this but there is a catch! the node_modules/a is a symbolic link to node_modules/.pnpm/b. When we are running external tracer, we follow the links and assume the real name is b which is wrong. To add to the complexity, rollup, mlly and nft also resolve real paths in various places so it is almost impossible to trace aliaces without manually specifying. (We might auto detect from root level package.json using resolutions and aliases)

This PR enables new externals.traceAliases option in order to speficy trace aliased packages:

export default defineNitroConfig({
  externals: {
    traceAlias: {
      "h3-nightly": "h3"
    },
  },
})

This tells nitro when tracing .output/server/h3-nightly, try to link it to .output/server/node_modules/h3.

(h3-nightly alias is added by default as a known dependency)

Isolated Preset Testing

This PR enables a new isolated way of testing presets.

Previously, we were running fixture build output within /<repo>/test/presets/.tmp/node. Even if an external like h3 is missing, tests were wrongly passed since Node.js also searches in /<repo>/node_modules. The tests are now more secure by using /tmp/nitro-test/<preset>/output.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #1553 (3d6737e) into main (de6d2d0) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1553      +/-   ##
==========================================
- Coverage   76.47%   76.43%   -0.04%     
==========================================
  Files          73       73              
  Lines        7574     7580       +6     
  Branches      750      751       +1     
==========================================
+ Hits         5792     5794       +2     
- Misses       1781     1784       +3     
- Partials        1        2       +1     
Files Changed Coverage Ξ”
src/rollup/config.ts 89.77% <100.00%> (-0.76%) ⬇️
src/rollup/plugins/externals.ts 93.29% <100.00%> (+0.02%) ⬆️

@pi0 pi0 changed the title fix(externals): handle linked (pnpm) package aliases feat(externals): support aliasing traced packages Aug 8, 2023
@pi0 pi0 marked this pull request as ready for review August 8, 2023 23:07
@pi0 pi0 merged commit 7fa8408 into main Aug 8, 2023
8 checks passed
@pi0 pi0 deleted the fix/package-alias branch August 8, 2023 23:07
@pi0 pi0 mentioned this pull request Aug 21, 2023
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