From 9735d8d82ae0b8f69421b69f426f7bc63a65a3ad Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 22 Sep 2022 09:31:19 -0400 Subject: [PATCH] cleanup --- src/cli.js | 39 ++++++--------------------------- src/lib/findAtConfigPath.js | 1 - src/lib/setupTrackingContext.js | 6 ++--- src/util/normalizeConfig.js | 2 +- src/util/resolveConfigPath.js | 36 +----------------------------- 5 files changed, 12 insertions(+), 72 deletions(-) diff --git a/src/cli.js b/src/cli.js index 5f4bad74a..c9d6ab7c0 100644 --- a/src/cli.js +++ b/src/cli.js @@ -435,31 +435,12 @@ async function build() { process.exit(9) } - let configPath - - if (args['--config']) { - // The user has specified an exact config file to use - // So we want to use that one and only that one - configPath = path.resolve(args['--config']) - } else { - let postcssOptions = { - config: `./${configs.tailwind}`, - experimental: { - contextualPaths: args['--experimental-contextual-paths'], - }, - } - - // The user has not specified an exact config file to use - // So we want to find the closest one to the input file - // when experimental contextual paths are enabled - let maybeConfigPath = resolveConfigPath(postcssOptions, input ? path.resolve(input) : null) - - if (fs.existsSync(maybeConfigPath)) { - configPath = maybeConfigPath - } else { - configPath = null - } - } + // TODO: Reference the @config path here if exists + let configPath = args['--config'] + ? args['--config'] + : ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))( + path.resolve(`./${configs.tailwind}`) + ) async function loadPostCssPlugins() { let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined @@ -578,14 +559,8 @@ async function build() { function extractFileGlobs(config) { let context = { + tailwindConfig: config, userConfigPath: configPath, - postcssOptions: args['--experimental-contextual-paths'] - ? { - experimental: { - contextualPaths: true, - }, - } - : {}, } let contentPaths = parseCandidateFiles(context, config) diff --git a/src/lib/findAtConfigPath.js b/src/lib/findAtConfigPath.js index 81bf9cae4..22702bc2c 100644 --- a/src/lib/findAtConfigPath.js +++ b/src/lib/findAtConfigPath.js @@ -3,7 +3,6 @@ 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 */ 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) }