Move some config error checking out of resolveConfig (#8362)

This commit is contained in:
Jordan Pittman 2022-05-16 10:10:40 -04:00 committed by GitHub
parent 638c8f43ea
commit 0313f02e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 9 deletions

View File

@ -17,6 +17,7 @@ import getModuleDependencies from './lib/getModuleDependencies'
import log from './util/log'
import packageJson from '../package.json'
import normalizePath from 'normalize-path'
import { validateConfig } from './util/validateConfig.js'
let env = {
DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0',
@ -490,10 +491,13 @@ async function build() {
let files = args['--content'].split(/(?<!{[^}]+),/)
let resolvedConfig = resolveConfigInternal(config, { content: { files } })
resolvedConfig.content.files = files
resolvedConfig = validateConfig(resolvedConfig)
return resolvedConfig
}
return resolveConfigInternal(config)
let resolvedConfig = resolveConfigInternal(config)
resolvedConfig = validateConfig(resolvedConfig)
return resolvedConfig
}
function extractFileGlobs(config) {

View File

@ -16,6 +16,7 @@ import { env } from './sharedState'
import { getContext, getFileModifiedMap } from './setupContextUtils'
import parseDependency from '../util/parseDependency'
import { validateConfig } from '../util/validateConfig.js'
let configPathCache = new LRU({ maxSize: 100 })
@ -63,6 +64,7 @@ function getTailwindConfig(configOrPath) {
delete require.cache[file]
}
let newConfig = resolveConfig(require(userConfigPath))
newConfig = validateConfig(newConfig)
let newHash = hash(newConfig)
configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
return [newConfig, userConfigPath, newHash, newDeps]
@ -73,6 +75,8 @@ function getTailwindConfig(configOrPath) {
configOrPath.config === undefined ? configOrPath : configOrPath.config
)
newConfig = validateConfig(newConfig)
return [newConfig, null, hash(newConfig), []]
}

View File

@ -258,13 +258,5 @@ export function normalizeConfig(config) {
}
}
if (config.content.files.length === 0) {
log.warn('content-problems', [
'The `content` option in your Tailwind CSS configuration is missing or empty.',
'Configure your content sources or your generated CSS will be missing styles.',
'https://tailwindcss.com/docs/content-configuration',
])
}
return config
}

View File

@ -0,0 +1,13 @@
import log from './log'
export function validateConfig(config) {
if (config.content.files.length === 0) {
log.warn('content-problems', [
'The `content` option in your Tailwind CSS configuration is missing or empty.',
'Configure your content sources or your generated CSS will be missing styles.',
'https://tailwindcss.com/docs/content-configuration',
])
}
return config
}