Skip to content

Commit a86f36c

Browse files
Fix TypeScript inclusion in tsconfig.json for cli-v3 init (#1105)
* Fix TypeScript inclusion in tsconfig.json for cli-v3 init Fixed an issue where TypeScript files were included in the project directory when no include directive was present in tsconfig.json. Previously, the CLI added trigger.config.ts to the inclusion list by default, causing TypeScript compilation errors for other files. The fix ensures that trigger.config.ts is only added to the inclusion list if there's an existing include directive present in tsconfig.json * Create hot-fishes-retire.md --------- Co-authored-by: Eric Allam <[email protected]>
1 parent 5a6e79e commit a86f36c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.changeset/hot-fishes-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
trigger.dev: patch
3+
---
4+
5+
Fix TypeScript inclusion in tsconfig.json for `cli-v3 init`

packages/cli-v3/src/commands/init.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { recordSpanException } from "@trigger.dev/core/v3/workers";
55
import chalk from "chalk";
66
import { Command } from "commander";
77
import { execa } from "execa";
8-
import { applyEdits, modify } from "jsonc-parser";
8+
import { applyEdits, modify, findNodeAtLocation, parseTree, getNodeValue } from "jsonc-parser";
99
import { writeFile } from "node:fs/promises";
1010
import { join, relative, resolve } from "node:path";
1111
import terminalLink from "terminal-link";
@@ -329,8 +329,29 @@ async function addConfigFileToTsConfig(dir: string, options: InitCommandOptions)
329329
});
330330

331331
const tsconfigContent = await readFile(tsconfigPath);
332+
const tsconfigContentTree = parseTree(tsconfigContent, undefined);
333+
if (!tsconfigContentTree) {
334+
span.end();
335+
336+
return;
337+
}
338+
339+
const tsconfigIncludeOption = findNodeAtLocation(tsconfigContentTree, ["include"]);
340+
if (!tsconfigIncludeOption) {
341+
span.end();
342+
343+
return;
344+
}
345+
346+
const tsConfigFileName = "trigger.config.ts";
347+
const tsconfigIncludeOptionValue: string[] = getNodeValue(tsconfigIncludeOption);
348+
if (tsconfigIncludeOptionValue.includes(tsConfigFileName)) {
349+
span.end();
350+
351+
return;
352+
}
332353

333-
const edits = modify(tsconfigContent, ["include", -1], "trigger.config.ts", {
354+
const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
334355
isArrayInsertion: true,
335356
formattingOptions: {
336357
tabSize: 2,

0 commit comments

Comments
 (0)