diff --git a/src/lib/findAtConfigPath.js b/src/lib/findAtConfigPath.js index 81bf9cae4..15d28efa8 100644 --- a/src/lib/findAtConfigPath.js +++ b/src/lib/findAtConfigPath.js @@ -3,13 +3,12 @@ import path from 'path' /** * Find the @config at-rule in the given CSS AST and return the relative path to the config file * - * * @param {import('postcss').Root} root * @param {import('postcss').Result} result */ export function findAtConfigPath(root, result) { let configPath = null - let relativeTo = root.source.input.file ?? result.opts.from ?? null + let relativeTo = root.source?.input.file ?? result.opts.from ?? null root.walkAtRules('config', (rule) => { if (relativeTo === undefined) { @@ -22,12 +21,19 @@ export function findAtConfigPath(root, result) { throw rule.error('Only `@config` at-rule is allowed per file.') } - configPath = rule.params.replace(/^['"]|['"]$/g, '') - rule.remove() + let matches = rule.params.match(/(['"])(.*?)\1/) + if (!matches) { + throw rule.error( + 'The `@config` at-rule must be followed by a string containing the path to the config file.' + ) + } + configPath = matches[2] if (path.isAbsolute(configPath)) { throw rule.error('The `@config` at-rule cannot be used with an absolute path.') } + + rule.remove() }) return configPath ? path.resolve(path.dirname(relativeTo), configPath) : null diff --git a/src/lib/setupTrackingContext.js b/src/lib/setupTrackingContext.js index 8c68e9f18..3e51bd9e1 100644 --- a/src/lib/setupTrackingContext.js +++ b/src/lib/setupTrackingContext.js @@ -25,8 +25,8 @@ function getCandidateFiles(context, tailwindConfig) { } // Get the config object based on a path -function getTailwindConfig(configOrPath, inputPath) { - let userConfigPath = resolveConfigPath(configOrPath, inputPath) +function getTailwindConfig(configOrPath) { + let userConfigPath = resolveConfigPath(configOrPath) if (userConfigPath !== null) { let [prevConfig, prevConfigHash, prevDeps, prevModified] = @@ -79,7 +79,7 @@ export default function setupTrackingContext(configOrPath) { return ({ tailwindDirectives, registerDependency }) => { return (root, result) => { let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = - getTailwindConfig(configOrPath, result.opts.from) + getTailwindConfig(configOrPath) let contextDependencies = new Set(configDependencies) diff --git a/src/util/normalizeConfig.js b/src/util/normalizeConfig.js index 70ff792fb..baee48394 100644 --- a/src/util/normalizeConfig.js +++ b/src/util/normalizeConfig.js @@ -59,7 +59,7 @@ export function normalizeConfig(config) { // Only `files`, `relative`, `extract`, and `transform` can exist in `config.content` if ( Object.keys(config.content).some( - (key) => !['files', 'extract', 'transform', 'relative'].includes(key) + (key) => !['files', 'relative', 'extract', 'transform'].includes(key) ) ) { return false diff --git a/src/util/resolveConfigPath.js b/src/util/resolveConfigPath.js index 24fda7b5e..646a46fd4 100644 --- a/src/util/resolveConfigPath.js +++ b/src/util/resolveConfigPath.js @@ -1,6 +1,5 @@ import fs from 'fs' import path from 'path' -import { flagEnabled } from '../featureFlags.js' function isObject(value) { return typeof value === 'object' && value !== null @@ -14,36 +13,7 @@ function isString(value) { return typeof value === 'string' || value instanceof String } -/** - * This will take a possibly-relative path to a config and resolve - * it relative to the input path IF that config file exists and - * has the `resolveConfigRelativeToInput` flag enabled. - * - * If that file does not exist, or the flag is disabled, it will - * resolve the path relative to the current working directory. - * - * @param {string|undefined} inputPath - * @param {string} configPath - * @returns {string} - */ -function pickResolvedPath(configPath, inputPath) { - if (path.isAbsolute(configPath)) { - return configPath - } - - if (inputPath) { - try { - // Use require.resolve so we can find config file in parent directories - return require.resolve(configPath, { - paths: [path.dirname(inputPath)], - }) - } catch {} - } - - return path.resolve(configPath) -} - -export default function resolveConfigPath(pathOrConfig, inputPath) { +export default function resolveConfigPath(pathOrConfig) { // require('tailwindcss')({ theme: ..., variants: ... }) if (isObject(pathOrConfig) && pathOrConfig.config === undefined && !isEmpty(pathOrConfig)) { return null @@ -55,10 +25,6 @@ export default function resolveConfigPath(pathOrConfig, inputPath) { pathOrConfig.config !== undefined && isString(pathOrConfig.config) ) { - // if (pathOrConfig.experimental?.contextualPaths) { - // return pickResolvedPath(pathOrConfig.config, inputPath) - // } - return path.resolve(pathOrConfig.config) }