Skip to content

Commit

Permalink
Include all css in context
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews committed Dec 18, 2021
1 parent e8e64f0 commit 9446822
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
19 changes: 6 additions & 13 deletions src/lib/setupTrackingContext.js
Expand Up @@ -119,20 +119,13 @@ export default function setupTrackingContext(configOrPath) {

let contextDependencies = new Set(configDependencies)

// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
// to be dependencies of the context. Can reuse the context even if they change.
// We may want to think about `@layer` being part of this trigger too, but it's tough
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
// in another file since independent sources are effectively isolated.
if (tailwindDirectives.size > 0) {
// Add current css file as a context dependencies.
contextDependencies.add(result.opts.from)
// Add current css file as a context dependencies.
contextDependencies.add(result.opts.from)

// Add all css @import dependencies as context dependencies.
for (let message of result.messages) {
if (message.type === 'dependency') {
contextDependencies.add(message.file)
}
// Add all css @import dependencies as context dependencies.
for (let message of result.messages) {
if (message.type === 'dependency') {
contextDependencies.add(message.file)
}
}

Expand Down
19 changes: 6 additions & 13 deletions src/lib/setupWatchingContext.js
Expand Up @@ -236,20 +236,13 @@ export default function setupWatchingContext(configOrPath) {

let contextDependencies = new Set(configDependencies)

// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
// to be dependencies of the context. Can reuse the context even if they change.
// We may want to think about `@layer` being part of this trigger too, but it's tough
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
// in another file since independent sources are effectively isolated.
if (tailwindDirectives.size > 0) {
// Add current css file as a context dependencies.
contextDependencies.add(result.opts.from)
// Add current css file as a context dependencies.
contextDependencies.add(result.opts.from)

// Add all css @import dependencies as context dependencies.
for (let message of result.messages) {
if (message.type === 'dependency') {
contextDependencies.add(message.file)
}
// Add all css @import dependencies as context dependencies.
for (let message of result.messages) {
if (message.type === 'dependency') {
contextDependencies.add(message.file)
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/apply.test.js
Expand Up @@ -774,3 +774,38 @@ it('should not apply unrelated siblings when applying something from within atru
`)
})
})

it('should be possible to apply user css without directives', () => {
let config = {
content: [{ raw: html`<div class="foo"></div>` }],
plugins: [],
}

let input = css`
.bop {
color: red;
}
.bar {
background-color: blue;
}
.foo {
@apply absolute bar bop;
}
`

return run(input, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.bop {
color: red;
}
.bar {
background-color: blue;
}
.foo {
position: absolute;
color: red;
background-color: blue;
}
`)
})
})

0 comments on commit 9446822

Please sign in to comment.