cleanup
This commit is contained in:
parent
78eea5bee0
commit
9735d8d82a
5 changed files with 12 additions and 72 deletions
39
src/cli.js
39
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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue