Skip to content

merge.unique problem #125

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

Closed
eightHundreds opened this issue Feb 20, 2020 · 3 comments · Fixed by #135
Closed

merge.unique problem #125

eightHundreds opened this issue Feb 20, 2020 · 3 comments · Fixed by #135
Milestone

Comments

@eightHundreds
Copy link

eightHundreds commented Feb 20, 2020

const _ = require("lodash");
const merge = require("webpack-merge");

const PluginA = function(a) {
  this.a = a;
};
const PluginB = function() {};

console.log(
  merge({
    customizeArray: merge.unique(
      "plugins",
      ["PluginA"],
      plugin => plugin.constructor && plugin.constructor.name
    )
  })(
    {
      plugins: [new PluginB()]
    },
    {
      plugins: [new PluginA(), new PluginB()]
    }
  )
);

output

{ plugins: [ PluginB {}, PluginB {} ] }

expect result

{ plugins: [ PluginB {},PluginA {}, PluginB {} ] }
@InsOpDe
Copy link

InsOpDe commented May 5, 2020

Same problem here

@InsOpDe
Copy link

InsOpDe commented May 5, 2020

quick'n'dirty solution

const merge = require("webpack-merge");
const _ = require("lodash");
const PluginA = function (a) {
	this.a = a;
};
const PluginB = function () { };
const PluginC = function () { };

console.log(
	merge({
		customizeArray(a, b, key) {
			if (key === 'plugins') {
				return [...b, ...a].reduce((sum, val)=>{
					let inside = false;
					for(const entry of sum){
						if(entry.constructor && val.constructor && val.constructor.name == "PluginA") {
							inside = inside || entry.constructor.name === val.constructor.name
						}
					}
					if (!inside) {
						sum.push(val);
					}
					return sum;
					}, []);
			}
			// Fall back to default merging
			return undefined;
		}
	})(
		{
			plugins: [new PluginB(), new PluginA(2)]
		},
		{
			plugins: [new PluginA(1), new PluginC(), new PluginB()]
		}
	)
);

@bebraw bebraw added this to the v5 milestone Jul 3, 2020
bebraw added a commit that referenced this issue Jul 3, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Closes #125.
@bebraw
Copy link
Member

bebraw commented Jul 3, 2020

This will be fixed in #135 (v5).

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 a pull request may close this issue.

3 participants