Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: library target UMD supports names per target #4883

Merged

Conversation

AndersDJohnson
Copy link
Contributor

@AndersDJohnson AndersDJohnson commented May 17, 2017

What kind of change does this PR introduce?

feature

Did you add tests for your changes?

Yes, I updated the tests for LibraryTemplatePlugin. There didn't seem to be any for UmdMainTemplatePlugin yet - not sure if that's intentional, but if not, I could look into adding.

If relevant, link to documentation update:

I'll take the time to add documentation after getting approval for this feature.

Summary

Currently, the output.libraryTarget of 'umd' only supports a single name (output.library), whereas the user may instead wish to specify a different name for each target type (CommonJS, AMD, and global), e.g., to use kebab-case for AMD and CommonJS but camelCase for global.

Does this PR introduce a breaking change?

No.

Other information

Feel free to ask.

@jsf-clabot
Copy link

jsf-clabot commented May 17, 2017

CLA assistant check
All committers have signed the CLA.

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

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

A testcase in test/configCases would be great too to test the configuration schema

@@ -163,12 +173,12 @@ class UmdMainTemplatePlugin {
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
}.bind(this));
mainTemplate.plugin("global-hash-paths", function(paths) {
if(this.name) paths = paths.concat(this.name);
if(this.names.root) paths = paths.concat(this.names.root);
Copy link
Member

Choose a reason for hiding this comment

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

Could you add all names here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Is it okay if names are repeated in paths, or do we need to dedupe first?

Copy link
Member

Choose a reason for hiding this comment

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

That's ok. They should just contribute all to the hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Again here, the paths have been added for all names.

return paths;
}.bind(this));
mainTemplate.plugin("hash", function(hash) {
hash.update("umd");
hash.update(`${this.name}`);
hash.update(`${this.names.root}`);
Copy link
Member

Choose a reason for hiding this comment

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

here also all names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Again, is it okay if names are repeated here, or do we need to dedupe first?

Copy link
Member

Choose a reason for hiding this comment

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

yep, it's ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra The hash has been updated with all names.

@@ -0,0 +1 @@
original
Copy link
Member

Choose a reason for hiding this comment

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

these files should not be commited (temp)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Oops, thanks. Any reason not to add a pattern to .gitignore for these? As well as test/statsCases/*/actual.txt?

if(typeof name === "object" && !Array.isArray(name)) {
this.name = name.root || name.amd || name.commonjs;
this.names = name;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

does the schema allow an object as output.libraryName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Good point. Updated schema and added test.

(this.name && this.namedDefine === true ?
" define(" + libraryName(this.name) + ", [], " + amdFactory + ");\n" :
(this.names.amd && this.namedDefine === true ?
" define(" + libraryName(this.names.amd) + ", [], " + amdFactory + ");\n" :
Copy link
Member

Choose a reason for hiding this comment

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

this line is not tested, if you want to you can add a test, but it's not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Thanks, I've added tests for namedDefine being true and false. I'm not sure why it was a string value before, as I'm not sure that's a valid value per the docs - I'd only copied that from other test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sokra Not sure how to get that line covered. Looks like it wasn't before either, and this PR now improves coverage overall. https://codecov.io/gh/webpack/webpack/pull/4883/changes

@webpack-bot
Copy link
Contributor

@AndersDJohnson Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@AndersDJohnson AndersDJohnson force-pushed the library-target-umd-names-per-target branch from 5e8dcd6 to d87fb0e Compare May 29, 2017 18:49
@webpack-bot
Copy link
Contributor

It looks like this Pull Request doesn't include enough test cases (based on Code Coverage analysis of the PR diff).

A PR need to be covered by tests if you add a new feature (we want to make sure that your feature is working) or if you fix a bug (we want to make sure that we don't run into a regression in future).

@AndersDJohnson Please check if this is appliable to your PR and if you can add more test cases.

Read the test readme for details how to write test cases.

@@ -163,12 +173,12 @@ class UmdMainTemplatePlugin {
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
}.bind(this));
mainTemplate.plugin("global-hash-paths", function(paths) {
if(this.name) paths = paths.concat(this.name);
if(this.names.root) paths = paths.concat(this.names.root);
Copy link
Member

Choose a reason for hiding this comment

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

That's ok. They should just contribute all to the hash.

return paths;
}.bind(this));
mainTemplate.plugin("hash", function(hash) {
hash.update("umd");
hash.update(`${this.name}`);
hash.update(`${this.names.root}`);
Copy link
Member

Choose a reason for hiding this comment

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

yep, it's ok

@sokra
Copy link
Member

sokra commented May 31, 2017

Could you sign the CLA, so we can merge it?

@AndersDJohnson
Copy link
Contributor Author

@sokra CLA has been signed.

@sokra sokra merged commit 3e3b748 into webpack:master Jun 21, 2017
@AndersDJohnson
Copy link
Contributor Author

@sokra Thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants