Skip to content

Commit c20c92d

Browse files
authored
Merge branch 'main' into fix/watch-other-css-files
2 parents 9af2783 + c7ba564 commit c20c92d

File tree

5 files changed

+66
-9
lines changed

5 files changed

+66
-9
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ playwright-report/
77
blob-report/
88
playwright/.cache/
99
target/
10-
.debug
10+
.debug/

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- Fix negated `content` rules in legacy JavaScript configuration ([#17255](https://github.com/tailwindlabs/tailwindcss/pull/17255))
3535
- Extract special `@("@")md:…` syntax in Razor files ([#17427](https://github.com/tailwindlabs/tailwindcss/pull/17427))
3636
- Disallow arbitrary values with top-level braces and semicolons as well as unbalanced parentheses and brackets ([#17361](https://github.com/tailwindlabs/tailwindcss/pull/17361))
37+
- Ensure the `--theme(…)` function still resolves to the CSS variables even when legacy JS plugins are enabled
3738
- Extract used CSS variables from `.css` files ([#17433](https://github.com/tailwindlabs/tailwindcss/pull/17433), [#17467](https://github.com/tailwindlabs/tailwindcss/pull/17467))
3839

3940
### Changed

Diff for: packages/@tailwindcss-postcss/src/index.test.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import dedent from 'dedent'
2-
import { unlink, writeFile } from 'node:fs/promises'
2+
import { mkdir, mkdtemp, unlink, writeFile } from 'node:fs/promises'
3+
import { tmpdir } from 'node:os'
4+
import path from 'path'
35
import postcss from 'postcss'
4-
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
6+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
57
import tailwindcss from './index'
68

79
// We give this file path to PostCSS for processing.
@@ -106,14 +108,21 @@ test('@apply can be used without emitting the theme in the CSS file', async () =
106108
})
107109

108110
describe('processing without specifying a base path', () => {
109-
let filepath = `${process.cwd()}/my-test-file.html`
110-
111-
beforeEach(() =>
112-
writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`),
113-
)
111+
let filepath: string
112+
let dir: string
113+
114+
beforeEach(async () => {
115+
dir = await mkdtemp(path.join(tmpdir(), 'tw-postcss'))
116+
await mkdir(dir, { recursive: true })
117+
filepath = path.join(dir, 'my-test-file.html')
118+
await writeFile(filepath, `<div class="md:[&:hover]:content-['testing_default_base_path']">`)
119+
})
114120
afterEach(() => unlink(filepath))
115121

116122
test('the current working directory is used by default', async () => {
123+
const spy = vi.spyOn(process, 'cwd')
124+
spy.mockReturnValue(dir)
125+
117126
let processor = postcss([tailwindcss({ optimize: { minify: false } })])
118127

119128
let result = await processor.process(`@import "tailwindcss"`, { from: inputCssFilePath() })

Diff for: packages/tailwindcss/src/compat/apply-compat-hooks.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ function upgradeToFullPluginSupport({
260260
// config files are actually being used. In the future we may want to optimize
261261
// this further by only doing this if plugins or config files _actually_
262262
// registered JS config objects.
263+
let defaultResolveThemeValue = designSystem.resolveThemeValue
263264
designSystem.resolveThemeValue = function resolveThemeValue(path: string, forceInline?: boolean) {
264-
let resolvedValue = pluginApi.theme(path, forceInline)
265+
if (path[0] === '-' && path[1] === '-') {
266+
return defaultResolveThemeValue(path, forceInline)
267+
}
268+
269+
let resolvedValue = pluginApi.theme(path, undefined)
265270

266271
if (Array.isArray(resolvedValue) && resolvedValue.length === 2) {
267272
// When a tuple is returned, return the first element

Diff for: packages/tailwindcss/src/css-functions.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,48 @@ describe('--theme(…)', () => {
384384
`[Error: Could not resolve value for theme function: \`theme(--color-green-500)\`. Consider checking if the variable name is correct or provide a fallback value to silence this error.]`,
385385
)
386386
})
387+
388+
test('--theme(…) function still works as expected, even when a plugin is imported', async () => {
389+
expect(
390+
await compileCss(
391+
css`
392+
@layer base {
393+
html,
394+
:host {
395+
font-family: --theme(--default-font-family, system-ui);
396+
}
397+
}
398+
@layer theme {
399+
@theme {
400+
--font-sans: sans-serif;
401+
--default-font-family: --theme(--font-sans, initial);
402+
}
403+
}
404+
@plugin "my-plugin.js";
405+
`,
406+
[],
407+
{
408+
loadModule: async () => ({
409+
module: () => {},
410+
base: '/root',
411+
}),
412+
},
413+
),
414+
).toMatchInlineSnapshot(`
415+
"@layer base {
416+
html, :host {
417+
font-family: var(--default-font-family, system-ui);
418+
}
419+
}
420+
421+
@layer theme {
422+
:root, :host {
423+
--font-sans: sans-serif;
424+
--default-font-family: var(--font-sans);
425+
}
426+
}"
427+
`)
428+
})
387429
})
388430

389431
describe('theme(…)', () => {

0 commit comments

Comments
 (0)