From ed7c448441f4b8cef25f9a215dff5328d1414dd0 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 15 Jun 2023 12:13:05 -0400 Subject: [PATCH] Push CSS-based theme resolution inside getTailwindConfig --- src/lib/parseCssConfig.js | 5 +++-- src/lib/setupTrackingContext.js | 6 +++++- src/plugin.js | 5 +---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/parseCssConfig.js b/src/lib/parseCssConfig.js index fbef1387d..36921ebc7 100644 --- a/src/lib/parseCssConfig.js +++ b/src/lib/parseCssConfig.js @@ -5,8 +5,9 @@ */ export class CssBasedConfig { - /** @type {*} */ - config = {}; + constructor() { + this.config = {} + } /** * Find and convert the `:theme` rule to a configuration object diff --git a/src/lib/setupTrackingContext.js b/src/lib/setupTrackingContext.js index ba4d9c228..550914be0 100644 --- a/src/lib/setupTrackingContext.js +++ b/src/lib/setupTrackingContext.js @@ -12,6 +12,7 @@ import { validateConfig } from '../util/validateConfig.js' import { parseCandidateFiles, resolvedChangedContent } from './content.js' import { loadConfig } from '../lib/load-config' import getModuleDependencies from './getModuleDependencies' +import { CssBasedConfig } from './parseCssConfig.js' let configPathCache = new LRU({ maxSize: 100 }) @@ -80,9 +81,12 @@ function getTailwindConfig(configOrPath, cssThemeValues = {}) { // Retrieve an existing context from cache if possible (since contexts are unique per // source path), or set up a new one (including setting up watchers and registering // plugins) then return it -export default function setupTrackingContext(configOrPath, cssThemeValues = {}) { +export default function setupTrackingContext(configOrPath) { return ({ tailwindDirectives, registerDependency }) => { return (root, result) => { + // Parse any CSS-based config values from `:theme` rules + let cssThemeValues = new CssBasedConfig().parse(root) + let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath, cssThemeValues) diff --git a/src/plugin.js b/src/plugin.js index fb53e43bb..4fcb058f3 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -24,10 +24,7 @@ module.exports = function tailwindcss(configOrPath) { // path for the file being processed configOrPath = findAtConfigPath(root, result) ?? configOrPath - // Parse any CSS-based config values from `:theme` rules - let themeValues = new CssBasedConfig().parse(root) - - let context = setupTrackingContext(configOrPath, themeValues) + let context = setupTrackingContext(configOrPath) if (root.type === 'document') { let roots = root.nodes.filter((node) => node.type === 'root')