Add esm format alias - #2102
Conversation
guybedford
left a comment
There was a problem hiding this comment.
Thanks for getting to this, have been meaning to myself.
I guess we should decide if we want to make esm the main form and deprecate es or just allow it as an alias.
Perhaps just treating it as an alias for now, to avoid documentation changes etc might be simpler, but I'm open to considering the more major deprecation path - although will likely need further feedback from @Rich-Harris and @lukastaegert on this.
| if (!options.format) { | ||
| error({ | ||
| message: `You must specify options.format, which can be one of 'amd', 'cjs', 'system', 'es', 'iife' or 'umd'`, | ||
| message: `You must specify options.format, which can be one of 'amd', 'cjs', 'system', 'esm', 'iife' or 'umd'`, |
There was a problem hiding this comment.
If we do this, we should work on a documentation change as well.
There was a problem hiding this comment.
Although for now, I'm thinking it might just be better to treat esm as an alias, with es remaining the primary term - moving to consider this being changed in future?
| @@ -229,7 +229,7 @@ function checkOutputOptions(options: OutputOptions) { | |||
|
|
|||
| if (!options.format) { | |||
There was a problem hiding this comment.
An alternative here might be to do if (options.format === 'es') options.format = 'esm'; to avoid the need to do both checks through the codebase.
There was a problem hiding this comment.
I guess this merge should happen in mergeOptions?
There was a problem hiding this comment.
This could work, but there is an issue, what we should pass to transformBundle(code, { format })?
There was a problem hiding this comment.
It would be a breaking change to alter - so keeping es internally and esm as an alias is probably the best bet.
|
|
||
| private prepareDynamicImports({ format }: OutputOptions) { | ||
| const es = format === 'es'; | ||
| const esm = format === 'esm' || format === 'es'; |
There was a problem hiding this comment.
Ideally all these checks should only check one format string - either esm or es, with internal rewriting to ensure only one is used.
af21c79 to
eec7c39
Compare
|
Added tests for esm with a couple of hacks to reuse es expected |
|
I'd be pro-deprecating |
|
We can then merge this pr with an alias to give users time to migrate then add deprecation. |
|
I would prefer |
|
I can coordinate this breaking change through all of these modules. |
guybedford
left a comment
There was a problem hiding this comment.
Looks great to me, just a question re possible duplication in the tests.
| const samples = path.resolve(__dirname, 'samples'); | ||
|
|
||
| const FORMATS = ['amd', 'cjs', 'system', 'es', 'iife', 'umd']; | ||
| const FORMATS = ['amd', 'cjs', 'system', 'es', 'esm', 'iife', 'umd']; |
There was a problem hiding this comment.
Did you mean to include both es and esm here or just use esm?
There was a problem hiding this comment.
Both. Esm is an alias which we also should test
There was a problem hiding this comment.
Yes, but it will slow down the tests if we're rerunning each and every es module format test twice now. Perhaps just one test is necessary.
| const samples = path.resolve(__dirname, 'samples'); | ||
|
|
||
| const FORMATS = ['es', 'cjs', 'amd', 'system']; | ||
| const FORMATS = ['es', 'esm', 'cjs', 'amd', 'system']; |
There was a problem hiding this comment.
We are gonna support both for now
| if (!options.format) { | ||
| error({ | ||
| message: `You must specify options.format, which can be one of 'amd', 'cjs', 'system', 'es', 'iife' or 'umd'`, | ||
| message: `You must specify options.format, which can be one of 'amd', 'cjs', 'system', 'esm', 'es', 'iife' or 'umd'`, |
There was a problem hiding this comment.
Shall we already move to only documenting esm perhaps as a first step towards deprecation?
|
Could you rebase this for merge? Otherwise I can aim to take a look. Sorry this one dropped off my radar, would be great to get it in. |
2e67202 to
1958970
Compare
|
Done |
|
Amazing, thanks for the update here. We should be able to switch around the |
|
The generateBundle hook in rollup version 1.16 still gives me "es" instead of "esm" in outputOptions.format. In my rollup config, I have "esm". Does this mean, the breaking change did not happen in 1.x? |
|
@stefanocke Yes, breaking change did not happen before 1.0. esm is only alias for now. We may reconsider this later. |
|
@TrySound , thanks for clarification. |
Ref #1917
Added
esmas an alias to be compatible in naming with esm loader.Also since it's more descriptive renamed a few variables too.
Should I add format for every form in tests?