Allow for system format modules to be named. Fixes #2027 - #2028
Conversation
| const samples = path.resolve(__dirname, 'samples'); | ||
|
|
||
| const FORMATS = ['amd', 'cjs', 'es', 'iife', 'umd']; | ||
| const FORMATS = ['amd', 'cjs', 'es', 'iife', 'umd', 'system']; |
There was a problem hiding this comment.
Let me know your thoughts on this -- the vast majority of the tests do not have an _expected/system.js file defined for the "form" tests. But I'm thinking that all future tests should.
There was a problem hiding this comment.
This is included in the PR at #2022. Perhaps rebase to that if you want to do this?
| FORMATS.forEach(format => { | ||
| const skipBecauseNoSystem = format === 'system' && !fs.existsSync(path.resolve(__dirname, samples, dir, '_expected', 'system.js')) | ||
| if (skipBecauseNoSystem) { | ||
| return; |
There was a problem hiding this comment.
Don't call it() for "form" tests that don't have a system format expectation.
This prevents breaking existing tests but also providing a consistent way to add systemjs expectations in future tests.
There was a problem hiding this comment.
This can also be avoided by rebasing to the other branch.
| description: 'names bundles correctly', | ||
| options: { | ||
| output: { | ||
| name: 'libraryName', |
There was a problem hiding this comment.
Before this pr, this name was ignored in the outputted System.register format.
| @@ -0,0 +1,10 @@ | |||
| System.register('libraryName', [], function (exports, module) { | |||
There was a problem hiding this comment.
Before my pr, 'libraryName', would not have appeared in this System.register call
guybedford
left a comment
There was a problem hiding this comment.
Thanks @joeldenning for the PR! Glad to hear you're exploring these workflows :)
The general approach seems good to me, with suggestion of rebasing to the system format test PR branch.
@Rich-Harris I would be interested to hear if there was any previous discussion on using the name option to refer to AMD module naming in output, as this seems related to that.
|
Looking through the issue queue I can find nothing on named AMD defines, so assume it just hasn't been a needed use case. I take it code splitting is the feature that makes this different here really. |
|
Thanks @guybedford for the review -- I've rebased to master and have updated all the tests that previously were not naming their System.register bundles. |
lukastaegert
left a comment
There was a problem hiding this comment.
Looks good from my side as well!
|
It's worth considering here that this won't apply to the code splitting workflow very well. It might be nice to think up a solution that can work with both single-file and code splitting workflows instead of having separate mechanisms for both of these. Perhaps combining with the chunk naming feature would make more sense for code splitting integration - #1995. Just thinking aloud here though... |
|
@guybedford I'm not very familiar with rollup code splitting -- I heard it was announced pretty recently but don't know the mechanics of how it would work. How do umd and iife handle named libraries and code splitting? |
|
UMD and IIFE output formats aren't actually supported for code splitting due to the lack of easy dependency modularity. I'm making progress on the general proposal for chunk naming. When such a feature lands, I tend to think that it would be a good fit for these named format outputs, potentially through a |
|
@guybedford This PR is marked as requesting changes from you. Is this still the case or can this be merged? |
|
I still think it's worth discussing the API use cases here with regards to code splitting workflows a little further to ensure we have an approach that can work in both scenarios. The new code splitting work will allow customizing all chunk names (in progress, I'm hoping to provide a PR shortly). If this is the case, it may well provide an API that can work for this feature being just a boolean flag. In addition it may be worth making a separate top-level method for concatenation, something like Then the single-file case becomes: rollup.rollup({
// allow input object to work in single-file case for naming:
input: {
'inputName': 'input/file/path.js'
}
}).generate({
chunkNames: 'chunk-[hash].js',
format: 'system',
combineNamedModules: true
});Which would output a single source containing edit: This is kinda combining the code splitting and single-file workflows a bit... exact form still to be sketched out! |
|
Ok, so I'll leave this out of the current release. |
|
@guybedford since it sounds like code splitting is potentially going to be overhauled in the near future, would it make sense to address this problem at that time? The Getting named system register modules at all would be cool -- I vote for merging this in and then iterating on it once the code splits / combineNamedModules discussions are fleshed out. |
|
@joeldenning I'm aiming to get a PR for chunk naming very soon... once that is in we can build this feature on top of that I think. |
guybedford
left a comment
There was a problem hiding this comment.
@joeldenning after thinking about this a little further I actually think this is the best approach after all.
While a combineNamedModules option could work for code splitting alongside #2068, I'm not sure how beneficial it would be since chunk names are difficult to share between builds. In addition it still doesn't handle the single-file case anyway.
So it would only be the entry points that would be usefully shared... and running separate / multiple builds is likely a better technique here.
If you'd like to rebase this work I think it would be good to merge!
|
I just noticed there is actually an |
| `\n${t}${varOrConst} _starExcludes = { ${Array.from(starExcludes).join(': 1, ')}${starExcludes.size ? ': 1' : ''} };`; | ||
|
|
||
| const importBindingsSection = importBindings.length ? `\n${t}var ${importBindings.join(', ')};` : ''; | ||
| const registeredName = outputOptions.name ? `'${outputOptions.name}', ` : ''; |
There was a problem hiding this comment.
Looking through rollup's documentation, I think using name here is an abuse of this option which is meant to define global variable names for IIFE/umd bundles (maybe we want to add SystemJS to our umd output at some point?). As @guybedford pointed out, the amd.id option would be more equivalent except for the amd part of the name. So I would prefer deprecating amd.id in favour of a new output option. Not sure what the best name could be; we could call it something like moduleId as it is the id of the generated module as used by the loader. Maybe @guybedford has a more elaborate opinion on this.
|
Yup, we'd need to avoid the name overload. |
|
@lukastaegert @guybedford I started work on switching over to Maybe Also, would you like me to deprecate |
|
It seems At the time, AMD was the only module format with a moduleId, so I see the reasoning, but perhaps now with both AMD and System formats, it would be worth reconsidering this. If we do undeprecate moduleId, then we should ensure that we provide warnings when moduleId is used with a format that is not AMD or System. Personally I'd be for deprecating |
|
What's the status here? |
|
Looking forward for this PR to be merged when ready. Can you guys be so kind to update us with a status? |
|
I think the only reason this has remained unmerged was the choice of option name. But I guess using |
|
Sorry for the long wait! |
|
Will be a few days until we do another release, though. |
|
🕺 Better late than never! Thanks for the update. |
See #2027. This makes it possible to create named System.register bundles