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!: rewrite external copy with multi version hoisting support #782

Merged
merged 38 commits into from
Jan 16, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Dec 23, 2022

Resolves #572

Based on amazing work from @mahdiboomeri (#758) this PR introduces a full rewrite of the external copy mechanism.

Previously if multiple versions of an external library were being used by traced externals, we used this strategy:

  • In case of minor version conflicts, pick the latest to use for all libs
  • In case of major version conflicts, warn and pick the latest semver-major one

This causes unresolvable issues especially when sub-dependencies are conflicting.

With this refactor, we respect hoisted structure of package manager and map it into .output/server/node_modules:

  • Create a normalized list of all traced files and their parents
  • Create a normalized list of all relevant package/versions from traced files
  • For each package
    • If there is only one traced version detected, copy it as as
    • If more than one traced version is detected, copy to node_modules/{name}@{version} and symlink to node_modules/{parent}/node_modules/{name} for each parent. If no parent modules are detected, hoist it to top level as default (user's version)

In case of having issues with new implementation in nitropack v2, you can opt to use legacy externals:

experimental: {
  // Use nitropack v1 behavior
  legacyExternals: true
}

@codecov
Copy link

codecov bot commented Dec 23, 2022

Codecov Report

Merging #782 (f1c9ce4) into main (f812c81) will decrease coverage by 3.45%.
The diff coverage is 36.83%.

❗ Current head f1c9ce4 differs from pull request most recent head 71641e0. Consider uploading reports for the commit 71641e0 to get more accurate results

@@            Coverage Diff             @@
##             main     #782      +/-   ##
==========================================
- Coverage   70.63%   67.17%   -3.46%     
==========================================
  Files          57       58       +1     
  Lines        5299     5716     +417     
  Branches      607      605       -2     
==========================================
+ Hits         3743     3840      +97     
- Misses       1549     1869     +320     
  Partials        7        7              
Impacted Files Coverage Δ
src/rollup/plugins/externals-legacy.ts 6.80% <6.80%> (ø)
src/rollup/config.ts 92.12% <80.00%> (-0.17%) ⬇️
src/rollup/plugins/externals.ts 94.90% <98.13%> (-0.07%) ⬇️
src/types/nitro.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mahdiboomeri
Copy link
Contributor

@pi0 I added the options as a workaround if they were some edge cases that weren't covered (such as a package that doesn't follow semver), but IMO the new approach seems reliable enough to skip that.

@itpropro
Copy link
Contributor

itpropro commented Jan 7, 2023

Any updates for this @pi0 ?

@pi0 pi0 marked this pull request as ready for review January 16, 2023 12:52
@pi0
Copy link
Member Author

pi0 commented Jan 16, 2023

Updated implementation with parent-level hosting for nested support, windows support using junctions (not portable), and alias support.

Although new implementation should be much better for handling hoisting situations and allow better enhancements using new clearer data-structures, it can be buggy without testing on real-world installs. So let's get it a spin.

Also there is new experimental.legacyExternals flag to allows an escape hatch to use v1 behavior.

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.

Issues with flatten extrernals tracing and multiple versions
3 participants