Skip to content

Commit

Permalink
chore(fix): stop relying on non-standard vite.sortVitePlugins function
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed May 25, 2024
1 parent 3f51bd2 commit 401e1b1
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/core/getSausPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ export async function getSausPlugins(
config: vite.ResolvedConfig = context.config
) {
const sausPlugins: SausPlugin[] = []
for (const p of flattenPlugins(config.plugins, p => {
if (!p || !p.saus) {
return false
for (const p of config.plugins) {
if (!p || !p.saus || !isApplicablePlugin(p, config)) {
continue
}
if (typeof p.apply == 'function') {
return p.apply(config.inlineConfig, {
command: config.command,
mode: config.mode,
})
}
return !p.apply || p.apply == config.command
})) {

const sausPlugin =
typeof p.saus == 'function' ? await p.saus(context, config) : p.saus!

Expand All @@ -29,10 +22,12 @@ export async function getSausPlugins(
return sausPlugins
}

function flattenPlugins<T extends vite.Plugin>(
plugins: readonly T[],
filter?: (p: T) => any
) {
const filtered: vite.Plugin[] = filter ? plugins.filter(filter) : [...plugins]
return vite.sortVitePlugins(filtered).flat() as T[]
function isApplicablePlugin(p: vite.Plugin, config: vite.ResolvedConfig) {
if (typeof p.apply == 'function') {
return p.apply(config.inlineConfig, {
command: config.command,
mode: config.mode,
})
}
return p.apply == null || p.apply == config.command
}

0 comments on commit 401e1b1

Please sign in to comment.