diff --git a/package.json b/package.json index fb84302..92d233d 100644 --- a/package.json +++ b/package.json @@ -69,5 +69,8 @@ "hooks": { "pre-commit": "lint-staged" } + }, + "volta": { + "node": "16.20.2" } } diff --git a/src/__tests__/tsconfig-loader.test.ts b/src/__tests__/tsconfig-loader.test.ts index bee2624..c3693c0 100644 --- a/src/__tests__/tsconfig-loader.test.ts +++ b/src/__tests__/tsconfig-loader.test.ts @@ -1,5 +1,6 @@ import { tsConfigLoader, walkForTsConfig } from "../tsconfig-loader"; import { join, resolve } from "path"; +import { getTsconfig } from "get-tsconfig"; describe("tsconfig-loader", () => { it("should find tsconfig in cwd", () => { @@ -207,37 +208,7 @@ describe("loadSyncDefault", () => { expect(result).toEqual({ baseUrl: undefined, - paths: { foo: ['bar'] }, - tsConfigPath: resolve(cwd, 'tsconfig.json') - }); - }); - - it("should load a config with string extends and overwrite all options", () => { - const cwd = resolve(__dirname, "../../example/extend-overwrite") - const tsConfigPath = resolve(cwd, 'nested/tsconfig.json'); - - const result = tsConfigLoader({ - cwd, - getEnv: (name: string) => name === 'TS_NODE_PROJECT' ? tsConfigPath : undefined - }); - - expect(result).toEqual({ - baseUrl: "./kalle", - paths: { foo: ["bar2"] }, - strict: true, - tsConfigPath - }); - }); - - it("should load a config with string extends from node_modules and overwrite all options", () => { - const cwd = resolve(__dirname, "../../example/extend-node-module") - - const result = tsConfigLoader({ cwd, getEnv: () => undefined }); - - expect(result).toEqual({ - baseUrl: "./kalle", - paths: { foo: ["bar2"] }, - strict: true, + paths: { foo: ["bar"] }, tsConfigPath: resolve(cwd, "tsconfig.json") }); }); @@ -289,3 +260,39 @@ describe("loadSyncDefault", () => { }); }); }); + +describe("getTsconfig", () => { + it("should load a config with string extends and overwrite all options", () => { + const tsConfigPath = resolve(__dirname, "../../example/extend-overwrite/nested/tsconfig.json"); + + const result = getTsconfig(tsConfigPath); + + expect(result).toEqual({ + config: { + compilerOptions: { + baseUrl: "./kalle", + paths: { foo: ["bar2"] }, + strict: true, + } + }, + path: tsConfigPath + }); + }); + + it("should load a config with string extends from node_modules and overwrite all options", () => { + const tsConfigPath = resolve(__dirname, "../../example/extend-node-module/tsconfig.json") + + const result = getTsconfig(tsConfigPath); + + expect(result).toEqual({ + config: { + compilerOptions: { + baseUrl: "./kalle", + paths: { foo: ["bar2"] }, + strict: true, + } + }, + path: tsConfigPath + }); + }); +}); diff --git a/src/tsconfig-loader.ts b/src/tsconfig-loader.ts index 17eb867..e6556fb 100644 --- a/src/tsconfig-loader.ts +++ b/src/tsconfig-loader.ts @@ -64,7 +64,6 @@ function loadSyncDefault( return { tsConfigPath: configPath, - ...tsconfig?.config.compilerOptions, baseUrl: baseUrl || tsconfig?.config.compilerOptions?.baseUrl, paths: tsconfig?.config.compilerOptions?.paths ?? {}, };