Skip to content

Commit 0b23d2e

Browse files
authored
Fix using negated content globs (#5625)
* Fix negated content patterns * Update changelog
1 parent c5c644f commit 0b23d2e

7 files changed

+39
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
### Fixed
3434

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

3738
## [2.2.16] - 2021-09-26
3839

src/lib/setupTrackingContext.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function getCandidateFiles(context, tailwindConfig) {
2828

2929
let candidateFiles = tailwindConfig.content.content
3030
.filter((item) => typeof item === 'string')
31-
.map((contentPath) => normalizePath(path.resolve(contentPath)))
31+
.map((contentPath) => normalizePath(contentPath))
3232

3333
return candidateFilesCache.set(context, candidateFiles).get(context)
3434
}
@@ -159,7 +159,10 @@ export default function setupTrackingContext(configOrPath) {
159159

160160
// Add template paths as postcss dependencies.
161161
for (let fileOrGlob of candidateFiles) {
162-
registerDependency(parseDependency(fileOrGlob))
162+
let dependency = parseDependency(fileOrGlob)
163+
if (dependency) {
164+
registerDependency(dependency)
165+
}
163166
}
164167

165168
for (let changedContent of resolvedChangedContent(

src/lib/setupWatchingContext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function getCandidateFiles(context, tailwindConfig) {
149149

150150
let candidateFiles = tailwindConfig.content.content
151151
.filter((item) => typeof item === 'string')
152-
.map((contentPath) => normalizePath(path.resolve(contentPath)))
152+
.map((contentPath) => normalizePath(contentPath))
153153

154154
return candidateFilesCache.set(context, candidateFiles).get(context)
155155
}

src/util/parseDependency.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function parseGlob(pattern) {
2626
}
2727

2828
export default function parseDependency(normalizedFileOrGlob) {
29+
if (normalizedFileOrGlob.startsWith('!')) {
30+
return null
31+
}
32+
2933
let message
3034

3135
if (isGlob(normalizedFileOrGlob)) {
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="lowercase"></div>
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="uppercase"></div>

tests/negated-content.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as path from 'path'
2+
import { run, css } from './util/run'
3+
4+
it('should be possible to use negated content patterns', () => {
5+
let config = {
6+
content: [
7+
path.resolve(__dirname, './negated-content-*.test.html'),
8+
'!' + path.resolve(__dirname, './negated-content-ignore.test.html'),
9+
],
10+
corePlugins: { preflight: false },
11+
}
12+
13+
let input = css`
14+
@tailwind base;
15+
@tailwind components;
16+
@tailwind utilities;
17+
`
18+
19+
return run(input, config).then((result) => {
20+
expect(result.css).toMatchFormattedCss(css`
21+
.uppercase {
22+
text-transform: uppercase;
23+
}
24+
`)
25+
})
26+
})

0 commit comments

Comments
 (0)