Skip to content

Commit

Permalink
Fix TypeScript inclusion in tsconfig.json for cli-v3 init (#1105)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
alexandredev3 and ericallam committed May 21, 2024
1 parent 5a6e79e commit a86f36c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-fishes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
trigger.dev: patch
---

Fix TypeScript inclusion in tsconfig.json for `cli-v3 init`
25 changes: 23 additions & 2 deletions packages/cli-v3/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();

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], "trigger.config.ts", {
const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
isArrayInsertion: true,
formattingOptions: {
tabSize: 2,
Expand Down

0 comments on commit a86f36c

Please sign in to comment.