mirror of
https://github.com/honojs/hono.git
synced 2024-11-24 02:07:30 +01:00
a6ccfa29ca
* feat(build): for both exports to be the same * some fix * fix exclude of coverage * update * stylish error message and add comment * revert auto lint * chore: format
38 lines
952 B
TypeScript
38 lines
952 B
TypeScript
export const validateExports = (
|
|
source: Record<string, unknown>,
|
|
target: Record<string, unknown>,
|
|
fileName: string
|
|
) => {
|
|
const isEntryInTarget = (entry: string): boolean => {
|
|
if (entry in target) {
|
|
return true
|
|
}
|
|
|
|
// e.g., "./utils/*" -> "./utils"
|
|
const wildcardPrefix = entry.replace(/\/\*$/, '')
|
|
if (entry.endsWith('/*')) {
|
|
return Object.keys(target).some(
|
|
(targetEntry) =>
|
|
targetEntry.startsWith(wildcardPrefix + '/') && targetEntry !== wildcardPrefix
|
|
)
|
|
}
|
|
|
|
const separatedEntry = entry.split('/')
|
|
while (separatedEntry.length > 0) {
|
|
const pattern = `${separatedEntry.join('/')}/*`
|
|
if (pattern in target) {
|
|
return true
|
|
}
|
|
separatedEntry.pop()
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
Object.keys(source).forEach((sourceEntry) => {
|
|
if (!isEntryInTarget(sourceEntry)) {
|
|
throw new Error(`Missing "${sourceEntry}" in '${fileName}'`)
|
|
}
|
|
})
|
|
}
|