Skip to content

Allow for system format modules to be named. Fixes #2027 - #2028

Merged
lukastaegert merged 3 commits into
rollup:masterfrom
internettrans:named-system
May 20, 2018
Merged

Allow for system format modules to be named. Fixes #2027#2028
lukastaegert merged 3 commits into
rollup:masterfrom
internettrans:named-system

Conversation

@internettrans

Copy link
Copy Markdown

See #2027. This makes it possible to create named System.register bundles

Comment thread test/form/index.js Outdated
const samples = path.resolve(__dirname, 'samples');

const FORMATS = ['amd', 'cjs', 'es', 'iife', 'umd'];
const FORMATS = ['amd', 'cjs', 'es', 'iife', 'umd', 'system'];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is included in the PR at #2022. Perhaps rebase to that if you want to do this?

Comment thread test/form/index.js Outdated
FORMATS.forEach(format => {
const skipBecauseNoSystem = format === 'system' && !fs.existsSync(path.resolve(__dirname, samples, dir, '_expected', 'system.js'))
if (skipBecauseNoSystem) {
return;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can also be avoided by rebasing to the other branch.

description: 'names bundles correctly',
options: {
output: {
name: 'libraryName',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Before this pr, this name was ignored in the outputted System.register format.

@@ -0,0 +1,10 @@
System.register('libraryName', [], function (exports, module) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Before my pr, 'libraryName', would not have appeared in this System.register call

@guybedford guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@guybedford

Copy link
Copy Markdown
Contributor

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.

@internettrans

Copy link
Copy Markdown
Author

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 lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good from my side as well!

@lukastaegert lukastaegert added this to the 0.57.0 milestone Mar 6, 2018
@guybedford

Copy link
Copy Markdown
Contributor

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...

@internettrans

Copy link
Copy Markdown
Author

@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?

@guybedford

Copy link
Copy Markdown
Contributor

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 namedModules: true or similar boolean flag.

@lukastaegert lukastaegert removed this from the 0.57.0 milestone Mar 12, 2018
@lukastaegert

Copy link
Copy Markdown
Member

@guybedford This PR is marked as requesting changes from you. Is this still the case or can this be merged?

@lukastaegert lukastaegert added this to the 0.57.0 milestone Mar 14, 2018
@guybedford

guybedford commented Mar 14, 2018

Copy link
Copy Markdown
Contributor

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 generateCombined which only works for the system and amd formats (and in future if ES modules support named wrappers).

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 System.register('inputName', [',/chunk-asdf897.js'], ...); System.register(',/chunk-asdf897.js', [], ...).

edit: This is kinda combining the code splitting and single-file workflows a bit... exact form still to be sketched out!

@lukastaegert

Copy link
Copy Markdown
Member

Ok, so I'll leave this out of the current release.

@lukastaegert lukastaegert removed this from the 0.57.0 milestone Mar 14, 2018
@internettrans

Copy link
Copy Markdown
Author

@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 combineNamedModules option seems really cool (and relevant to #2036!), but it seems like there is some discussion and work to be done to decide if it will even happen.

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.

@guybedford

Copy link
Copy Markdown
Contributor

@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 guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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!

@guybedford

guybedford commented Mar 21, 2018

Copy link
Copy Markdown
Contributor

I just noticed there is actually an amd.id output option. It's probably worth ensuring that whatever is done here either deprecates that or works with it then.

Comment thread src/finalisers/system.ts
`\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}', ` : '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@guybedford

Copy link
Copy Markdown
Contributor

Yup, we'd need to avoid the name overload. moduleId as a new option to replace amd.id sounds really sensible to me actually, with it only supported in the non-code-splitting build. For the code splitting case, moduleId: true could possibly be an option as well I guess.

@internettrans

Copy link
Copy Markdown
Author

@lukastaegert @guybedford I started work on switching over to moduleId instead of name, but discovered that moduleId is already a rollup output option that means something else. On top of that, it's a deprecated option, so I'm not sure if we would want to piggy back on it.

Maybe moduleName?

Also, would you like me to deprecate amd.id in favor of the new property? I think I know how to do so in the amd finalizer, but might need some help hunting down all the places where deprecation warnings are supposed to happen / documentation needs to be updated.

@guybedford

Copy link
Copy Markdown
Contributor

It seems moduleId was exactly for this purpose but deprecated in 979b5e4.

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 amd.id for going back to moduleId, but open to suggestions. @Rich-Harris @lukastaegert what do you think?

@kerwitz

kerwitz commented May 17, 2018

Copy link
Copy Markdown

What's the status here?

@CoskunSunali

Copy link
Copy Markdown

Looking forward for this PR to be merged when ready. Can you guys be so kind to update us with a status?

@lukastaegert

Copy link
Copy Markdown
Member

I think the only reason this has remained unmerged was the choice of option name. But I guess using name here should be ok so I'll merge this now.

@lukastaegert

Copy link
Copy Markdown
Member

Sorry for the long wait!

@lukastaegert

Copy link
Copy Markdown
Member

Will be a few days until we do another release, though.

@lukastaegert
lukastaegert merged commit e7354bf into rollup:master May 20, 2018
@lukastaegert lukastaegert modified the milestones: 0.59., 0.60.0 May 20, 2018
@CoskunSunali

Copy link
Copy Markdown

🕺 Better late than never!

Thanks for the update.

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.

5 participants