UNPKG

@clerk/nextjs

Version:

Clerk SDK for NextJS

43 lines 1.91 kB
import "../../chunk-BUSYA2B4.js"; import { isNext16OrHigher } from "../../utils/sdk-versions"; import { nodeCwdOrThrow, nodeFsOrThrow, nodePathOrThrow } from "./utils"; function hasSrcAppDir() { const { existsSync } = nodeFsOrThrow(); const path = nodePathOrThrow(); const cwd = nodeCwdOrThrow(); const projectWithAppSrc = path.join(cwd(), "src", "app"); return !!existsSync(projectWithAppSrc); } function suggestMiddlewareLocation() { const fileExtensions = ["ts", "js"]; const fileNames = isNext16OrHigher ? ["middleware", "proxy"] : ["middleware"]; const fileNameDisplay = isNext16OrHigher ? "middleware or proxy" : "middleware"; const suggestionMessage = (fileName, extension, to, from) => `Clerk: clerkMiddleware() was not run, your ${fileNameDisplay} file might be misplaced. Move your ${fileNameDisplay} file to ./${to}${fileName}.${extension}. Currently located at ./${from}${fileName}.${extension}`; const { existsSync } = nodeFsOrThrow(); const path = nodePathOrThrow(); const cwd = nodeCwdOrThrow(); const projectWithAppSrcPath = path.join(cwd(), "src", "app"); const projectWithAppPath = path.join(cwd(), "app"); const checkMiddlewareLocation = (basePath, to, from) => { for (const fileName of fileNames) { for (const fileExtension of fileExtensions) { if (existsSync(path.join(basePath, `${fileName}.${fileExtension}`))) { return suggestionMessage(fileName, fileExtension, to, from); } } } return void 0; }; if (existsSync(projectWithAppSrcPath)) { return checkMiddlewareLocation(projectWithAppSrcPath, "src/", "src/app/") || checkMiddlewareLocation(cwd(), "src/", ""); } if (existsSync(projectWithAppPath)) { return checkMiddlewareLocation(projectWithAppPath, "", "app/"); } return void 0; } export { hasSrcAppDir, suggestMiddlewareLocation }; //# sourceMappingURL=middleware-location.js.map