Skip to content

feat(pluginutils): add native node es modules support#419

Merged
shellscape merged 4 commits intomasterfrom
pluginutils-mjs
Jun 1, 2020
Merged

feat(pluginutils): add native node es modules support#419
shellscape merged 4 commits intomasterfrom
pluginutils-mjs

Conversation

@TrySound
Copy link
Copy Markdown
Member

@TrySound TrySound commented May 26, 2020

Rollup Plugin Name: pluginutils

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

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

List any relevant issue numbers:

Description

Enable native node es modules via "exports" field in package.json.
Added custom plugin to generate nested package.json with {"type": "module"}
as an alternative to mjs extension usage. This works similar to rollup distribution.
https://unpkg.com/browse/[email protected]/dist/es/

This change is necessary before migrating all other plugins.

Ref #412 #413

Enable native node es modules via "exports" field in package.json.
Added custom plugin to generate nested package.json with `{"type": "module"}`
to prevent mjs extension usage.

import pkg from './package.json';

function emitModulePackageFile() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TrySound added a commit to TrySound/estree-walker that referenced this pull request May 26, 2020
A blocker for rollup/plugins#419

emitModulePackageFile is used to avoid .mjs extension.
@TrySound
Copy link
Copy Markdown
Member Author

Looks like there is a blocker
Rich-Harris/estree-walker#23

@TrySound
Copy link
Copy Markdown
Member Author

@shellscape Bundling estree-walker would eliminate the problem. What do you think?

@shellscape
Copy link
Copy Markdown
Collaborator

@TrySound it's got a pretty small bundle footprint of 2.9kb raw. That should be fine.

@TrySound TrySound requested a review from lukastaegert May 27, 2020 15:24
Comment on lines +78 to +82
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/es/index.js"
},
"module": "./dist/es/index.js",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question about the choice to nest these within a directory: our prior file format was index.[format].[extension] for output files. e.g. index.es.js. what's the reasoning behind the choice to put them into directories?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

es/package.json with {type:module}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As an alternative to .mjs extension.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OK. Can you explain in the PR description why we need mjs alternative? I've added a bunch more people to review. We're going to need to get majority buy-in to move forward with this since it's a pretty big paradigm shift.

@danielgindi
Copy link
Copy Markdown
Contributor

@TrySound can you please explain why we need to shift from mjs?

@TrySound
Copy link
Copy Markdown
Member Author

I just don't like it. And to be consistent with rollup. So no strong opinion.

@shellscape
Copy link
Copy Markdown
Collaborator

And to be consistent with Rollup

That seems the most compelling reason. I really don't like how it litters dist but if that stops the complaining about Node 14+ imports then I guess that's what we do.

If we're going to adopt this, we should also revisit comments by @Andarist where dist files were named pluginutils.js instead of index.js, as that would also follow parent Rollup's convention.

@shellscape
Copy link
Copy Markdown
Collaborator

I'll be following up with a PR to address the comment from above:

If we're going to adopt this, we should also revisit comments by @Andarist where dist files were named pluginutils.js instead of index.js, as that would also follow parent Rollup's convention.

@shellscape shellscape merged commit c599182 into master Jun 1, 2020
@shellscape shellscape deleted the pluginutils-mjs branch June 1, 2020 14:03
LarsDenBakker pushed a commit to LarsDenBakker/plugins that referenced this pull request Sep 12, 2020
* feat(pluginutils): add native node es modules support

Ref rollup#412 rollup#413

Enable native node es modules via "exports" field in package.json.
Added custom plugin to generate nested package.json with `{"type": "module"}`
to prevent mjs extension usage.

* Export emitModulePackageFile from shared config

* Bundle estree-walker

* Swap options
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.

6 participants