Skip to content

Commit

Permalink
[fix] webpack-config-composer minor things
Browse files Browse the repository at this point in the history
- .gitignore lib
- don't use Object.assign
- get data.config without ... operator in case it's a get field
  • Loading branch information
jchip committed Apr 28, 2021
1 parent 007471d commit c6cb1ad
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 155 deletions.
1 change: 1 addition & 0 deletions packages/webpack-config-composer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
# should use latest dep, as an app that consumes a module would have its
# own lockfile, but remove this if you want to commit the package lock file.
*-lock*
lib
28 changes: 9 additions & 19 deletions packages/webpack-config-composer/lib/partial.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/webpack-config-composer/lib/partial.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions packages/webpack-config-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"src"
],
"dependencies": {
"lodash": "^4.13.1",
"tslib": "^2.1.0"
"lodash": "^4.17.21",
"tslib": "^2.2.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
Expand Down Expand Up @@ -59,10 +59,6 @@
"typedoc": "^0.20.13",
"typescript": "^4.1.3"
},
"engines": {
"node": ">= 6",
"npm": ">= 3"
},
"mocha": {
"require": [
"ts-node/register",
Expand Down Expand Up @@ -91,7 +87,8 @@
"gulpfile.js",
"test",
"xrun*.js",
"xrun*.ts"
"xrun*.ts",
"lib"
],
"check-coverage": true,
"statements": 100,
Expand Down
27 changes: 10 additions & 17 deletions packages/webpack-config-composer/src/partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Partial {
if (typeof data === "function") {
this[DATA] = { config: data };
} else {
this[DATA] = Object.assign({ config: {}, options: {} }, data);
this[DATA] = { config: {}, options: {}, ...data };
}
this.setOverride(_.identity);
}
Expand All @@ -28,7 +28,7 @@ class Partial {
}

set options(options) {
this[DATA].options = Object.assign({}, options);
this[DATA].options = { ...options };
}

get options() {
Expand All @@ -44,27 +44,20 @@ class Partial {
}

compose(options) {
options = Object.assign({}, this.options, options);
options = { ...this.options, ...options };

const config = this.config.webpackPartial || this.config;
const configType = typeof config;
let config = this.config;

let ret;

if (configType === "object") {
ret = config;
} else if (configType === "function") {
ret = config(options);
if (typeof ret === "function") {
ret = ret(options);
while (typeof config === "function") {
config = config(options);
if (config && config.webpackPartial) {
config = config.webpackPartial;
}
} else {
throw new Error(`can't process config from Partial ${this._name}`);
}

const override = this[OVERRIDE](ret, options);
const override = this[OVERRIDE](config, options);

return override || ret;
return override || config;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import deleteCustomProps from "../../src/delete-custom-props";
import { expect } from "chai";

Expand All @@ -8,8 +6,8 @@ describe("delete custom props", () => {
const o = {
module: {
__dirname: "/test",
_name: "test"
}
_name: "test",
},
};
const x = deleteCustomProps(o);
expect(x.module.__dirname).to.equal("/test");
Expand All @@ -20,8 +18,8 @@ describe("delete custom props", () => {
const o = {
module: {
__filename: "/test",
_name: "test"
}
_name: "test",
},
};
const x = deleteCustomProps(o);
expect(x.module.__filename).to.equal("/test");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import headConcatArrayMerge from "../../src/head-concat-array-merge";
import { expect } from "chai";

Expand Down
Loading

0 comments on commit c6cb1ad

Please sign in to comment.