Resolve purge paths relative to the current working directory (#4655)

* resolve purge paths relative to cwd

* simplify test
This commit is contained in:
Brad Cornes 2021-06-15 21:37:04 +01:00 • committed by GitHub
parent 38a71d8d60
commit 243e8814d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 31 deletions

View file

@ -92,7 +92,7 @@ module.exports = function tailwindcss(config) {
return {
postcssPlugin: 'tailwindcss',
plugins: [...plugins, processTailwindFeatures(getConfig, resolvedConfigPath), formatCSS],
plugins: [...plugins, processTailwindFeatures(getConfig), formatCSS],
}
}

View file

@ -21,7 +21,7 @@ let configPathCache = new LRU({ maxSize: 100 })
let candidateFilesCache = new WeakMap()
function getCandidateFiles(context, userConfigPath, tailwindConfig) {
function getCandidateFiles(context, tailwindConfig) {
if (candidateFilesCache.has(context)) {
return candidateFilesCache.get(context)
}
@ -30,10 +30,9 @@ function getCandidateFiles(context, userConfigPath, tailwindConfig) {
? tailwindConfig.purge
: tailwindConfig.purge.content
let basePath = userConfigPath === null ? process.cwd() : path.dirname(userConfigPath)
let candidateFiles = purgeContent
.filter((item) => typeof item === 'string')
.map((purgePath) => normalizePath(path.resolve(basePath, purgePath)))
.map((purgePath) => normalizePath(path.resolve(purgePath)))
return candidateFilesCache.set(context, candidateFiles).get(context)
}
@ -172,7 +171,7 @@ export default function setupTrackingContext(configOrPath) {
contextDependencies
)
let candidateFiles = getCandidateFiles(context, userConfigPath, tailwindConfig)
let candidateFiles = getCandidateFiles(context, tailwindConfig)
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
// to be dependencies of the context. Can reuse the context even if they change.

View file

@ -142,7 +142,7 @@ function getConfigDependencies(context) {
let candidateFilesCache = new WeakMap()
function getCandidateFiles(context, userConfigPath, tailwindConfig) {
function getCandidateFiles(context, tailwindConfig) {
if (candidateFilesCache.has(context)) {
return candidateFilesCache.get(context)
}
@ -151,10 +151,9 @@ function getCandidateFiles(context, userConfigPath, tailwindConfig) {
? tailwindConfig.purge
: tailwindConfig.purge.content
let basePath = userConfigPath === null ? process.cwd() : path.dirname(userConfigPath)
let candidateFiles = purgeContent
.filter((item) => typeof item === 'string')
.map((purgePath) => normalizePath(path.resolve(basePath, purgePath)))
.map((purgePath) => normalizePath(path.resolve(purgePath)))
return candidateFilesCache.set(context, candidateFiles).get(context)
}
@ -282,7 +281,7 @@ export default function setupWatchingContext(configOrPath) {
contextDependencies
)
let candidateFiles = getCandidateFiles(context, userConfigPath, tailwindConfig)
let candidateFiles = getCandidateFiles(context, tailwindConfig)
let contextConfigDependencies = getConfigDependencies(context)
for (let file of configDependencies) {

View file

@ -48,12 +48,7 @@ function getTransformer(config, fileExtension) {
return transformers[fileExtension] || transformers.DEFAULT || ((content) => content)
}
export default function purgeUnusedUtilities(
config,
configChanged,
resolvedConfigPath,
registerDependency
) {
export default function purgeUnusedUtilities(config, configChanged, registerDependency) {
const purgeEnabled = _.get(
config,
'purge.enabled',
@ -130,9 +125,7 @@ export default function purgeUnusedUtilities(
Array.isArray(config.purge) ? config.purge : config.purge.content || purgeOptions.content || []
).map((item) => {
if (typeof item === 'string') {
return normalizePath(
path.resolve(resolvedConfigPath ? path.dirname(resolvedConfigPath) : process.cwd(), item)
)
return normalizePath(path.resolve(item))
}
return item
})

View file

@ -24,7 +24,7 @@ let previousConfig = null
let processedPlugins = null
let getProcessedPlugins = null
export default function (getConfig, resolvedConfigPath) {
export default function (getConfig) {
return function (css, result) {
const config = getConfig()
const configChanged = hash(previousConfig) !== hash(config)
@ -73,7 +73,7 @@ export default function (getConfig, resolvedConfigPath) {
substituteScreenAtRules({ tailwindConfig: config }),
substituteClassApplyAtRules(config, getProcessedPlugins, configChanged),
applyImportantConfiguration(config),
purgeUnusedStyles(config, configChanged, resolvedConfigPath, registerDependency),
purgeUnusedStyles(config, configChanged, registerDependency),
]).process(css, { from: _.get(css, 'source.input.file') })
}
}