(options: { cwd?: string; config?: Config; configPath?: string } = {})
| 28 | * Used by the CLI and PostCSS plugin. |
| 29 | */ |
| 30 | export async function loadConfigAndCreateContext(options: { cwd?: string; config?: Config; configPath?: string } = {}) { |
| 31 | const { config, configPath } = options |
| 32 | |
| 33 | const cwd = options.cwd ?? options?.config?.cwd ?? process.cwd() |
| 34 | const conf = await loadConfig({ cwd, file: configPath }) |
| 35 | |
| 36 | if (config) { |
| 37 | Object.assign(conf.config, config) |
| 38 | } |
| 39 | |
| 40 | if (options.cwd) { |
| 41 | conf.config.cwd = options.cwd |
| 42 | } |
| 43 | |
| 44 | if (conf.config.lightningcss && !conf.config.browserslist) { |
| 45 | conf.config.browserslist ||= browserslist.findConfig(cwd)?.defaults |
| 46 | } |
| 47 | |
| 48 | // Auto-inject built-in plugins (vue, svelte, lightningcss) |
| 49 | // Auto plugins run first, then the already-resolved user hooks run after |
| 50 | const autoPlugins = getAutoPlugins(conf.config) |
| 51 | |
| 52 | // conf.hooks is already properly merged from user plugins + inline hooks by resolveConfig. |
| 53 | // Prepend auto-plugins before it — don't re-process user plugins to avoid double-execution. |
| 54 | conf.hooks = mergeHooks([...autoPlugins, { name: RESOLVED_HOOKS_NAME, hooks: conf.hooks }]) |
| 55 | conf.config.plugins = [...autoPlugins, ...(conf.config.plugins ?? [])] |
| 56 | |
| 57 | const tsConfResult = await loadTsConfig(conf, cwd) |
| 58 | |
| 59 | if (tsConfResult) { |
| 60 | Object.assign(conf, tsConfResult) |
| 61 | } |
| 62 | |
| 63 | return new PandaContext(conf) |
| 64 | } |
no test coverage detected