Skip to content

Commit

Permalink
fix: Don't crash without a rule
Browse files Browse the repository at this point in the history
Related to #151.
  • Loading branch information
bebraw committed Nov 12, 2020
1 parent 08c88c1 commit 07e21c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ function mergeWithRules(rules: Rules) {
let currentRule: CustomizeRule | Rules = rules;

key.split(".").forEach(k => {
if (!currentRule) {
return;
}

currentRule = currentRule[k];
});

Expand Down
31 changes: 21 additions & 10 deletions test/merge-with-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ describe("Merge with rules", function() {
}
]
},
plugins: [
{ name: 'StylelintPlugin' }
]
plugins: [{ name: "StylelintPlugin" }]
};
const development = {
module: {
Expand All @@ -323,9 +321,7 @@ describe("Merge with rules", function() {
}
]
},
plugins: [
{ name: "MiniCssExtractPlugin" }
]
plugins: [{ name: "MiniCssExtractPlugin" }]
};
const result = {
entry: "demo",
Expand All @@ -345,10 +341,7 @@ describe("Merge with rules", function() {
}
]
},
plugins: [
{ name: "StylelintPlugin" },
{ name: "MiniCssExtractPlugin" }
]
plugins: [{ name: "StylelintPlugin" }, { name: "MiniCssExtractPlugin" }]
};

assert.deepStrictEqual(
Expand Down Expand Up @@ -485,4 +478,22 @@ describe("Merge with rules", function() {
result
);
});

it("should merge without rule (#151)", function() {
const module = {
rules: {
test: CustomizeRule.Match,
use: {
loader: CustomizeRule.Match,
options: CustomizeRule.Replace
}
}
};
const _mergeWithoutRule = mergeWithRules({
module
});
const config = { resolve: { extensions: [".js"] } };

expect(() => _mergeWithoutRule(config, config)).not.toThrow();
});
});

0 comments on commit 07e21c1

Please sign in to comment.