diff --git a/.changeset/rude-spoons-compete.md b/.changeset/rude-spoons-compete.md new file mode 100644 index 00000000000..c3ff5ccff7d --- /dev/null +++ b/.changeset/rude-spoons-compete.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/cli": patch +--- + +Bugfix: @trigger.dev/cli init now correctly identifies the App Dir when using JS diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 16b0ae9126d..7bdf7671899 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -117,7 +117,7 @@ export const initCommand = async (options: InitCommandOptions) => { logger.info("📁 Detected use of src directory"); } - const nextJsDir = await detectPagesOrAppDir(resolvedPath, usesSrcDir, isTypescriptProject); + const nextJsDir = await detectPagesOrAppDir(resolvedPath, usesSrcDir); const routeDir = pathModule.join(resolvedPath, usesSrcDir ? "src" : ""); @@ -283,7 +283,6 @@ async function detectUseOfSrcDir(path: string): Promise { async function detectPagesOrAppDir( path: string, usesSrcDir = false, - isTypescriptProject = false ): Promise<"pages" | "app"> { const nextConfigPath = pathModule.join(path, "next.config.js"); const importedConfig = await import(pathToFileURL(nextConfigPath).toString()).catch(() => ({})); @@ -296,14 +295,16 @@ async function detectPagesOrAppDir( // If so then we return app // If not return pages - const extension = isTypescriptProject ? "tsx" : "js"; + const extensionsToCheck = ["jsx", "tsx", "js", "ts"]; + const basePath = pathModule.join(path, usesSrcDir ? "src" : "", "app", `page.`); - const appPagePath = pathModule.join(path, usesSrcDir ? "src" : "", "app", `page.${extension}`); + for (const extension of extensionsToCheck) { + const appPagePath = basePath + extension; + const appPageExists = await pathExists(appPagePath); - const appPageExists = await pathExists(appPagePath); - - if (appPageExists) { - return "app"; + if (appPageExists) { + return "app"; + } } return "pages";