Skip to content

Commit c0979f2

Browse files
committedAug 24, 2023
fix: improve error message upon +page.js
1 parent fc88332 commit c0979f2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,26 @@ function isGlobalConfig(configName: string): configName is ConfigNameGlobal {
12201220
function assertConfigExists(configName: string, configsDefined: string[], definedByFile: string) {
12211221
if (isGlobalConfig(configName)) return
12221222
if (configsDefined.includes(configName)) return
1223+
handleUnknownConfig(configName, configsDefined, definedByFile)
1224+
assert(false)
1225+
}
1226+
function handleUnknownConfig(configName: string, configsDefined: string[], definedByFile: string) {
12231227
let errMsg = `${definedByFile} defines an unknown config ${pc.bold(configName)}`
1224-
const configNameSimilar = getMostSimilar(configName, configsDefined)
1228+
let configNameSimilar: string | null = null
1229+
if (configName === 'page') {
1230+
configNameSimilar = 'Page'
1231+
} else {
1232+
configNameSimilar = getMostSimilar(configName, configsDefined)
1233+
}
12251234
if (configNameSimilar) {
12261235
assert(configNameSimilar !== configName)
1227-
errMsg = `${errMsg}, did you mean to define ${pc.bold(configNameSimilar)} instead?`
1236+
errMsg += `, did you mean to define ${pc.bold(configNameSimilar)} instead?`
1237+
}
1238+
if (configName === 'page') {
1239+
assert(configNameSimilar === 'Page')
1240+
errMsg += ` (The name of the config ${pc.bold('Page')} starts with a capital letter ${pc.bold(
1241+
'P'
1242+
)} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`
12281243
}
12291244
assertUsage(false, errMsg)
12301245
}

0 commit comments

Comments
 (0)
Please sign in to comment.