Skip to content

Commit d14aff8

Browse files
committed
Only warn once per run
1 parent 1d20b0d commit d14aff8

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/config.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { pathToFileURL } from 'url'
44
import escalade from 'escalade/sync'
55
import prettier from 'prettier'
66
import type { ParserOptions } from 'prettier'
7+
import * as console from './console'
78
import { expiringMap } from './expiring-map.js'
89
import { resolveJsFrom } from './resolve'
910
import type { UnifiedApi } from './types'
@@ -89,6 +90,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
8990
// In this case the user explicitly gave us a stylesheet and a config.
9091
// Warn them about this and use the bundled v4.
9192
console.error(
93+
'explicit-stylesheet-and-config-together',
9294
'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.',
9395
)
9496
}
@@ -102,6 +104,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
102104
// installation is not v4. We'll fallback to the bundled v4 in this case.
103105
mod = null
104106
console.error(
107+
'stylesheet-unsupported',
105108
'You have specified a Tailwind CSS stylesheet but your installed version of Tailwind CSS does not support this feature.',
106109
)
107110
}
@@ -130,8 +133,8 @@ async function resolvePrettierConfigPath(filePath: string): Promise<string> {
130133
try {
131134
return await prettier.resolveConfigFile(filePath)
132135
} catch (err) {
133-
console.error('Failed to resolve Prettier Config')
134-
console.error(err)
136+
console.error('prettier-config-not-found', 'Failed to resolve Prettier Config')
137+
console.error('prettier-config-not-found-err', err)
135138
return null
136139
}
137140
})
@@ -201,6 +204,7 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
201204
options.tailwindStylesheet.endsWith('.cts')
202205
) {
203206
console.error(
207+
'stylesheet-is-js-file',
204208
"Your `tailwindStylesheet` option points to a JS/TS config file. You must point to your project's `.css` file for v4 projects.",
205209
)
206210
} else if (
@@ -210,10 +214,12 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
210214
options.tailwindStylesheet.endsWith('.styl')
211215
) {
212216
console.error(
217+
'stylesheet-is-preprocessor-file',
213218
'Your `tailwindStylesheet` option points to a preprocessor file. This is unsupported and you may get unexpected results.',
214219
)
215220
} else if (!options.tailwindStylesheet.endsWith('.css')) {
216221
console.error(
222+
'stylesheet-is-not-css-file',
217223
'Your `tailwindStylesheet` option does not point to a CSS file. This is unsupported and you may get unexpected results.',
218224
)
219225
}
@@ -222,13 +228,19 @@ function resolveStylesheet(options: ParserOptions, baseDir: string): string | nu
222228
}
223229

224230
if (options.tailwindEntryPoint) {
225-
console.warn('Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindEntryPoint`.')
231+
console.warn(
232+
'entrypoint-is-deprecated',
233+
'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindEntryPoint`.',
234+
)
226235

227236
return path.resolve(baseDir, options.tailwindEntryPoint)
228237
}
229238

230239
if (options.tailwindConfig && options.tailwindConfig.endsWith('.css')) {
231-
console.warn('Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindConfig`.')
240+
console.warn(
241+
'config-as-css-is-deprecated',
242+
'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindConfig`.',
243+
)
232244

233245
return path.resolve(baseDir, options.tailwindConfig)
234246
}

src/console.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let seen = new Set<string>()
2+
3+
export function log(key: string, arg: unknown, ...args: unknown[]) {
4+
if (seen.has(key)) return
5+
seen.add(key)
6+
console.log(arg, ...args)
7+
}
8+
9+
export function warn(key: string, arg: unknown, ...args: unknown[]) {
10+
if (seen.has(key)) return
11+
seen.add(key)
12+
console.warn(arg, ...args)
13+
}
14+
15+
export function error(key: string, arg: unknown, ...args: unknown[]) {
16+
if (seen.has(key)) return
17+
seen.add(key)
18+
console.error(arg, ...args)
19+
}

0 commit comments

Comments
 (0)