Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

es2015-in-modules support, useful for Angular (and more) - #85

Closed
kylecordes wants to merge 5 commits into
rollup:masterfrom
OasisDigital:fields2
Closed

kylecordes wants to merge 5 commits into
rollup:masterfrom
OasisDigital:fields2

Conversation

@kylecordes

Copy link
Copy Markdown

Update dependencies so it will build/test on Node 7.

Lint cleanup

Refactor to make it easier to change the list/order of "what kind of module do you want?"

Add support for options.es2015, which is a hopefully-emerging way to say "here is es2015 code in es2015 modules". This is the format for optimal downstream tree-shaking etc with rollup and similar tools.

Useful now, to start working with Angular 4 rc.1 sitting there with es2015-code-in-es2015-modules code shipping.

Kyle Cordes added 4 commits February 26, 2017 22:20
Update various dependencies - avoid errors with Node 7, keep up with the ecosystem.
The code appeared to follow the syntax rule in most cases; add it to the lintrc and follow it throughout.
(as used in recent packages includes Angular - perhaps on the way to broader use)
@kylecordes

Copy link
Copy Markdown
Author

Travis doesn't build node 0.12 anymore, but also doesn't have node 7 ready yet.

@kylecordes

Copy link
Copy Markdown
Author

@Rich-Harris What do you think of this? Could it be merged?

@Rich-Harris

Copy link
Copy Markdown
Contributor

Thanks for the PR. Is anybody doing this (pkg.es2015) except Angular? Am always hesitant to add something in that isn't a standard or a community convention, however small it might seem, because it can create confusion, fragmentation and technical debt. Would it make more sense for Angular to have its own dedicated resolver plugin if it's adopting idiosyncratic conventions?

@kylecordes

Copy link
Copy Markdown
Author

There is discussion over at RxJS of shipping ES2015-in-ES2015 modules, and I suspect that if that happens they will use the same es2015 field to point to them. I have not seen any alternatives proposed for a field for this purpose, and given the benefits of ES2015-in-ES2015 modules I hope we see adoption escalate. So this perhaps a nascent community convention?

To keep the number of different plug-ins a person must find down, I thought about not adding an explicit es2015 flag, rather having the user configure an array of keys they would like searched in what order. A user could specify packageMainField: ['es2015', 'module', 'main'] or whatever other subset, combination, or order they need. I think the Webpack equivalent to rollup-plugin-node-resolve does something like this.

Downside:

  • User would have to understand what those options are and in what order it is most wise to prefer them. It seems ideally best to have the tooling know the right thing and do it.

Upsides:

  • As various package authors create their own new conventions, they can be met without any further edits to rollup-plugin-node-resolve.
  • There is at least one other open issue about what order the fields should be searched and, in such a design would solve that one also.

I'm happy to go any of these directions though. Keep it as it is here? Publish this instead as rollup-plugin-node-resolve-es2015? Switch to the packageMainField array idea?

@TrySound

TrySound commented Mar 9, 2017

Copy link
Copy Markdown
Member

I think we should do the same as webpack and add customizable entry points.

@Rich-Harris

Copy link
Copy Markdown
Contributor

As various package authors create their own new conventions

This is the nub of the issue — I would consider that a downside, not an upside! The thing is, I've seen how this story ends — with lots of confusion over which thing does what, and what practices should be considered 'best'. I believe that things like es2015 should be discouraged (given that it's nowhere close to being a standard, unlike module which has advocates on TC39, it should at the very least be renamed to something that's guaranteed to never conflict with anything, like jsnext:main was before module), and 'official' plugins like this one have a role to play in setting those community conventions and expectations.

But the plugin API was designed to give this sort of freedom to people who need it, so to that end I think this would be best done as a separate Angular/RxJS-specific plugin. If it does end up being adopted more widely, it would be appropriate to revisit this.

Hope that explains my stance, and that this doesn't just come across as me being awkward! 😀

@kylecordes

Copy link
Copy Markdown
Author

Rich - got it, the plan is to make es2015 available on a secondary plugin, and reserve this primary plugin for the NPM package features that are either already official or have wide community support.

In keeping with that, I think it's better to meet this (temporary?) pkg:es2015 need with a plugin that can be configured to grab pkg:es2016, rather than one that has pkg:es2015 on its feature list per se. I'm thinking of a name like rollup-plugin-node-resolve-adhoc. Or -experimental.

Where should such a plugin exist?

  • I could publish it to NPM on my own - but then Angular people are going to keep coming here looking for es2015 support.
  • I could make it then transfer the repo to you, in the rollup org, you could own and publish it to NPM.

@kylecordes

Copy link
Copy Markdown
Author

(Actually, naming it -angular might help discoverability.)

@Rich-Harris

Copy link
Copy Markdown
Contributor

Yeah, calling it something with angular seems like a good option. I think it's fine to have it outside the Rollup org, I don't reckon people will struggle to find it — we can include it on the wiki etc.

@kylecordes

kylecordes commented Mar 16, 2017 •

Copy link
Copy Markdown
Author

I have published it, with the -angular name as @Rich-Harris recommended:

https://www.npmjs.com/package/rollup-plugin-node-resolve-angular

I linked it in the Wiki:

https://github.com/rollup/rollup/wiki/Plugins

(I'll close this PR, since things are likely to change in various chaotic ways between now and when a way of saying es2015-in-es2015 is settled as official.)

@kylecordes kylecordes closed this Mar 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants