Skip to content

Commit 61d1b1d

Browse files
authored
Merge pull request #219 from benyap/fix/218-baseurl-should-be-optional
fix: make `baseUrl` optional
2 parents 4702569 + 47abcff commit 61d1b1d

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ being able to ship working JavaScript code.
2121
```ts
2222
{
2323
"compilerOptions": {
24-
"baseUrl": ".",
2524
"paths": {
2625
"~/*": ["./src/*"]
2726
}

src/steps/resolvePaths.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function resolvePaths(
1111
options: Pick<ProgramOptions, "out" | "project" | "src">,
1212
tsConfig: TSConfig
1313
): ProgramPaths {
14-
const { baseUrl, outDir, paths } = tsConfig.options ?? {};
14+
const { baseUrl = "", outDir, paths } = tsConfig.options ?? {};
1515

1616
const out = options.out ?? outDir;
1717
if (!out) {
@@ -21,12 +21,6 @@ export function resolvePaths(
2121
);
2222
}
2323

24-
if (!baseUrl)
25-
throw new TSConfigPropertyError(
26-
resolvePaths.name,
27-
"compilerOptions.baseUrl"
28-
);
29-
3024
if (!paths)
3125
throw new TSConfigPropertyError(resolvePaths.name, "compilerOptions.paths");
3226

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This is a comment
2+
{
3+
"compilerOptions": {
4+
"lib": ["ES6"],
5+
"module": "CommonJS",
6+
"moduleResolution": "Node",
7+
"target": "ES6",
8+
"resolveJsonModule": true,
9+
"skipLibCheck": true,
10+
"strict": true,
11+
"outDir": "build",
12+
// This is a comment
13+
"paths": {
14+
"~/*": ["./src/*"]
15+
}
16+
},
17+
"include": ["src/**/*", "test/**/*"]
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc",
3+
/**
4+
* This is a multiline comment
5+
*/
6+
"compilerOptions": {
7+
// This is a single line comment
8+
"outDir": "dist"
9+
}
10+
}

test/steps/loadTSConfig.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,33 @@ describe("steps/loadTSConfig", () => {
5555
`);
5656
});
5757

58+
it("loads tsconfig (jsonc) with extends correctly (no baseUrl)", () => {
59+
const config = loadTSConfig(
60+
"test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc"
61+
);
62+
expect(config.options).toMatchInlineSnapshot(`
63+
{
64+
"configFilePath": undefined,
65+
"lib": [
66+
"lib.es2015.d.ts",
67+
],
68+
"module": 1,
69+
"moduleResolution": 2,
70+
"outDir": "dist",
71+
"paths": {
72+
"~/*": [
73+
"./src/*",
74+
],
75+
},
76+
"pathsBasePath": "test/fixtures/tsconfig/nested",
77+
"resolveJsonModule": true,
78+
"skipLibCheck": true,
79+
"strict": true,
80+
"target": 2,
81+
}
82+
`);
83+
});
84+
5885
// Was going to use this test to make sure that syntax errors were reported sensibly.
5986
// Turns out the Typescript config loader does some crazy stuff to recover from syntax errors!
6087
it("loads tsconfig with syntax errors (crazy stuff!)", () => {

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"noUnusedLocals": true,
1616
"noUnusedParameters": true,
1717
"forceConsistentCasingInFileNames": true,
18-
"baseUrl": ".",
1918
"paths": {
2019
"~/*": ["./src/*"]
2120
}

0 commit comments

Comments
 (0)