Skip to content

Commit 05d4b42

Browse files
committed
simplify resolving of purge/content information
1 parent c8f2809 commit 05d4b42

5 files changed

+84
-227
lines changed

src/cli.js

+1-69
Original file line numberDiff line numberDiff line change
@@ -20,72 +20,6 @@ let env = {
2020
DEBUG: process.env.DEBUG !== undefined,
2121
}
2222

23-
let warned = false
24-
function resolveContentPaths(config) {
25-
if (config.hasOwnProperty('purge') && !warned) {
26-
log.warn([
27-
'The `purge` option in your tailwind.config.js file has been deprecated.',
28-
'Please rename this to `content` instead.',
29-
])
30-
warned = true
31-
}
32-
33-
if (Array.isArray(config.content)) {
34-
return config.content
35-
}
36-
37-
if (Array.isArray(config.content?.content)) {
38-
return config.content.content
39-
}
40-
41-
// TODO: Drop this in a future version
42-
if (Array.isArray(config.purge)) {
43-
return config.purge
44-
}
45-
46-
if (Array.isArray(config.purge?.content)) {
47-
return config.purge.content
48-
}
49-
50-
return []
51-
}
52-
53-
function resolveSafelistPaths(config) {
54-
if (config.hasOwnProperty('purge') && !warned) {
55-
log.warn([
56-
'The `purge` option in your tailwind.config.js file has been deprecated.',
57-
'Please rename this to `content` instead.',
58-
])
59-
warned = true
60-
}
61-
62-
let [key, content] = (() => {
63-
if (Array.isArray(config.content?.safelist)) {
64-
return ['content.safelist', config.content.safelist]
65-
}
66-
67-
if (Array.isArray(config.purge?.safelist)) {
68-
return ['purge.safelist', config.purge.safelist]
69-
}
70-
71-
return [null, []]
72-
})()
73-
74-
return content.map((content) => {
75-
if (typeof content === 'string') {
76-
return { raw: content, extension: 'html' }
77-
}
78-
79-
if (content instanceof RegExp) {
80-
throw new Error(`Values inside '${key}' can only be of type 'string', found 'regex'.`)
81-
}
82-
83-
throw new Error(
84-
`Values inside '${key}' can only be of type 'string', found '${typeof content}'.`
85-
)
86-
})
87-
}
88-
8923
// ---
9024

