Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-spoons-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/cli": patch
---

Bugfix: @trigger.dev/cli init now correctly identifies the App Dir when using JS
17 changes: 9 additions & 8 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "");

Expand Down Expand Up @@ -283,7 +283,6 @@ async function detectUseOfSrcDir(path: string): Promise<boolean> {
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(() => ({}));
Expand All @@ -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";
Expand Down