Skip to content

Commit

Permalink
Only process plugins once
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Jun 26, 2018
1 parent b21d258 commit 9b22ff3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
3 changes: 2 additions & 1 deletion __tests__/variantsAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteVariantsAtRules'
import config from '../defaultConfig.stub.js'
import processPlugins from '../src/util/processPlugins'

function run(input, opts = config) {
return postcss([plugin(opts)]).process(input, { from: undefined })
return postcss([plugin(opts, processPlugins(opts))]).process(input, { from: undefined })
}

test('it can generate hover variants', () => {
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import registerConfigAsDependency from './lib/registerConfigAsDependency'
import processTailwindFeatures from './processTailwindFeatures'
import mergeConfigWithDefaults from './util/mergeConfigWithDefaults'


const plugin = postcss.plugin('tailwind', config => {
const plugins = []

Expand Down
7 changes: 1 addition & 6 deletions src/lib/substituteTailwindAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ import postcss from 'postcss'
import utilityModules from '../utilityModules'
import prefixTree from '../util/prefixTree'
import generateModules from '../util/generateModules'
import processPlugins from '../util/processPlugins'

export default function(config) {
export default function(config, { components: pluginComponents, utilities: pluginUtilities }) {
return function(css) {
const { components: pluginComponents, utilities: pluginUtilities } = processPlugins(
config
)

css.walkAtRules('tailwind', atRule => {
if (atRule.params === 'preflight') {
const preflightTree = postcss.parse(
Expand Down
5 changes: 2 additions & 3 deletions src/lib/substituteVariantsAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'lodash'
import postcss from 'postcss'
import buildSelectorVariant from '../util/buildSelectorVariant'
import generateVariantFunction from '../util/generateVariantFunction'
import processPlugins from '../util/processPlugins'

function generatePseudoClassVariant(pseudoClass) {
return generateVariantFunction(({ className, separator }) => {
Expand All @@ -29,11 +28,11 @@ const defaultVariantGenerators = {
active: generatePseudoClassVariant('active'),
}

export default function(config) {
export default function(config, { variantGenerators: pluginVariantGenerators }) {
return function(css) {
const variantGenerators = {
...defaultVariantGenerators,
...processPlugins(config).variantGenerators,
...pluginVariantGenerators,
}

css.walkAtRules('variants', atRule => {
Expand Down
10 changes: 4 additions & 6 deletions src/processTailwindFeatures.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import path from 'path'

import _ from 'lodash'
import postcss from 'postcss'

import registerConfigAsDependency from './lib/registerConfigAsDependency'
import substituteTailwindAtRules from './lib/substituteTailwindAtRules'
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
import substituteVariantsAtRules from './lib/substituteVariantsAtRules'
import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
import substituteScreenAtRules from './lib/substituteScreenAtRules'
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
import processPlugins from './util/processPlugins'

export default function(lazyConfig) {
const config = lazyConfig()
const plugins = processPlugins(config)

return postcss([
substituteTailwindAtRules(config),
substituteTailwindAtRules(config, plugins),
evaluateTailwindFunctions(config),
substituteVariantsAtRules(config),
substituteVariantsAtRules(config, plugins),
substituteResponsiveAtRules(config),
substituteScreenAtRules(config),
substituteClassApplyAtRules(config),
Expand Down

0 comments on commit 9b22ff3

Please sign in to comment.