9125
function indentRecursive(node, indent = 0) {
@@ -498,9 +432,7 @@ async function build() {
498432
}
499433

500434
function extractContent(config) {
501-
let result = resolveContentPaths(config).concat(resolveSafelistPaths(config))
502-
console.log({ result })
503-
return result
435+
return config.content.content.concat(config.content.safelist)
504436
}
505437

506438
function extractFileGlobs(config) {

src/lib/expandTailwindAtRules.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const builtInTransformers = {
3030
}
3131

3232
function getExtractor(tailwindConfig, fileExtension) {
33-
let extractors = tailwindConfig?.content?.extract || tailwindConfig?.purge?.extract || {}
34-
let contentOptions = tailwindConfig?.content?.options || tailwindConfig?.purge?.options || {}
33+
let extractors = tailwindConfig.content.extract
34+
let contentOptions = tailwindConfig.content.options
3535

3636
if (typeof extractors === 'function') {
3737
extractors = {
@@ -56,7 +56,7 @@ function getExtractor(tailwindConfig, fileExtension) {
5656
}
5757

5858
function getTransformer(tailwindConfig, fileExtension) {
59-
let transformers = tailwindConfig?.content?.transform || tailwindConfig?.purge?.transform || {}
59+
let transformers = tailwindConfig.content.transform
6060

6161
if (typeof transformers === 'function') {
6262
transformers = {

src/lib/setupTrackingContext.js

+3-70
Original file line numberDiff line numberDiff line change
@@ -16,73 +16,6 @@ import { env } from './sharedState'
1616

1717
import { getContext, getFileModifiedMap } from './setupContextUtils'
1818
import parseDependency from '../util/parseDependency'
19-
import log from '../util/log'
20-
21-
let warned = false
22-
function resolveContentPaths(config) {
23-
if (config.hasOwnProperty('purge') && !warned) {
24-
log.warn([
25-
'The `purge` option in your tailwind.config.js file has been deprecated.',
26-
'Please rename this to `content` instead.',
27-
])
28-
warned = true
29-
}
30-
31-
if (Array.isArray(config.content)) {
32-
return config.content
33-
}
34-
35-
if (Array.isArray(config.content?.content)) {
36-
return config.content.content
37-
}
38-
39-
// TODO: Drop this in a future version
40-
if (Array.isArray(config.purge)) {
41-
return config.purge
42-
}
43-
44-
if (Array.isArray(config.purge?.content)) {
45-
return config.purge.content
46-
}
47-
48-
return []
49-
}
50-
51-
function resolveSafelistPaths(config) {
52-
if (config.hasOwnProperty('purge') && !warned) {
53-
log.warn([
54-
'The `purge` option in your tailwind.config.js file has been deprecated.',
55-
'Please rename this to `content` instead.',
56-
])
57-
warned = true
58-
}
59-
60-
let [key, content] = (() => {
61-
if (Array.isArray(config.content?.safelist)) {
62-
return ['content.safelist', config.content.safelist]
63-
}
64-
65-
if (Array.isArray(config.purge?.safelist)) {
66-
return ['purge.safelist', config.purge.safelist]
67-
}
68-
69-
return [null, []]
70-
})()
71-
72-
return content.map((content) => {
73-
if (typeof content === 'string') {
74-
return { raw: content, extension: 'html' }
75-
}
76-
77-
if (content instanceof RegExp) {
78-
throw new Error(`Values inside '${key}' can only be of type 'string', found 'regex'.`)
79-
}
80-
81-
throw new Error(
82-
`Values inside '${key}' can only be of type 'string', found '${typeof content}'.`
83-
)
84-
})
85-
}
8619

8720
let configPathCache = new LRU({ maxSize: 100 })
8821

@@ -93,7 +26,7 @@ function getCandidateFiles(context, tailwindConfig) {
9326
return candidateFilesCache.get(context)
9427
}
9528

96-
let candidateFiles = resolveContentPaths(tailwindConfig)
29+
let candidateFiles = tailwindConfig.content.content
9730
.filter((item) => typeof item === 'string')
9831
.map((contentPath) => normalizePath(path.resolve(contentPath)))
9932

@@ -144,9 +77,9 @@ function getTailwindConfig(configOrPath) {
14477
}
14578

14679
function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
147-
let changedContent = resolveContentPaths(context.tailwindConfig)
80+
let changedContent = context.tailwindConfig.content.content
14881
.filter((item) => typeof item.raw === 'string')
149-
.concat(resolveSafelistPaths(context.tailwindConfig))
82+
.concat(context.tailwindConfig.content.safelist)
15083
.map(({ raw, extension }) => ({ content: raw, extension }))
15184

15285
for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {

src/lib/setupWatchingContext.js

+3-69
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,6 @@ import resolveConfig from '../../resolveConfig'
1414
import resolveConfigPath from '../util/resolveConfigPath'
1515
import { getContext } from './setupContextUtils'
1616

17-
let warned = false
18-
function resolveContentPaths(config) {
19-
if (config.hasOwnProperty('purge') && !warned) {
20-
log.warn([
21-
'The `purge` option in your tailwind.config.js file has been deprecated.',
22-
'Please rename this to `content` instead.',
23-
])
24-
warned = true
25-
}
26-
27-
if (Array.isArray(config.content)) {
28-
return config.content
29-
}
30-
31-
if (Array.isArray(config.content?.content)) {
32-
return config.content.content
33-
}
34-
35-
// TODO: Drop this in a future version
36-
if (Array.isArray(config.purge)) {
37-
return config.purge
38-
}
39-
40-
if (Array.isArray(config.purge?.content)) {
41-
return config.purge.content
42-
}
43-
44-
return []
45-
}
46-
47-
function resolveSafelistPaths(config) {
48-
if (config.hasOwnProperty('purge') && !warned) {
49-
log.warn([
50-
'The `purge` option in your tailwind.config.js file has been deprecated.',
51-
'Please rename this to `content` instead.',
52-
])
53-
warned = true
54-
}
55-
56-
let [key, content] = (() => {
57-
if (Array.isArray(config.content?.safelist)) {
58-
return ['content.safelist', config.content.safelist]
59-
}
60-
61-
if (Array.isArray(config.purge?.safelist)) {
62-
return ['purge.safelist', config.purge.safelist]
63-
}
64-
65-
return [null, []]
66-
})()
67-
68-
return content.map((content) => {
69-
if (typeof content === 'string') {
70-
return { raw: content, extension: 'html' }
71-
}
72-
73-
if (content instanceof RegExp) {
74-
throw new Error(`Values inside '${key}' can only be of type 'string', found 'regex'.`)
75-
}
76-
77-
throw new Error(
78-
`Values inside '${key}' can only be of type 'string', found '${typeof content}'.`
79-
)
80-
})
81-
}
82-
8317
// This is used to trigger rebuilds. Just updating the timestamp
8418
// is significantly faster than actually writing to the file (10x).
8519

@@ -213,7 +147,7 @@ function getCandidateFiles(context, tailwindConfig) {
213147
return candidateFilesCache.get(context)
214148
}
215149

216-
let candidateFiles = resolveContentPaths(tailwindConfig)
150+
let candidateFiles = tailwindConfig.content.content
217151
.filter((item) => typeof item === 'string')
218152
.map((contentPath) => normalizePath(path.resolve(contentPath)))
219153

@@ -251,9 +185,9 @@ function getTailwindConfig(configOrPath) {
251185
}
252186

253187
function resolvedChangedContent(context, candidateFiles) {
254-
let changedContent = resolveContentPaths(context.tailwindConfig)
188+
let changedContent = context.tailwindConfig.content.content
255189
.filter((item) => typeof item.raw === 'string')
256-
.concat(resolveSafelistPaths(context.tailwindConfig))
190+
.concat(context.tailwindConfig.content.safelist)
257191
.map(({ raw, extension }) => ({ content: raw, extension }))
258192

259193
for (let changedFile of resolveChangedFiles(context, candidateFiles)) {

0 commit comments

Comments
 (0)