Skip to content

Commit

Permalink
fix: enforce Vike extension conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jun 4, 2024
1 parent 2c361cc commit be770f2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,46 @@ async function loadInterfaceFiles(
} else {
assertUsage(extensionNameValue, warnMsg)
}
{
const { filePathToShowToUserResolved } = interfaceFile.filePath
assert(filePathToShowToUserResolved)
const errPrefix = `The setting ${pc.bold('name')} defined at ${filePathToShowToUserResolved}`
assertUsage(typeof extensionNameValue === 'string', `${errPrefix} should be a string`)
assertWarning(
extensionNameValue === extensionName,
`${errPrefix} is ${pc.bold(extensionNameValue)} but it should be ${pc.bold(extensionName)} instead`,
{ onlyOnce: true }
)
}
{
const importPathAbsoluteExpected = `${extensionName}/config`
assertWarning(
importPathAbsolute === importPathAbsoluteExpected,
`The Vike configuration of ${extensionName} is exported at ${pc.bold(
importPathAbsolute
)} but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead`,
{ onlyOnce: true }
)
}
if (extensionName.startsWith('vike-')) {
const prefix = [
//
'vike-react',
'vike-vue',
'vike-solid',
'vike-svelte',
'vike-angular',
'vike-preact'
]
assertWarning(
prefix.some((p) => extensionName === p || extensionName.startsWith(`${p}-`)),
`The name of the Vike extension ${pc.bold(extensionName)} should be or start with ${joinEnglish(
prefix.map(pc.bold),
'or'
)}`,
{ onlyOnce: true }
)
}
}
interfaceFilesByLocationId[locationId]!.push(interfaceFile)
})
Expand Down

0 comments on commit be770f2

Please sign in to comment.