Skip to content

Deprecate cache parameter in favour of seed #57

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

Merged
merged 14 commits into from
Jul 20, 2017

Conversation

nathanbirrell
Copy link
Contributor

@nathanbirrell nathanbirrell commented Jul 11, 2017

Functionality for cache stays the same, the more generic name is better suited for when your app needs to set custom keys.

requested in #55


closes #25

@codecov-io
Copy link

codecov-io commented Jul 11, 2017

Codecov Report

Merging #57 into master will increase coverage by 3.69%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   89.28%   92.98%   +3.69%     
==========================================
  Files           2        2              
  Lines          56       57       +1     
==========================================
+ Hits           50       53       +3     
+ Misses          6        4       -2
Impacted Files Coverage Δ
lib/plugin.js 92.85% <100%> (+3.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a985131...357f3d7. Read the comment docs.

lib/plugin.js Outdated
@@ -88,6 +90,9 @@ ManifestPlugin.prototype.apply = function(compiler) {
}.bind(this), {});
}

// Add custom values last, so they don't get the basePath prefixed to them
_.merge(manifest, initValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

use manifest = _.assign({}, initValue, manifest)

@@ -214,6 +214,58 @@ describe('ManifestPlugin', function() {
});
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test to prove that initValue is being overwritten

@mastilver
Copy link
Contributor

@a-x- @zuzusik @gmac Does initValue make sense to you (I had no idea how to name it so I just looked at the doc for Array.reduce :D )

Copy link
Contributor

@gmac gmac left a comment

Choose a reason for hiding this comment

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

I'm 👎 on this as a feature. This capability is already possible using cache, which handles seeding a manifest with initial key value pairs. That would be the correct way to achieve this.

Admittedly, the readme docs only mention cache in the context of multi-compiler architecture (which is a less common use case). I'd propose changing this PR to be documentation-only with the cache article updated to denote: "A cache of key/value pairs to used to seed the manifest. This may include a set of custom key/value pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode]."

@nathanbirrell nathanbirrell changed the title Add initValue object Deprecate cache parameter in favour of seed Jul 13, 2017
@nathanbirrell
Copy link
Contributor Author

nathanbirrell commented Jul 13, 2017

Hey @gmac, I agree.

I've updated the PR, unit tests and readme to reflect the move to seed (mentioned here).

It will still accept cache for now.

Cheers

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "webpack-manifest-plugin",
"version": "1.1.2",
"version": "1.1.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave the version as is :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done

@mastilver
Copy link
Contributor

@gmac are you ok with those changes?
Or shall we output a deprecation warning using util.deprecate?

});
});

it('seed attributes do not get prefixed with basePath', function(done) {
Copy link

Choose a reason for hiding this comment

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

I think we should go here with does something style - does not prefix seed attributes with basePath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice one, done.

it('combines manifests of multiple compilations', function(done) {
var seed = {};
webpackCompile([{
Copy link

Choose a reason for hiding this comment

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

  1. do we need this var at all?
  2. shouldn't we place a new line after var?

README.md Outdated
@@ -52,4 +55,4 @@ new ManifestPlugin({
* `publicPath`: A path prefix used only on output files, similar to Webpack's [output.publicPath](https://github.com/webpack/docs/wiki/configuration#outputpublicpath). Ignored if `basePath` was also provided.
* `stripSrc`: removes unwanted strings from source filenames (string or regexp)
* `writeToFileEmit`: If set to `true` will emit to build folder and memory in combination with `webpack-dev-server`
* `cache`: In [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler) webpack will overwrite the manifest on each compilation. Passing a shared `{}` as the `cache` option into each compilation's ManifestPlugin will combine the manifest between compilations.
* `seed`: A cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler).
Copy link

@zuzusik zuzusik Jul 17, 2017

Choose a reason for hiding this comment

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

Should we add here the information how exactly it should be used in multi-compiler-mode?

Maybe I am missing something, but for me it is not really clear that I need to specify it as an empty object to do that - I cleared this out from tests, but who is going to read tests when he needs info?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about just adding: To combine manifests, pass a shared seed object to each compiler's plugin instance.

Copy link

Choose a reason for hiding this comment

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

To combine manifests, pass a shared seed object to each compiler's plugin instance.

this can be somehow confusing for those not knowing how it all works under the hood - the first question will be what is compiler plugin instance?

I assume adding : just pass it as empty object: 'seed: {}' before final .

Copy link
Contributor

Choose a reason for hiding this comment

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

I find just pass it as empty object: 'seed: {}' more confusing than helpful. It doesn't make that point that a shared singleton object must be passed to multiple plugin instances to combine their manifests. I amend my earlier text for clarity:

To combine manifests, pass a shared seed object to each compiler's ManifestPlugin instance.

If you're doing multi-compiler architecture, that should make sense. If you're not, you don't need the information anyway.

Copy link
Contributor

@gmac gmac left a comment

Choose a reason for hiding this comment

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

Adding that extra bit of docs about a shared compiler instance would be helpful. Overall though, this looks good. 👍

README.md Outdated
@@ -52,4 +55,4 @@ new ManifestPlugin({
* `publicPath`: A path prefix used only on output files, similar to Webpack's [output.publicPath](https://github.com/webpack/docs/wiki/configuration#outputpublicpath). Ignored if `basePath` was also provided.
* `stripSrc`: removes unwanted strings from source filenames (string or regexp)
* `writeToFileEmit`: If set to `true` will emit to build folder and memory in combination with `webpack-dev-server`
* `cache`: In [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler) webpack will overwrite the manifest on each compilation. Passing a shared `{}` as the `cache` option into each compilation's ManifestPlugin will combine the manifest between compilations.
* `seed`: A cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler).
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just adding: To combine manifests, pass a shared seed object to each compiler's plugin instance.

@zuzusik
Copy link

zuzusik commented Jul 17, 2017

Thinking about further improvements here: is there a way to detect that we are in multi-compiler mode inside of a plugin and then switch to seeding mode?

This would be really great and convenient - no need to specify seed as {} - it will just work out of the box.

@gmac
Copy link
Contributor

gmac commented Jul 17, 2017

Sure, it's possible to detect multi-compiler mode... you just look at the number of compilers configured. Off the top of my head, I think that's managed by an array called compilers on the root Webpack compiler object.

This sounds like a potentially useful feature, although beyond the scope of this PR. There's definitely some nuances there that would need to be solved for. The way I'd see it working would be to pass an option like universalManifest: true. When enabled, a plugin instance would configure around an internal singleton and assign any provided seed params onto that. Otherwise, it would configure around the provided seed object itself. The nuance would be in tracking the right object identity.

@nathanbirrell
Copy link
Contributor Author

Thanks all. Updated the readme with @gmac's suggestion 👍🏼

Copy link
Contributor

@gmac gmac left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@gmac gmac merged commit 56cfa00 into shellscape:master Jul 20, 2017
@mastilver
Copy link
Contributor

👍 I will release that tonight

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.

Define other manifest fields
5 participants