Skip to content

Commit b178b95

Browse files
committed
Include Prettier config path in error messages
1 parent d14aff8 commit b178b95

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/config.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
3434
//
3535
// These lookups can take a bit so we cache them. This is especially important
3636
// for files with lots of embedded languages (e.g. Vue bindings).
37-
let configDir = await resolvePrettierConfigPath(options.filepath)
37+
let [configDir, configPath] = await resolvePrettierConfigPath(options.filepath)
3838

3939
// Locate Tailwind CSS itself
4040
//
@@ -48,7 +48,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
4848
// We resolve this relative to the config file because it is *required*
4949
// to work with a project's custom config. Given that, resolving it
5050
// relative to where the path is defined makes the most sense.
51-
let stylesheet = resolveStylesheet(options, configDir)
51+
let stylesheet = resolveStylesheet(options, configDir, configPath)
5252

5353
// Locate *explicit* v3 configs relative to the prettier config file
5454
//
@@ -91,7 +91,8 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
9191
// Warn them about this and use the bundled v4.
9292
console.error(
9393
'explicit-stylesheet-and-config-together',
94-
'You have specified a Tailwind CSS stylesheet and a Tailwind CSS config at the same time. Use tailwindStylesheet unless you are using v3. Preferring the stylesheet.',
94+
configPath ?? '',
95+
`You have specified a Tailwind CSS stylesheet and a Tailwind CSS config at the same time. Use tailwindStylesheet unless you are using v3. Preferring the stylesheet.`,
9596
)
9697
}
9798

@@ -105,6 +106,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
105106
mod = null
106107
console.error(
107108
'stylesheet-unsupported',
109+
configPath ?? '',
108110
'You have specified a Tailwind CSS stylesheet but your installed version of Tailwind CSS does not support this feature.',
109111
)
110112
}
@@ -128,7 +130,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
128130

129131
let prettierConfigCache = expiringMap<string, Promise<string | null>>(10_000)
130132

131-
async function resolvePrettierConfigPath(filePath: string): Promise<string> {
133+
async function resolvePrettierConfigPath(filePath: string): Promise<[string, string | null]> {
132134
let prettierConfig = await prettierConfigCache.remember(filePath, async () => {
133135
try {
134136
return await prettier.resolveConfigFile(filePath)
@@ -139,7 +141,7 @@ async function resolvePrettierConfigPath(filePath: string): Promise<string> {
139141
}
140142
})
141143

142-
return prettierConfig ? path.dirname(prettierConfig) : process.cwd()
144+
return prettierConfig ? [path.dirname(prettierConfig), prettierConfig] : [process.cwd(), null]
143145
}
144146

145147
let resolvedModCache = expiringMap<string, Promise<[any | null, string | null]>>(10_000)
@@ -193,7 +195,7 @@ function findClosestJsConfig(inputDir: string): string | null {
193195
return configPath
194196
}
195197

196-
function resolveStylesheet(options: ParserOptions, baseDir: string): string | null {
198+
function resolveStylesheet(options: ParserOptions, baseDir: string, configPath: string | null): string | null {
197199
if (options.tailwindStylesheet) {
198200
if (
199201
options.tailwindStylesheet.endsWith('.js') ||
@@ -205,6 +207,7 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
205207
) {
206208
console.error(
207209
'stylesheet-is-js-file',
210+
configPath ?? '',
208211
"Your `tailwindStylesheet` option points to a JS/TS config file. You must point to your project's `.css` file for v4 projects.",
209212
)
210213
} else if (
@@ -215,11 +218,13 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
215218
) {
216219
console.error(
217220
'stylesheet-is-preprocessor-file',
221+
configPath ?? '',
218222
'Your `tailwindStylesheet` option points to a preprocessor file. This is unsupported and you may get unexpected results.',
219223
)
220224
} else if (!options.tailwindStylesheet.endsWith('.css')) {
221225
console.error(
222226
'stylesheet-is-not-css-file',
227+
configPath ?? '',
223228
'Your `tailwindStylesheet` option does not point to a CSS file. This is unsupported and you may get unexpected results.',
224229
)
225230
}
@@ -230,6 +235,7 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
230235
if (options.tailwindEntryPoint) {
231236
console.warn(
232237
'entrypoint-is-deprecated',
238+
configPath ?? '',
233239
'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindEntryPoint`.',
234240
)
235241

@@ -239,6 +245,7 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
239245
if (options.tailwindConfig && options.tailwindConfig.endsWith('.css')) {
240246
console.warn(
241247
'config-as-css-is-deprecated',
248+
configPath ?? '',
242249
'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindConfig`.',
243250
)
244251

0 commit comments

Comments
 (0)