Skip to content

feat: library target UMD supports names per target - #4883

Merged
sokra merged 5 commits into
webpack:masterfrom
AndersDJohnson:library-target-umd-names-per-target
Jun 21, 2017
Merged

sokra merged 5 commits into
webpack:masterfrom
AndersDJohnson:library-target-umd-names-per-target

Conversation

@AndersDJohnson

@AndersDJohnson AndersDJohnson commented May 17, 2017

Copy link
Copy Markdown
Contributor

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

jsf-clabot commented May 17, 2017

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@webpack-bot

Copy link
Copy Markdown
Contributor

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

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

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

}.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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

mainTemplate.plugin("hash", function(hash) {
hash.update("umd");
hash.update(`${this.name}`);
hash.update(`${this.names.root}`);

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.

here also all names

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread test/fixtures/temp-1000/file2.js Outdated
@@ -0,0 +1 @@
original No newline at end of file

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.

these files should not be commited (temp)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

}.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
Copy Markdown
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.

mainTemplate.plugin("hash", function(hash) {
hash.update("umd");
hash.update(`${this.name}`);
hash.update(`${this.names.root}`);

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.

yep, it's ok

@sokra

sokra commented May 31, 2017

Copy link
Copy Markdown
Member

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

@AndersDJohnson

Copy link
Copy Markdown
Contributor Author

@sokra CLA has been signed.

@sokra
sokra merged commit 3e3b748 into webpack:master Jun 21, 2017
@AndersDJohnson

Copy link
Copy Markdown
Contributor Author

@sokra Thanks for merging.

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.

4 participants