Skip to content

Commit 8cf8544

Browse files
Chigalaericallam
andauthored
bugfix: jsx extensions breaks cli init (#374)
* bugfix: jsx extensions breaks cli init * Update init.ts (adding ts extension to check) * Create rude-spoons-compete.md --------- Co-authored-by: Eric Allam <eallam@icloud.com>
1 parent dd10717 commit 8cf8544

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

.changeset/rude-spoons-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
Bugfix: @trigger.dev/cli init now correctly identifies the App Dir when using JS

packages/cli/src/commands/init.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const initCommand = async (options: InitCommandOptions) => {
117117
logger.info("📁 Detected use of src directory");
118118
}
119119

120-
const nextJsDir = await detectPagesOrAppDir(resolvedPath, usesSrcDir, isTypescriptProject);
120+
const nextJsDir = await detectPagesOrAppDir(resolvedPath, usesSrcDir);
121121

122122
const routeDir = pathModule.join(resolvedPath, usesSrcDir ? "src" : "");
123123

@@ -283,7 +283,6 @@ async function detectUseOfSrcDir(path: string): Promise<boolean> {
283283
async function detectPagesOrAppDir(
284284
path: string,
285285
usesSrcDir = false,
286-
isTypescriptProject = false
287286
): Promise<"pages" | "app"> {
288287
const nextConfigPath = pathModule.join(path, "next.config.js");
289288
const importedConfig = await import(pathToFileURL(nextConfigPath).toString()).catch(() => ({}));
@@ -296,14 +295,16 @@ async function detectPagesOrAppDir(
296295
// If so then we return app
297296
// If not return pages
298297

299-
const extension = isTypescriptProject ? "tsx" : "js";
298+
const extensionsToCheck = ["jsx", "tsx", "js", "ts"];
299+
const basePath = pathModule.join(path, usesSrcDir ? "src" : "", "app", `page.`);
300300

301-
const appPagePath = pathModule.join(path, usesSrcDir ? "src" : "", "app", `page.${extension}`);
301+
for (const extension of extensionsToCheck) {
302+
const appPagePath = basePath + extension;
303+
const appPageExists = await pathExists(appPagePath);
302304

303-
const appPageExists = await pathExists(appPagePath);
304-
305-
if (appPageExists) {
306-
return "app";
305+
if (appPageExists) {
306+
return "app";
307+
}
307308
}
308309

309310
return "pages";

0 commit comments

Comments
 (0)