-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eef575
commit 2bff250
Showing
5 changed files
with
64 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 suggestionMessage = (to?: 'src/', from?: 'src/app/' | 'app/') => | ||
`Clerk: clerkMiddleware() was not run, your middleware file might be misplaced. Move your middleware file to ./${to || ''}middleware.ts. Currently located at ./${from || ''}middleware.ts`; | ||
|
||
const { existsSync } = nodeFsOrThrow(); | ||
const path = nodePathOrThrow(); | ||
const cwd = nodeCwdOrThrow(); | ||
|
||
const projectWithAppSrcPath = path.join(cwd(), 'src', 'app'); | ||
const projectWithAppPath = path.join(cwd(), 'app'); | ||
|
||
if (existsSync(projectWithAppSrcPath)) { | ||
if (existsSync(path.join(projectWithAppSrcPath, 'middleware.ts'))) { | ||
return suggestionMessage('src/', 'src/app/'); | ||
} | ||
|
||
if (existsSync(path.join(cwd(), 'middleware.ts'))) { | ||
return suggestionMessage('src/'); | ||
} | ||
|
||
// default error | ||
return undefined; | ||
} | ||
|
||
if (existsSync(projectWithAppPath)) { | ||
if (existsSync(path.join(projectWithAppPath, 'middleware.ts'))) { | ||
return suggestionMessage(undefined, 'app/'); | ||
} | ||
// default error | ||
return undefined; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export { suggestMiddlewareLocation, hasSrcAppDir }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters