Skip to content

Commit 30fbc2c

Browse files
authored
Fix rebuilds when editing imported CSS files (#14561)
1 parent 78b75e4 commit 30fbc2c

File tree

5 files changed

+104
-4
lines changed

5 files changed

+104
-4
lines changed

CHANGELOG.md

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

2222
- Use the right import base path when using the CLI to reading files from stdin ([#14522](https://github.com/tailwindlabs/tailwindcss/pull/14522))
2323
- Ensure that `@utility` is top-level and cannot be nested ([#14525](https://github.com/tailwindlabs/tailwindcss/pull/14525))
24+
- Editing imported CSS files should trigger a rebuild ([#14561](https://github.com/tailwindlabs/tailwindcss/pull/14561))
2425
- _Experimental_: Improve codemod output, keep CSS after last Tailwind directive unlayered ([#14512](https://github.com/tailwindlabs/tailwindcss/pull/14512))
2526
- _Experimental_: Fix incorrect empty `layer()` at the end of `@import` at-rules when running codemods ([#14513](https://github.com/tailwindlabs/tailwindcss/pull/14513))
2627
- _Experimental_: Do not wrap comment nodes in `@layer` when running codemods ([#14517](https://github.com/tailwindlabs/tailwindcss/pull/14517))

integrations/cli/index.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe.each([
112112
`,
113113
'project-a/index.html': html`
114114
<div
115-
class="underline 2xl:font-bold hocus:underline inverted:flex"
115+
class="underline 2xl:font-bold hocus:underline inverted:flex text-primary"
116116
></div>
117117
`,
118118
'project-a/plugin.js': js`
@@ -128,10 +128,17 @@ describe.each([
128128
`,
129129
'project-a/src/index.css': css`
130130
@import 'tailwindcss/utilities';
131+
@import './custom-theme.css';
131132
@config '../tailwind.config.js';
132133
@source '../../project-b/src/**/*.html';
133134
@plugin '../plugin.js';
134135
`,
136+
'project-a/src/custom-theme.css': css`
137+
/* Will be overwritten later */
138+
@theme {
139+
--color-primary: black;
140+
}
141+
`,
135142
'project-a/src/index.js': js`
136143
const className = "content-['project-a/src/index.js']"
137144
module.exports = { className }
@@ -157,6 +164,11 @@ describe.each([
157164
candidate`content-['project-b/src/index.js']`,
158165
candidate`inverted:flex`,
159166
candidate`hocus:underline`,
167+
css`
168+
.text-primary {
169+
color: var(--color-primary, black);
170+
}
171+
`,
160172
])
161173

162174
await fs.write(
@@ -180,6 +192,24 @@ describe.each([
180192
await fs.expectFileToContain('project-a/dist/out.css', [
181193
candidate`[.changed_&]:content-['project-b/src/index.js']`,
182194
])
195+
196+
await fs.write(
197+
'project-a/src/custom-theme.css',
198+
css`
199+
/* Overriding the primary color */
200+
@theme {
201+
--color-primary: red;
202+
}
203+
`,
204+
)
205+
206+
await fs.expectFileToContain('project-a/dist/out.css', [
207+
css`
208+
.text-primary {
209+
color: var(--color-primary, red);
210+
}
211+
`,
212+
])
183213
},
184214
)
185215

integrations/postcss/index.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ test(
342342
`,
343343
'project-a/index.html': html`
344344
<div
345-
class="underline 2xl:font-bold hocus:underline inverted:flex"
345+
class="underline 2xl:font-bold hocus:underline inverted:flex text-primary"
346346
></div>
347347
`,
348348
'project-a/plugin.js': js`
@@ -358,10 +358,17 @@ test(
358358
`,
359359
'project-a/src/index.css': css`
360360
@import 'tailwindcss/utilities';
361+
@import './custom-theme.css';
361362
@config '../tailwind.config.js';
362363
@source '../../project-b/src/**/*.html';
363364
@plugin '../plugin.js';
364365
`,
366+
'project-a/src/custom-theme.css': css`
367+
/* Will be overwritten later */
368+
@theme {
369+
--color-primary: black;
370+
}
371+
`,
365372
'project-a/src/index.js': js`
366373
const className = "content-['a/src/index.js']"
367374
module.exports = { className }
@@ -389,6 +396,11 @@ test(
389396
candidate`content-['b/src/index.js']`,
390397
candidate`inverted:flex`,
391398
candidate`hocus:underline`,
399+
css`
400+
.text-primary {
401+
color: var(--color-primary, black);
402+
}
403+
`,
392404
])
393405

394406
await fs.write(
@@ -414,5 +426,23 @@ test(
414426
await fs.expectFileToContain('project-a/dist/out.css', [
415427
candidate`[.changed_&]:content-['project-b/src/index.js']`,
416428
])
429+
430+
await fs.write(
431+
'project-a/src/custom-theme.css',
432+
css`
433+
/* Overriding the primary color */
434+
@theme {
435+
--color-primary: red;
436+
}
437+
`,
438+
)
439+
440+
await fs.expectFileToContain('project-a/dist/out.css', [
441+
css`
442+
.text-primary {
443+
color: var(--color-primary, red);
444+
}
445+
`,
446+
])
417447
},
418448
)

integrations/vite/index.test.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ for (let transformer of ['postcss', 'lightningcss']) {
287287
<link rel="stylesheet" href="./src/index.css" />
288288
</head>
289289
<body>
290-
<div class="underline">Hello, world!</div>
290+
<div class="underline text-primary">Hello, world!</div>
291291
</body>
292292
`,
293293
'project-a/tailwind.config.js': js`
@@ -298,9 +298,16 @@ for (let transformer of ['postcss', 'lightningcss']) {
298298
'project-a/src/index.css': css`
299299
@import 'tailwindcss/theme' theme(reference);
300300
@import 'tailwindcss/utilities';
301+
@import './custom-theme.css';
301302
@config '../tailwind.config.js';
302303
@source '../../project-b/src/**/*.html';
303304
`,
305+
'project-a/src/custom-theme.css': css`
306+
/* Will be overwritten later */
307+
@theme {
308+
--color-primary: black;
309+
}
310+
`,
304311
'project-b/src/index.html': html`
305312
<div class="flex" />
306313
`,
@@ -322,7 +329,37 @@ for (let transformer of ['postcss', 'lightningcss']) {
322329
filename = files[0][0]
323330
})
324331

325-
await fs.expectFileToContain(filename, [candidate`underline`, candidate`flex`])
332+
await fs.expectFileToContain(filename, [
333+
candidate`underline`,
334+
candidate`flex`,
335+
css`
336+
.text-primary {
337+
color: var(--color-primary, black);
338+
}
339+
`,
340+
])
341+
342+
await retryAssertion(async () => {
343+
await fs.write(
344+
'project-a/src/custom-theme.css',
345+
css`
346+
/* Overriding the primary color */
347+
@theme {
348+
--color-primary: red;
349+
}
350+
`,
351+
)
352+
353+
let files = await fs.glob('project-a/dist/**/*.css')
354+
expect(files).toHaveLength(1)
355+
let [, styles] = files[0]
356+
357+
expect(styles).toContain(css`
358+
.text-primary {
359+
color: var(--color-primary, red);
360+
}
361+
`)
362+
})
326363

327364
await retryAssertion(async () => {
328365
// Updates are additive and cause new candidates to be added.

packages/@tailwindcss-node/src/compile.ts

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ async function loadStylesheet(id: string, base: string, onDependency: (path: str
7474
let resolvedPath = await resolveCssId(id, base)
7575
if (!resolvedPath) throw new Error(`Could not resolve '${id}' from '${base}'`)
7676

77+
onDependency(resolvedPath)
78+
7779
if (typeof globalThis.__tw_readFile === 'function') {
7880
let file = await globalThis.__tw_readFile(resolvedPath, 'utf-8')
7981
if (file) {

0 commit comments

Comments
 (0)