/
githubmirror
/
tailwindcss
Обзор
Документация
Войти
/
githubmirror
/
tailwindcss
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v3.4.19
src/lib/load-config.ts
46 строк
1 KB
Jordan Pittman
Fix native ESM config loading in v3 (#18938)
16 сен 2025, 21:03
Не верифицирован
16 сен 2025, 21:03
ba55a44
Код
Авторство
О чём код?
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) => { // Sucrase can't transform import.meta so we have to use Babel if (opts.source.includes('import.meta')) { return require('jiti/dist/babel.js')(opts) } return transform(opts.source, { transforms: ['typescript', 'imports'], }) }, })) ) } export function loadConfig(path: string): Config { let config = (function () { if (!path) return {} try { return require(path) } catch { return lazyJiti()(path) } })() return config.default ?? config }