Skip to content

Commit fa61eae

Browse files
Resolve tailwindcss relative to the file being processed (#386)
* Bump deps * Cleanup formatting * Drop support for `prettier-plugin-style-order` The last release was over 5 years ago * Ridiculously large config loading refactor * Resolve `tailwindcss` relative to the file being processed * Resolve auto-loaded v3 configs relative to the file being processed * Renamed bundled v3 package * Ensure CSS imports are inlined * Add tests * Only warn once per run * Include Prettier config path in error messages * Apply suggestions from code review Co-authored-by: Robin Malfait <[email protected]> * Update changelog * Tweak error message * Add tests for errors --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent c3c5ff5 commit fa61eae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2562
-1497
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Support sorting in callable template literals ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367))
1414
- Support sorting in function calls mixed with property accesses ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367))
1515
- Handle quote escapes in LESS when sorting `@apply` ([#392](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/392))
16+
- Improved monorepo support by loading Tailwind CSS relative to the input file instead of prettier config file ([#386](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/386))
17+
- Improved monorepo support by loading v3 configs relative to the input file instead of prettier config file ([#386](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/386))
1618

1719
## [0.6.14] - 2025-07-09
1820

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ This plugin uses Prettier APIs that can only be used by one plugin at a time, ma
230230
- `prettier-plugin-multiline-arrays`
231231
- `prettier-plugin-organize-attributes`
232232
- `prettier-plugin-organize-imports`
233-
- `prettier-plugin-style-order`
234233
- `prettier-plugin-svelte`
235234
- `prettier-plugin-sort-imports`
236235

build.mjs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'node:fs'
2+
import { readFile } from 'node:fs/promises'
23
import * as path from 'node:path'
34
import { fileURLToPath } from 'node:url'
45
import esbuild from 'esbuild'
@@ -62,6 +63,47 @@ function patchCjsInterop() {
6263
}
6364
}
6465

66+
/**
67+
* @returns {import('esbuild').Plugin}
68+
*/
69+
function inlineCssImports() {
70+
return {
71+
name: 'inline-css-imports',
72+
setup(build) {
73+
// Inline CSS imports
74+
build.onLoad({ filter: /\.css$/ }, async (args) => {
75+
let content = await readFile(args.path, 'utf-8')
76+
77+
return {
78+
loader: 'js',
79+
contents: `export default ${JSON.stringify(content)}`,
80+
}
81+
})
82+
83+
// Inline preflight in v3
84+
// TODO: This needs a test
85+
build.onLoad({ filter: /corePlugins\.js$/ }, async (args) => {
86+
let preflightPath = path.resolve(path.dirname(args.path), './css/preflight.css')
87+
let preflightContent = await readFile(preflightPath, 'utf-8')
88+
89+
let content = await readFile(args.path, 'utf-8')
90+
91+
// This is a bit fragile but this is to inline preflight for the
92+
// *bundled* version which means a failing test should be enough
93+
content = content.replace(
94+
`_fs.default.readFileSync(_path.join(__dirname, "./css/preflight.css"), "utf8")`,
95+
JSON.stringify(preflightContent),
96+
)
97+
98+
return {
99+
loader: 'js',
100+
contents: content,
101+
}
102+
})
103+
},
104+
}
105+
}
106+
65107
const __dirname = path.dirname(fileURLToPath(import.meta.url))
66108

67109
let context = await esbuild.context({
@@ -73,7 +115,7 @@ let context = await esbuild.context({
73115
entryPoints: [path.resolve(__dirname, './src/index.js')],
74116
outfile: path.resolve(__dirname, './dist/index.mjs'),
75117
format: 'esm',
76-
plugins: [patchRecast(), patchCjsInterop()],
118+
plugins: [patchRecast(), patchCjsInterop(), inlineCssImports()],
77119
})
78120

79121
await context.rebuild()

0 commit comments

Comments
 (0)