Skip to content

Commit

Permalink
Make extension config override instead of deep merge (#95)
Browse files Browse the repository at this point in the history
* yarn-deduplicate && yarn

* Make extension config override instead of deep merge

Fixes #94
  • Loading branch information
OliverJAsh authored and jonaskello committed Sep 12, 2019
1 parent d1cb8f5 commit 87fbea7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 106 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"repository": "https://github.com/dividab/tsconfig-paths",
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/deepmerge": "^1.3.2",
"@types/minimist": "^1.2.0",
"@types/mocha": "^5.2.3",
"@types/node": "^6.0.54",
Expand All @@ -30,7 +29,6 @@
},
"dependencies": {
"@types/json5": "^0.0.29",
"deepmerge": "^2.0.1",
"json5": "^1.0.1",
"minimist": "^1.2.0",
"strip-bom": "^3.0.0"
Expand Down
11 changes: 9 additions & 2 deletions src/tsconfig-loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as path from "path";
import * as fs from "fs";
import * as deepmerge from "deepmerge";
// tslint:disable:no-require-imports
import JSON5 = require("json5");
import StripBom = require("strip-bom");
Expand All @@ -14,6 +13,7 @@ export interface Tsconfig {
compilerOptions?: {
baseUrl?: string;
paths?: { [key: string]: Array<string> };
strict?: boolean;
};
}

Expand Down Expand Up @@ -139,7 +139,14 @@ export function loadTsconfig(
);
}

return deepmerge(base, config);
return {
...base,
...config,
compilerOptions: {
...base.compilerOptions,
...config.compilerOptions
}
};
}
return config;
}
16 changes: 12 additions & 4 deletions test/tsconfig-loader-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ describe("loadConfig", () => {
assert.deepEqual(res, config);
});

it("It should load a config with extends and overwrite baseUrl", () => {
it("It should load a config with extends and overwrite all options", () => {
const firstConfig = {
extends: "../base-config.json",
compilerOptions: { baseUrl: "kalle" }
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } }
};
const firstConfigPath = join("/root", "dir1", "tsconfig.json");
const baseConfig = {
compilerOptions: { baseUrl: "olle", paths: { foo: ["bar"] } }
compilerOptions: {
baseUrl: "olle",
paths: { foo: ["bar1"] },
strict: true
}
};
const baseConfigPath = join("/root", "base-config.json");
const res = loadTsconfig(
Expand All @@ -156,7 +160,11 @@ describe("loadConfig", () => {

assert.deepEqual(res, {
extends: "../base-config.json",
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar"] } }
compilerOptions: {
baseUrl: "kalle",
paths: { foo: ["bar2"] },
strict: true
}
});
});

Expand Down
107 changes: 9 additions & 98 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
version "4.1.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.4.tgz#5ca073b330d90b4066d6ce18f60d57f2084ce8ca"

"@types/deepmerge@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/deepmerge/-/deepmerge-1.3.2.tgz#a87837384624d63e8c3df3ae85693d574ea6b5db"

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down Expand Up @@ -223,18 +219,10 @@ babel-types@^6.18.0, babel-types@^6.23.0:
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babylon@^6.11.0, babylon@^6.15.0:
version "6.16.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3"

babylon@^6.18.0:
babylon@^6.11.0, babylon@^6.15.0, babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"

balanced-match@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
Expand All @@ -246,13 +234,6 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

brace-expansion@^1.0.0:
version "1.1.6"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9"
dependencies:
balanced-match "^0.4.1"
concat-map "0.0.1"

brace-expansion@^1.1.7:
version "1.1.8"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
Expand All @@ -272,11 +253,7 @@ [email protected]:
version "1.3.1"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"

buffer-from@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.0.0.tgz#4cb8832d23612589b0406e9e2956c17f06fdf531"

buffer-from@^1.1.0:
buffer-from@^1.0.0, buffer-from@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04"

Expand Down Expand Up @@ -414,20 +391,10 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

[email protected]:
[email protected], commander@^2.11.0, commander@^2.9.0:
version "2.15.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"

commander@^2.11.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"

commander@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
dependencies:
graceful-readlink ">= 1.0.0"

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down Expand Up @@ -514,10 +481,6 @@ deep-eql@^3.0.0:
dependencies:
type-detect "^4.0.0"

deepmerge@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.0.1.tgz#25c1c24f110fb914f80001b925264dd77f3f4312"

default-require-extensions@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-1.0.0.tgz#f37ea15d3e13ffd9b437d33e1a75b5fb97874cb8"
Expand All @@ -535,18 +498,10 @@ detect-indent@^4.0.0:
dependencies:
repeating "^2.0.0"

[email protected]:
[email protected], diff@^3.1.0, diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

diff@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"

diff@^3.2.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"

ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
Expand Down Expand Up @@ -761,7 +716,7 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"

[email protected], glob@^7.1.1:
[email protected], glob@^7.0.0, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand All @@ -772,17 +727,6 @@ [email protected], glob@^7.1.1:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.5, glob@^7.0.6:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.2"
once "^1.3.0"
path-is-absolute "^1.0.0"

globals@^9.0.0:
version "9.17.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-9.17.0.tgz#0c0ca696d9b9bb694d2e5470bd37777caad50286"
Expand All @@ -791,10 +735,6 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

"graceful-readlink@>= 1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"

[email protected]:
version "1.10.5"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
Expand Down Expand Up @@ -1103,21 +1043,14 @@ js-tokens@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"

js-yaml@^3.12.0:
js-yaml@^3.12.0, js-yaml@^3.4.3:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
integrity sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.4.3:
version "3.10.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -1368,12 +1301,6 @@ [email protected], minimatch@^3.0.0, minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"

[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
Expand Down Expand Up @@ -1765,11 +1692,7 @@ resolve-from@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57"

resolve@^1.1.6:
version "1.2.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c"

resolve@^1.3.2:
resolve@^1.1.6, resolve@^1.3.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36"
dependencies:
Expand All @@ -1788,13 +1711,7 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@^2.5.4:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
glob "^7.0.5"

rimraf@^2.6.1, rimraf@^2.6.2:
rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
dependencies:
Expand Down Expand Up @@ -2141,18 +2058,12 @@ which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

which@^1.2.10, which@^1.3.0:
which@^1.2.10, which@^1.2.9, which@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
dependencies:
isexe "^2.0.0"

which@^1.2.9:
version "1.2.14"
resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5"
dependencies:
isexe "^2.0.0"

[email protected]:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"
Expand Down

0 comments on commit 87fbea7

Please sign in to comment.