simplify built-in plugin finder

master
Brad Cornes 2020-04-29 19:46:36 +01:00
parent 2cd29c13d6
commit 82dad05540
2 changed files with 6 additions and 13 deletions

View File

@ -3,21 +3,14 @@ import stackTrace from 'stack-trace'
import pkgUp from 'pkg-up' import pkgUp from 'pkg-up'
import { glob } from './glob' import { glob } from './glob'
import { isObject } from './isObject' import { isObject } from './isObject'
import importFrom from 'import-from'
export async function getBuiltInPlugins(cwd) { export async function getBuiltInPlugins({ cwd, resolvedConfig }) {
try { try {
// TODO: just require('tailwindcss/lib/corePlugins.js') instead of globbing
// TODO: add v0 support ("generators") // TODO: add v0 support ("generators")
return ( return importFrom(cwd, 'tailwindcss/lib/corePlugins.js').default({
await glob(path.resolve(cwd, 'node_modules/tailwindcss/lib/plugins/*.js')) corePlugins: resolvedConfig.corePlugins,
)
.map((x) => {
try {
const mod = __non_webpack_require__(x)
return mod.default ? mod.default() : mod()
} catch (_) {}
}) })
.filter(Boolean)
} catch (_) { } catch (_) {
return [] return []
} }

View File

@ -19,7 +19,7 @@ const proxyHandler = (base = []) => ({
}) })
export async function getUtilityConfigMap({ cwd, resolvedConfig, postcss }) { export async function getUtilityConfigMap({ cwd, resolvedConfig, postcss }) {
const builtInPlugins = await getBuiltInPlugins(cwd) const builtInPlugins = await getBuiltInPlugins({ cwd, resolvedConfig })
const userPlugins = Array.isArray(resolvedConfig.plugins) const userPlugins = Array.isArray(resolvedConfig.plugins)
? resolvedConfig.plugins ? resolvedConfig.plugins
: [] : []