diff --git a/README.md b/README.md index 6a59080..e4c2d90 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ being able to ship working JavaScript code. ```ts { "compilerOptions": { - "baseUrl": ".", "paths": { "~/*": ["./src/*"] } diff --git a/src/steps/resolvePaths.ts b/src/steps/resolvePaths.ts index 69ecab0..d19f88e 100644 --- a/src/steps/resolvePaths.ts +++ b/src/steps/resolvePaths.ts @@ -11,7 +11,7 @@ export function resolvePaths( options: Pick, tsConfig: TSConfig ): ProgramPaths { - const { baseUrl, outDir, paths } = tsConfig.options ?? {}; + const { baseUrl = "", outDir, paths } = tsConfig.options ?? {}; const out = options.out ?? outDir; if (!out) { @@ -21,12 +21,6 @@ export function resolvePaths( ); } - if (!baseUrl) - throw new TSConfigPropertyError( - resolvePaths.name, - "compilerOptions.baseUrl" - ); - if (!paths) throw new TSConfigPropertyError(resolvePaths.name, "compilerOptions.paths"); diff --git a/test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc b/test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc new file mode 100644 index 0000000..c73c4b2 --- /dev/null +++ b/test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc @@ -0,0 +1,18 @@ +// This is a comment +{ + "compilerOptions": { + "lib": ["ES6"], + "module": "CommonJS", + "moduleResolution": "Node", + "target": "ES6", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "outDir": "build", + // This is a comment + "paths": { + "~/*": ["./src/*"] + } + }, + "include": ["src/**/*", "test/**/*"] +} diff --git a/test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc b/test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc new file mode 100644 index 0000000..e2ee421 --- /dev/null +++ b/test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc @@ -0,0 +1,10 @@ +{ + "extends": "./test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc", + /** + * This is a multiline comment + */ + "compilerOptions": { + // This is a single line comment + "outDir": "dist" + } +} diff --git a/test/steps/loadTSConfig.test.ts b/test/steps/loadTSConfig.test.ts index 964ffba..da51955 100644 --- a/test/steps/loadTSConfig.test.ts +++ b/test/steps/loadTSConfig.test.ts @@ -55,6 +55,33 @@ describe("steps/loadTSConfig", () => { `); }); + it("loads tsconfig (jsonc) with extends correctly (no baseUrl)", () => { + const config = loadTSConfig( + "test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc" + ); + expect(config.options).toMatchInlineSnapshot(` + { + "configFilePath": undefined, + "lib": [ + "lib.es2015.d.ts", + ], + "module": 1, + "moduleResolution": 2, + "outDir": "dist", + "paths": { + "~/*": [ + "./src/*", + ], + }, + "pathsBasePath": "test/fixtures/tsconfig/nested", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": 2, + } + `); + }); + // Was going to use this test to make sure that syntax errors were reported sensibly. // Turns out the Typescript config loader does some crazy stuff to recover from syntax errors! it("loads tsconfig with syntax errors (crazy stuff!)", () => { diff --git a/tsconfig.json b/tsconfig.json index 67e15f7..4498758 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,6 @@ "noUnusedLocals": true, "noUnusedParameters": true, "forceConsistentCasingInFileNames": true, - "baseUrl": ".", "paths": { "~/*": ["./src/*"] }