astro-ghostcms/.pnpm-store/v3/files/52/99aee1a6a0fbe592a11de4e946c...

40 lines
859 B
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
import jitiFactory from 'jiti'
import { transform } from 'sucrase'
import { Config } from '../../types/config'
let jiti: ReturnType<typeof jitiFactory> | null = null
// @internal
// This WILL be removed in some future release
// If you rely on this your stuff WILL break
export function useCustomJiti(_jiti: () => ReturnType<typeof jitiFactory>) {
jiti = _jiti()
}
function lazyJiti() {
return (
jiti ??
(jiti = jitiFactory(__filename, {
interopDefault: true,
transform: (opts) => {
return transform(opts.source, {
transforms: ['typescript', 'imports'],
})
},
}))
)
}
export function loadConfig(path: string): Config {
let config = (function () {
try {
return path ? require(path) : {}
} catch {
return lazyJiti()(path)
}
})()
return config.default ?? config
}