Skip to content

Commit

Permalink
Make extension config override instead of deep merge
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverJAsh committed Sep 11, 2019
1 parent f8f6e5b commit 4f54d04
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 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
8 changes: 0 additions & 8 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 @@ -485,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 Down

0 comments on commit 4f54d04

Please sign in to comment.