Skip to content

Commit

Permalink
Fix using negated content globs (#5625)
Browse files Browse the repository at this point in the history
* Fix negated content patterns

* Update changelog
  • Loading branch information
bradlc authored Sep 29, 2021
1 parent c5c644f commit 0b23d2e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix defining colors as functions when color opacity plugins are disabled ([#5470](https://github.com/tailwindlabs/tailwindcss/pull/5470))
- Fix using negated `content` globs ([#5625](https://github.com/tailwindlabs/tailwindcss/pull/5625))

## [2.2.16] - 2021-09-26

Expand Down
7 changes: 5 additions & 2 deletions src/lib/setupTrackingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getCandidateFiles(context, tailwindConfig) {

let candidateFiles = tailwindConfig.content.content
.filter((item) => typeof item === 'string')
.map((contentPath) => normalizePath(path.resolve(contentPath)))
.map((contentPath) => normalizePath(contentPath))

return candidateFilesCache.set(context, candidateFiles).get(context)
}
Expand Down Expand Up @@ -159,7 +159,10 @@ export default function setupTrackingContext(configOrPath) {

// Add template paths as postcss dependencies.
for (let fileOrGlob of candidateFiles) {
registerDependency(parseDependency(fileOrGlob))
let dependency = parseDependency(fileOrGlob)
if (dependency) {
registerDependency(dependency)
}
}

for (let changedContent of resolvedChangedContent(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/setupWatchingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function getCandidateFiles(context, tailwindConfig) {

let candidateFiles = tailwindConfig.content.content
.filter((item) => typeof item === 'string')
.map((contentPath) => normalizePath(path.resolve(contentPath)))
.map((contentPath) => normalizePath(contentPath))

return candidateFilesCache.set(context, candidateFiles).get(context)
}
Expand Down
4 changes: 4 additions & 0 deletions src/util/parseDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function parseGlob(pattern) {
}

export default function parseDependency(normalizedFileOrGlob) {
if (normalizedFileOrGlob.startsWith('!')) {
return null
}

let message

if (isGlob(normalizedFileOrGlob)) {
Expand Down
1 change: 1 addition & 0 deletions tests/negated-content-ignore.test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="lowercase"></div>
1 change: 1 addition & 0 deletions tests/negated-content-include.test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="uppercase"></div>
26 changes: 26 additions & 0 deletions tests/negated-content.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as path from 'path'
import { run, css } from './util/run'

it('should be possible to use negated content patterns', () => {
let config = {
content: [
path.resolve(__dirname, './negated-content-*.test.html'),
'!' + path.resolve(__dirname, './negated-content-ignore.test.html'),
],
corePlugins: { preflight: false },
}

let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.uppercase {
text-transform: uppercase;
}
`)
})
})

0 comments on commit 0b23d2e

Please sign in to comment.