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 error messages when importing .keystone/config.js #9359

Merged
merged 5 commits into from
Oct 15, 2024
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/slimy-files-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fix misleading error messages when importing `.keystone/config.js`
14 changes: 6 additions & 8 deletions packages/core/src/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getBuiltKeystoneConfigurationPath } from '../lib/createSystem'
import fs from 'node:fs/promises'

export class ExitError extends Error {
code: number
Expand All @@ -10,13 +11,10 @@ export class ExitError extends Error {

// TODO: this cannot be changed for now, circular dependency with getSystemPaths, getEsbuildConfig
export async function importBuiltKeystoneConfiguration (cwd: string) {
try {
return require(getBuiltKeystoneConfigurationPath(cwd)).default
} catch (err: any) {
if (err.code === 'MODULE_NOT_FOUND') {
console.error('🚨 keystone build has not been run')
throw new ExitError(1)
}
throw err
const builtConfigPath = getBuiltKeystoneConfigurationPath(cwd)
if (!(await fs.stat(builtConfigPath).catch(() => null))) {
console.error('🚨 keystone build has not been run')
throw new ExitError(1)
}
return require(builtConfigPath).default
}
Loading