danger / danger/danger-js

[BUG] tsconfig.json "extends" field not parsed by transpiler

Open
#1,283 4 comments 1 reaction 0 assignees View on GitHub
bug enhancement help wanted You Can Do This
Dominant language
TypeScript
Stars
5.5k
Forks
379
Avg merge
2h 8m
Merged PRs (30d)
6

Description

**Describe the bug**
When using the built-in native TypeScript transpiler, the `extends` field is not supported and only the explicit `compilerOptions` are used. This field is sometimes used in monorepos to extend a shared config, or to extend one of the [official "base" templates](https://github.com/tsconfig/bases).

**To Reproduce**
Steps to reproduce the behavior:
0. Install a base config: `npm install @tsconfig/node16`
1. Create a `tsconfig.json` extending that config:
```json
{
"extends": "@tsconfig/node16/tsconfig.json"
}
```
2. Create a Dangerfile which tries to use non-commonjs features:
```ts
import { exec } from "child_process";
```
3. Try to run Danger with `danger ci`. It will report an error like "cannot use import outside a module", as the `module: "commonjs"` option from the base config does not get inherited correctly.

**Expected behavior**
Danger should support all official methods of configuring tsconfig.json.

| software | version
| ---------------- | -------
| danger.js | 11.0.7
| node | v16.15.0
| npm | 8.5.5
| Operating System | macOS 12.4

**Additional context**
I believe the bug is because Danger's transpiler directly loads the tsconfig file contents and passes it to `ts.transpileModule`:

https://github.com/danger/danger-js/blob/630f2a49cfa1e7e4b87173ee9754278e00452ac3/source/runner/runners/utils/transpiler.ts#L128-L134

This can be fixed by using the TypeScript APIs for parsing the config options. For example, in `ts-node`:
https://github.com/TypeStrong/ts-node/blob/14323f9d00d5c7051ac09b944c7f423e442145ea/src/configuration.ts#L301-L317

Some of the other functions in this file, like `lookupTSConfig`, can also use the native APIs instead.

Contributor guide

Open the contributing guide

Research direction

Read source/runner/runners/utils/transpiler.ts around lines 128-134, then inspect lookupTSConfig and the TypeScript configuration APIs referenced in the issue. Reproduce with the @tsconfig/node16 example and danger ci; done means the inherited compilerOptions are applied and official tsconfig extends configurations work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.