Skip to content

Commit

Permalink
fix: make baseUrl optional
Browse files Browse the repository at this point in the history
  • Loading branch information
benyap committed Apr 11, 2023
1 parent 4702569 commit 47abcff
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ being able to ship working JavaScript code.
```ts
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
}
Expand Down
8 changes: 1 addition & 7 deletions src/steps/resolvePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function resolvePaths(
options: Pick<ProgramOptions, "out" | "project" | "src">,
tsConfig: TSConfig
): ProgramPaths {
const { baseUrl, outDir, paths } = tsConfig.options ?? {};
const { baseUrl = "", outDir, paths } = tsConfig.options ?? {};

const out = options.out ?? outDir;
if (!out) {
Expand All @@ -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");

Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/tsconfig/nested/tsconfig.parent.no-base-url.jsonc
Original file line number Diff line number Diff line change
@@ -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/**/*"]
}
10 changes: 10 additions & 0 deletions test/fixtures/tsconfig/tsconfig.extends.no-base-url.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
}
27 changes: 27 additions & 0 deletions test/steps/loadTSConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)", () => {
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
}
Expand Down

0 comments on commit 47abcff

Please sign in to comment.