Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow setting admin path route from config #8085

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions packages/payload/src/bin/generateImportMap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export async function generateImportMap(

await writeImportMap({
componentMap: importMap,
config,
fileName: 'importMap.js',
force: options?.force,
importMap: imports,
Expand All @@ -158,27 +159,30 @@ export async function generateImportMap(

export async function writeImportMap({
componentMap,
config,
fileName,
force,
importMap,
log,
rootDir,
}: {
componentMap: InternalImportMap
config: SanitizedConfig
fileName: string
force?: boolean
importMap: Imports
log?: boolean
rootDir: string
}) {
let importMapFolderPath = ''
if (fs.existsSync(path.resolve(rootDir, 'app/(payload)/admin/'))) {
importMapFolderPath = path.resolve(rootDir, 'app/(payload)/admin/')
} else if (fs.existsSync(path.resolve(rootDir, 'src/app/(payload)/admin/'))) {
importMapFolderPath = path.resolve(rootDir, 'src/app/(payload)/admin/')
const adminPath = config.routes.admin || '/admin'
if (fs.existsSync(path.resolve(rootDir, `app/(payload)${adminPath}/`))) {
importMapFolderPath = path.resolve(rootDir, `app/(payload)${adminPath}/`)
} else if (fs.existsSync(path.resolve(rootDir, `src/app/(payload)${adminPath}/`))) {
importMapFolderPath = path.resolve(rootDir, `src/app/(payload)${adminPath}/`)
} else {
throw new Error(
`Could not find the payload admin directory. Looked in ${path.resolve(rootDir, 'app/(payload)/admin/')} and ${path.resolve(rootDir, 'src/app/(payload)/admin/')}`,
`Could not find the payload admin directory. Looked in ${path.resolve(rootDir, `app/(payload)${adminPath}/`)} and ${path.resolve(rootDir, `src/app/(payload)${adminPath}/`)}`,
)
}

Expand Down