Skip to content

Commit 35cd2ff

Browse files
Resolve third-party plugins with exports in their package.json (#14775)
This PR fixes an issue when trying to resolve plugins with `exports` in their `package.json`, like `@headlessui/tailwindcss`. The missing `conditionNames` in the enhanced resolver config would cause it to not properly look up the name. ## Test Plan I added a test using the `postcss` setup (the existing plugin tests are inside the CLI setup but the CLI can only ever run in Module JS mode). To ensure the tests are resolving to the right environment (CJS vs MJS), I added logging of the `import.meta.url` value to the resolver code. When run, this was the output: ![Screenshot 2024-10-24 at 15.28.10.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/0Y77ilPI2WoJfMLFiAEw/c0197934-7b61-47c4-bda5-de037b31d43a.png) Co-authored-by: Adam Wathan <[email protected]>
1 parent 3f2afaf commit 35cd2ff

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Ensure individual logical property utilities are sorted later than left/right pair utilities ([#14777](https://github.com/tailwindlabs/tailwindcss/pull/14777))
1313
- Don't migrate important modifiers inside conditional statements in Vue and Alpine (e.g. `<div v-if="!border" />`) ([#14774](https://github.com/tailwindlabs/tailwindcss/pull/14774))
14+
- Ensure third-party plugins with `exports` in their `package.json` are resolved correctly ([#14775](https://github.com/tailwindlabs/tailwindcss/pull/14775))
1415
- _Upgrade (experimental)_: Ensure `@import` statements for relative CSS files are actually migrated to use relative path syntax ([#14769](https://github.com/tailwindlabs/tailwindcss/pull/14769))
1516

1617
## [4.0.0-alpha.29] - 2024-10-23

integrations/postcss/plugins.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { candidate, css, html, js, json, test } from '../utils'
2+
3+
test(
4+
'builds the `@headlessui/tailwindcss` plugin utilities (CJS)',
5+
{
6+
fs: {
7+
'package.json': json`
8+
{
9+
"type": "commonjs",
10+
"dependencies": {
11+
"postcss": "^8",
12+
"postcss-cli": "^10",
13+
"tailwindcss": "workspace:^",
14+
"@tailwindcss/postcss": "workspace:^",
15+
"@headlessui/tailwindcss": "^0.2.1"
16+
}
17+
}
18+
`,
19+
'postcss.config.cjs': js`
20+
let tailwindcss = require('@tailwindcss/postcss')
21+
module.exports = {
22+
plugins: [tailwindcss()],
23+
}
24+
`,
25+
'index.html': html`
26+
<div className="ui-open:flex"></div>
27+
`,
28+
'src/index.css': css`
29+
@import 'tailwindcss/theme' theme(reference);
30+
@import 'tailwindcss/utilities';
31+
@plugin '@headlessui/tailwindcss';
32+
`,
33+
},
34+
},
35+
async ({ fs, exec }) => {
36+
await exec('pnpm postcss src/index.css --output dist/out.css')
37+
38+
await fs.expectFileToContain('dist/out.css', [candidate`ui-open:flex`])
39+
},
40+
)
41+
42+
test(
43+
'builds the `@headlessui/tailwindcss` plugin utilities (ESM)',
44+
{
45+
fs: {
46+
'package.json': json`
47+
{
48+
"type": "module",
49+
"dependencies": {
50+
"postcss": "^8",
51+
"postcss-cli": "^10",
52+
"tailwindcss": "workspace:^",
53+
"@tailwindcss/postcss": "workspace:^",
54+
"@headlessui/tailwindcss": "^0.2.1"
55+
}
56+
}
57+
`,
58+
'postcss.config.mjs': js`
59+
import tailwindcss from '@tailwindcss/postcss'
60+
export default {
61+
plugins: [tailwindcss()],
62+
}
63+
`,
64+
'index.html': html`
65+
<div className="ui-open:flex"></div>
66+
`,
67+
'src/index.css': css`
68+
@import 'tailwindcss/theme' theme(reference);
69+
@import 'tailwindcss/utilities';
70+
@plugin '@headlessui/tailwindcss';
71+
`,
72+
},
73+
},
74+
async ({ fs, exec }) => {
75+
await exec('pnpm postcss src/index.css --output dist/out.css')
76+
77+
await fs.expectFileToContain('dist/out.css', [candidate`ui-open:flex`])
78+
},
79+
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const jsResolver = EnhancedResolve.ResolverFactory.createResolver({
127127
fileSystem: new EnhancedResolve.CachedInputFileSystem(fs, 4000),
128128
useSyncFileSystemCalls: true,
129129
extensions: ['.js', '.json', '.node', '.ts'],
130+
conditionNames: import.meta.url ? ['node', 'import'] : ['node', 'require'],
130131
})
131132

132133
function resolveJsId(id: string, base: string): Promise<string | false | undefined> {

0 commit comments

Comments
 (0)