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 <eric@trigger.dev>
This commit is contained in:
Alexandre Costa
2024-05-21 10:40:49 -03:00
committed by GitHub
parent 5a6e79e0c0
commit a86f36cefa
2 changed files with 28 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
trigger.dev: patch
---
Fix TypeScript inclusion in tsconfig.json for `cli-v3 init`
+23 -2
View File
@@ -5,7 +5,7 @@ import { recordSpanException } from "@trigger.dev/core/v3/workers";
import chalk from "chalk";
import { Command } from "commander";
import { execa } from "execa";
import { applyEdits, modify } from "jsonc-parser";
import { applyEdits, modify, findNodeAtLocation, parseTree, getNodeValue } from "jsonc-parser";
import { writeFile } from "node:fs/promises";
import { join, relative, resolve } from "node:path";
import terminalLink from "terminal-link";
@@ -329,8 +329,29 @@ async function addConfigFileToTsConfig(dir: string, options: InitCommandOptions)
});
const tsconfigContent = await readFile(tsconfigPath);
const tsconfigContentTree = parseTree(tsconfigContent, undefined);
if (!tsconfigContentTree) {
span.end();
const edits = modify(tsconfigContent, ["include", -1], "trigger.config.ts", {
return;
}
const tsconfigIncludeOption = findNodeAtLocation(tsconfigContentTree, ["include"]);
if (!tsconfigIncludeOption) {
span.end();
return;
}
const tsConfigFileName = "trigger.config.ts";
const tsconfigIncludeOptionValue: string[] = getNodeValue(tsconfigIncludeOption);
if (tsconfigIncludeOptionValue.includes(tsConfigFileName)) {
span.end();
return;
}
const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
isArrayInsertion: true,
formattingOptions: {
tabSize: 2,