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(node-resolve): Mark built-ins as external #627

Merged
merged 20 commits into from Nov 28, 2020

Conversation

tjenkinson
Copy link
Member

@tjenkinson tjenkinson commented Nov 1, 2020

Rollup Plugin Name: node-resolve

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (updated)
  • no

Breaking Changes?

Not sure on this given previously it was a warning. It would have allowed other plugins to jump in though so maybe it should be 'yes'?

  • yes
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

Description

This continues from #564.

I thought that if useBuiltins was true then any builtins would automatically be marked as external. This was not the case. This PR does that. Let me know if you think it doesn't make sense.

It also makes some of the docs a bit more accurate.

It seems a bit strange that some options (like jail) don't mark an import as external, but others (like resolveOnly and now preferBuiltins) do. I wonder if there is a reason or if we should make them consistent?

There is one commit that updates all the snapshots as I noticed when updating the ones for the tests I updated it changed them all because the ava domain in the comment changed.

@tjenkinson tjenkinson marked this pull request as ready for review November 1, 2020 10:32
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks good so far, would like some clarification about the default behaviour


If `true`, the plugin will prefer built-in modules (e.g. `fs`, `path`). If `false`, the plugin will look for locally installed modules of the same name.

If unset the plugin will first look for modules of the same name, and then fall back to built-in modules.
Copy link
Member

Choose a reason for hiding this comment

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

If we keep the warning about unset that still appears to be in the code, I guess this should be mentioned here, otherwise people think they can get away with not configuring this option when they use imports like fs. Alternatively, we could allow this as a valid "third" option, e.g. "auto", where you want to override some builtins with local alternatives but keep others. But I am not sure I can imagine a scenario where people would want this.

Copy link
Member Author

Choose a reason for hiding this comment

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

The plugin behaves a bit differently when it's unset. I was confused by this because I though it would default to either the true or false behaviour, but it's essentially a third option, so this was to try and make that clear.

The way these 2 variables are used makes the third behaviour

  const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;

I'd be happy for it to be an explicit option. Are you suggesting that unset should become auto? or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the code again now I'm not actually sure if the line I added here is correct. It's quite confusing to follow through the logic

Copy link
Member

Choose a reason for hiding this comment

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

Your example looks very much like the default for preferBuiltins would be true, just with a warning about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeh removing this comment. Opened another PR to simplify how we handle preferBuiltins a bit

#637

@shellscape shellscape changed the title feat(node-resolve) Mark built-ins as external feat(node-resolve): Mark built-ins as external Nov 2, 2020
@shellscape
Copy link
Collaborator

Thanks for the PR. It looks like there are some tests breaking in CI that will need to be addressed, and we'll need to know if these changes proposed will be breaking changes for users (you didn't select an option in the template)

@tjenkinson
Copy link
Member Author

It looks like there are some tests breaking in CI that will need to be addressed

It looks like this was just a failure to update coverage info? A rerun might fix that.

and we'll need to know if these changes proposed will be breaking changes for users

Yeh I wasn't 100% on this so I left a comment above the check boxes. I guess if we're unsure it's probably safest to go with 'yes'

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks good to me, looking forward to this one. I would still treat it as a breaking change, though, due to the changed default behaviour, even though it is likely a change very much in the user's interest.

@tjenkinson
Copy link
Member Author

I have some more changes coming up in a different PR that would need to be major, so if you would prefer to release as few major bumps as possible, it might be best to wait a few days for that PR too.

@tjenkinson
Copy link
Member Author

Here's the other PR which would need to be major: #656

@shellscape
Copy link
Collaborator

thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants