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(rollup): simplify external #80

Merged
merged 1 commit into from
Dec 13, 2018
Merged

feat(rollup): simplify external #80

merged 1 commit into from
Dec 13, 2018

Conversation

kentcdodds
Copy link
Owner

What: basically this: Unless you're bundling a umd file, all files in node_modules should be marked as external. That's what this code does.

Why: I noticed that when I upgraded to emotion 10 in one of my packages and started using the babel plugin it swapped @emotion/styled for @emotion/styled-base which is not marked as an external with this logic and it kinda messed things up. So I improved the external to be what I think is intended.

How: the predicate function is called with the same module multiple times which is what made this more tricky than I thought. First it's called with the module id as it appears in the code, then it's called with the full path to the module.

Checklist:

  • Documentation N/A
  • Tests N/A
  • Ready to be merged
  • Added myself to contributors table N/A

I'd love some input from everyone who's touched the rollup config here. @Andarist, @alexandernanberg, @eliperkins, and @fobbyal. I think this is good, but it'd be nice to get a sanity check. Thanks!

I noticed that when I upgraded to emotion 10 in one of my packages and started using the babel plugin it swapped `@emotion/styled` for `@emotion/styled-base` which is not marked as an external with this logic and it kinda messed things up. So I improved the external to be what I think is intended.
@codecov
Copy link

codecov bot commented Dec 11, 2018

Codecov Report

Merging #80 into master will decrease coverage by 1.2%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #80      +/-   ##
==========================================
- Coverage   71.95%   70.75%   -1.21%     
==========================================
  Files          21       21              
  Lines         378      383       +5     
  Branches       84       85       +1     
==========================================
- Hits          272      271       -1     
- Misses         84       88       +4     
- Partials       22       24       +2
Impacted Files Coverage Δ
src/config/rollup.config.js 71.42% <0%> (-7.04%) ⬇️

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 5d99117...716ef49. Read the comment docs.

@weyert
Copy link
Contributor

weyert commented Dec 12, 2018

I will try it out. Somehow this sounds related with the issue I was having earlier this week. Thanks @kentcdodds

}
// for esm/cjs we want to make all node_modules external
// TODO: support bundledDependencies if someone needs it ever...
const isNodeModule = id.includes('node_modules')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd make it more strict with RegExp /\/node_modules\//, u'd have to check if id is normalized here, if not u'd have to construct the regexp based on path.sep (to support windows)

// TODO: support bundledDependencies if someone needs it ever...
const isNodeModule = id.includes('node_modules')
const isRelative = id.startsWith('.')
return isDep || (!isRelative && !path.isAbsolute(id)) || isNodeModule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(!isRelative && !path.isAbsolute(id))

what cases are covered by this which are not covered by isDep || isNodeModule?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's strange, but this would be called with '@emotion/styled-base' (not listed as a dep because it's added via a babel plugin). So I also need to factor in whether it's relative.

But I can't JUST do relative either because for each mistake it's called with both the source string id and the full path to the resolved module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but arent full paths already covered (kinda) by isNodeModule check?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full paths are, but not non-relative paths. It's weird I know, but I spent a few hours on this in a project that uses a similar config (paypal-scripts) and this was the only way I found to fix it 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, maybe its brain fart but I still dont get it 😅 non-relative paths can be either:

  • package name
  • absolute path (which should include node_modules)
  • alias (which is not covered, and arguably cant be, here)

am i missing something? 🤔

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kinda hard to explain. All I can say is that if I didn't have the relative and absolute logic in here, then weird things would happen :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldnt hurt, so im not opposed to it, was rather just curious why this is needed

APPROVED! 👍

@kentcdodds kentcdodds merged commit ad1826e into master Dec 13, 2018
@kentcdodds
Copy link
Owner Author

Thanks friends!

@kentcdodds kentcdodds deleted the pr/improve-external branch December 13, 2018 14:27
@kentcdodds
Copy link
Owner Author

🎉 This PR is included in version 0.49.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants