Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure --content is used in the CLI when passed #9587

Merged
merged 4 commits into from Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve type checking for formal syntax ([#9349](https://github.com/tailwindlabs/tailwindcss/pull/9349), [#9448](https://github.com/tailwindlabs/tailwindcss/pull/9448))
- 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))
- Fix content path detection on Windows ([#9569](https://github.com/tailwindlabs/tailwindcss/pull/9569))
- Ensure `--content` is used in the CLI when passed ([#9587](https://github.com/tailwindlabs/tailwindcss/pull/9587))

## [3.1.8] - 2022-08-05

Expand Down
4 changes: 2 additions & 2 deletions integrations/tailwindcss-cli/tests/cli.test.js
Expand Up @@ -169,9 +169,9 @@ describe('Build command', () => {
})

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

await $(`${EXECUTABLE} --content ./src/index.html --output ./dist/main.css`)
await $(`${EXECUTABLE} --content ./src/other.html --output ./dist/main.css`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no 🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, haha it was in tailwind.config.js so worked fine 😅


expect(await readOutputFile('main.css')).toIncludeCss(
css`
Expand Down
33 changes: 29 additions & 4 deletions src/cli/build/plugin.js
Expand Up @@ -17,6 +17,7 @@ import { parseCandidateFiles } from '../../lib/content.js'
import { createWatcher } from './watching.js'
import fastGlob from 'fast-glob'
import { findAtConfigPath } from '../../lib/findAtConfigPath.js'
import log from '../../util/log'

/**
*
Expand Down Expand Up @@ -139,7 +140,7 @@ let state = {
}
},

loadConfig(configPath) {
loadConfig(configPath, content) {
if (this.watcher && configPath) {
this.refreshConfigDependencies(configPath)
}
Expand All @@ -149,6 +150,11 @@ let state = {
// @ts-ignore
config = resolveConfig(config, { content: { files: [] } })

// Override content files if `--content` has been passed explicitly
if (content?.length > 0) {
config.content.files = content
}

return config
},

Expand Down Expand Up @@ -196,7 +202,7 @@ let state = {
return content
},

getContext({ createContext, cliConfigPath, root, result }) {
getContext({ createContext, cliConfigPath, root, result, content }) {
if (this.context) {
this.context.changedContent = this.changedContent.splice(0)

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

env.DEBUG && console.time('Loading config')
let config = this.loadConfig(configPath)
let config = this.loadConfig(configPath, content)
env.DEBUG && console.timeEnd('Loading config')

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

if (args['--purge']) {
log.warn('purge-flag-deprecated', [
'The `--purge` flag has been deprecated.',
'Please use `--content` instead.',
])

if (!args['--content']) {
args['--content'] = args['--purge']
}
}

let content = args['--content']?.split(/(?<!{[^}]+),/) ?? []

let tailwindPlugin = () => {
return {
postcssPlugin: 'tailwindcss',
Expand All @@ -260,7 +279,13 @@ export async function createProcessor(args, cliConfigPath) {
console.error('Rebuilding...')

return () => {
return state.getContext({ createContext, cliConfigPath, root, result })
return state.getContext({
createContext,
cliConfigPath,
root,
result,
content,
})
}
})(root, result)
env.DEBUG && console.timeEnd('Compiling CSS')
Expand Down
4 changes: 2 additions & 2 deletions standalone-cli/tests/test.js
Expand Up @@ -51,7 +51,7 @@ it('supports postcss config files', async () => {
/**
* @template T
* @param {() => T} fn
* @returns {T}
* @returns {Promise<T>}
*/
async function inIsolatedContext(fn) {
// Create a new directory entirely outside of the package for the test
Expand Down Expand Up @@ -79,6 +79,6 @@ async function inIsolatedContext(fn) {
process.chdir(__dirname)

// Delete the new directory
await fs.rmdir(dest, { recursive: true })
await fs.rm(dest, { recursive: true })
}
}