Skip to content

Commit 0313f02

Browse files
Move some config error checking out of resolveConfig (#8362)
1 parent 638c8f4 commit 0313f02

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import getModuleDependencies from './lib/getModuleDependencies'
1717
import log from './util/log'
1818
import packageJson from '../package.json'
1919
import normalizePath from 'normalize-path'
20+
import { validateConfig } from './util/validateConfig.js'
2021

2122
let env = {
2223
DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0',
@@ -490,10 +491,13 @@ async function build() {
490491
let files = args['--content'].split(/(?<!{[^}]+),/)
491492
let resolvedConfig = resolveConfigInternal(config, { content: { files } })
492493
resolvedConfig.content.files = files
494+
resolvedConfig = validateConfig(resolvedConfig)
493495
return resolvedConfig
494496
}
495497

496-
return resolveConfigInternal(config)
498+
let resolvedConfig = resolveConfigInternal(config)
499+
resolvedConfig = validateConfig(resolvedConfig)
500+
return resolvedConfig
497501
}
498502

499503
function extractFileGlobs(config) {

src/lib/setupTrackingContext.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { env } from './sharedState'
1616

1717
import { getContext, getFileModifiedMap } from './setupContextUtils'
1818
import parseDependency from '../util/parseDependency'
19+
import { validateConfig } from '../util/validateConfig.js'
1920

2021
let configPathCache = new LRU({ maxSize: 100 })
2122

@@ -63,6 +64,7 @@ function getTailwindConfig(configOrPath) {
6364
delete require.cache[file]
6465
}
6566
let newConfig = resolveConfig(require(userConfigPath))
67+
newConfig = validateConfig(newConfig)
6668
let newHash = hash(newConfig)
6769
configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
6870
return [newConfig, userConfigPath, newHash, newDeps]
@@ -73,6 +75,8 @@ function getTailwindConfig(configOrPath) {
7375
configOrPath.config === undefined ? configOrPath : configOrPath.config
7476
)
7577

78+
newConfig = validateConfig(newConfig)
79+
7680
return [newConfig, null, hash(newConfig), []]
7781
}
7882

src/util/normalizeConfig.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,5 @@ export function normalizeConfig(config) {
258258
}
259259
}
260260

261-
if (config.content.files.length === 0) {
262-
log.warn('content-problems', [
263-
'The `content` option in your Tailwind CSS configuration is missing or empty.',
264-
'Configure your content sources or your generated CSS will be missing styles.',
265-
'https://tailwindcss.com/docs/content-configuration',
266-
])
267-
}
268-
269261
return config
270262
}

src/util/validateConfig.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import log from './log'
2+
3+
export function validateConfig(config) {
4+
if (config.content.files.length === 0) {
5+
log.warn('content-problems', [
6+
'The `content` option in your Tailwind CSS configuration is missing or empty.',
7+
'Configure your content sources or your generated CSS will be missing styles.',
8+
'https://tailwindcss.com/docs/content-configuration',
9+
])
10+
}
11+
12+
return config
13+
}

0 commit comments

Comments
 (0)