Skip to content

Commit 4041c86

Browse files
authored
Ensure --content is used in the CLI when passed (#9587)
* update changelog * ensure `--content` is taken into account * cleanup tests - Use `rm` instead of deprecated `rmdir` - Type the returnType correctly * use a file not included in `content` of your tailwind.config.js file
1 parent 6f77caa commit 4041c86

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5757
- Improve type checking for formal syntax ([#9349](https://github.com/tailwindlabs/tailwindcss/pull/9349), [#9448](https://github.com/tailwindlabs/tailwindcss/pull/9448))
5858
- Don't require `content` key in custom plugin configs ([#9502](https://github.com/tailwindlabs/tailwindcss/pull/9502), [#9545](https://github.com/tailwindlabs/tailwindcss/pull/9545))
5959
- Fix content path detection on Windows ([#9569](https://github.com/tailwindlabs/tailwindcss/pull/9569))
60+
- Ensure `--content` is used in the CLI when passed ([#9587](https://github.com/tailwindlabs/tailwindcss/pull/9587))
6061

6162
## [3.1.8] - 2022-08-05
6263

integrations/tailwindcss-cli/tests/cli.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ describe('Build command', () => {
169169
})
170170

171171
test('--content', async () => {
172-
await writeInputFile('index.html', html`<div class="font-bold"></div>`)
172+
await writeInputFile('other.html', html`<div class="font-bold"></div>`)
173173

174-
await $(`${EXECUTABLE} --content ./src/index.html --output ./dist/main.css`)
174+
await $(`${EXECUTABLE} --content ./src/other.html --output ./dist/main.css`)
175175

176176
expect(await readOutputFile('main.css')).toIncludeCss(
177177
css`

src/cli/build/plugin.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { parseCandidateFiles } from '../../lib/content.js'
1717
import { createWatcher } from './watching.js'
1818
import fastGlob from 'fast-glob'
1919
import { findAtConfigPath } from '../../lib/findAtConfigPath.js'
20+
import log from '../../util/log'
2021

2122
/**
2223
*
@@ -139,7 +140,7 @@ let state = {
139140
}
140141
},
141142

142-
loadConfig(configPath) {
143+
loadConfig(configPath, content) {
143144
if (this.watcher && configPath) {
144145
this.refreshConfigDependencies(configPath)
145146
}
@@ -149,6 +150,11 @@ let state = {
149150
// @ts-ignore
150151
config = resolveConfig(config, { content: { files: [] } })
151152

153+
// Override content files if `--content` has been passed explicitly
154+
if (content?.length > 0) {
155+
config.content.files = content
156+
}
157+
152158
return config
153159
},
154160

@@ -196,7 +202,7 @@ let state = {
196202
return content
197203
},
198204

199-
getContext({ createContext, cliConfigPath, root, result }) {
205+
getContext({ createContext, cliConfigPath, root, result, content }) {
200206
if (this.context) {
201207
this.context.changedContent = this.changedContent.splice(0)
202208

@@ -208,7 +214,7 @@ let state = {
208214
env.DEBUG && console.timeEnd('Searching for config')
209215

210216
env.DEBUG && console.time('Loading config')
211-
let config = this.loadConfig(configPath)
217+
let config = this.loadConfig(configPath, content)
212218
env.DEBUG && console.timeEnd('Loading config')
213219

214220
env.DEBUG && console.time('Creating context')
@@ -250,6 +256,19 @@ export async function createProcessor(args, cliConfigPath) {
250256
? await loadPostCssPlugins(customPostCssPath)
251257
: loadBuiltinPostcssPlugins()
252258

259+
if (args['--purge']) {
260+
log.warn('purge-flag-deprecated', [
261+
'The `--purge` flag has been deprecated.',
262+
'Please use `--content` instead.',
263+
])
264+
265+
if (!args['--content']) {
266+
args['--content'] = args['--purge']
267+
}
268+
}
269+
270+
let content = args['--content']?.split(/(?<!{[^}]+),/) ?? []
271+
253272
let tailwindPlugin = () => {
254273
return {
255274
postcssPlugin: 'tailwindcss',
@@ -260,7 +279,13 @@ export async function createProcessor(args, cliConfigPath) {
260279
console.error('Rebuilding...')
261280

262281
return () => {
263-
return state.getContext({ createContext, cliConfigPath, root, result })
282+
return state.getContext({
283+
createContext,
284+
cliConfigPath,
285+
root,
286+
result,
287+
content,
288+
})
264289
}
265290
})(root, result)
266291
env.DEBUG && console.timeEnd('Compiling CSS')

standalone-cli/tests/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ it('supports postcss config files', async () => {
5151
/**
5252
* @template T
5353
* @param {() => T} fn
54-
* @returns {T}
54+
* @returns {Promise<T>}
5555
*/
5656
async function inIsolatedContext(fn) {
5757
// Create a new directory entirely outside of the package for the test
@@ -79,6 +79,6 @@ async function inIsolatedContext(fn) {
7979
process.chdir(__dirname)
8080

8181
// Delete the new directory
82-
await fs.rmdir(dest, { recursive: true })
82+
await fs.rm(dest, { recursive: true })
8383
}
8484
}

0 commit comments

Comments
 (0)