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

Fix negative content patterns #5625

Merged
merged 2 commits into from
Sep 29, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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;
}
`)
})
})