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

Properly handle upper directories as external dependencies #4419

Merged
merged 7 commits into from Mar 2, 2022

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
Resolves #4349

Description

There is a logic in Rollup that prevents using .. or . to import a chunk that corresponds to a parent directory of another chunk. While this makes sense for chunks, it fails for external dependencies, resulting in #4349.
This PR does two things:

  • If a relative external dependency is a parent directory of a chunk, it WILL be rendered as ., .., ../.. etc. I know this might be controversial as this is "correct" in CommonJS but not supported in true ESM engines. Feedback welcome. The alternative would be to add even more ../ to the import, i.e. .. might become ../../foo. This would also add the parent directory name to the import, which may actually not be what is intended if the original external import was ...
  • The logic for chunks now works correctly for ../.. as well (and directories even further up).

@github-actions
Copy link

github-actions bot commented Feb 26, 2022

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-4349-unexpected-upper-dirs

or load it into the REPL:
https://rollupjs.org/repl/?pr=4419

@codecov
Copy link

codecov bot commented Feb 26, 2022

Codecov Report

Merging #4419 (1545e0b) into master (b74cb92) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4419   +/-   ##
=======================================
  Coverage   98.75%   98.75%           
=======================================
  Files         204      204           
  Lines        7306     7308    +2     
  Branches     2079     2080    +1     
=======================================
+ Hits         7215     7217    +2     
  Misses         33       33           
  Partials       58       58           
Impacted Files Coverage Δ
src/ExternalModule.ts 100.00% <ø> (ø)
src/Chunk.ts 100.00% <100.00%> (ø)
src/utils/path.ts 100.00% <100.00%> (ø)
src/utils/relativeId.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b74cb92...1545e0b. Read the comment docs.

@lukastaegert lukastaegert force-pushed the gh-4349-unexpected-upper-dirs branch 2 times, most recently from 69cfd44 to 1e647a2 Compare March 2, 2022 06:45
@lukastaegert lukastaegert force-pushed the gh-4349-unexpected-upper-dirs branch from 1e647a2 to 9585dc4 Compare March 2, 2022 06:50
@lukastaegert lukastaegert merged commit 0b60dd8 into master Mar 2, 2022
@lukastaegert lukastaegert deleted the gh-4349-unexpected-upper-dirs branch March 2, 2022 12:58
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.

Rollup adds two upper dirs in the output
1 participant