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>
This commit is contained in:
Chigala
2023-08-21 16:03:10 +01:00
committed by GitHub
parent dd10717628
commit 8cf85443d5
2 changed files with 14 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/cli": patch
---
Bugfix: @trigger.dev/cli init now correctly identifies the App Dir when using JS
+9 -8
View File
@@ -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<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(() => ({}));
@@ -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";