MCPcopy Index your code
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / createPlugin

Function createPlugin

src/create-plugin.ts:9–53  ·  view source on GitHub ↗
(transforms: TransformOptions<any>[])

Source from the content-addressed store, hash-verified

7import type { TransformerEnv } from './types'
8
9export function createPlugin(transforms: TransformOptions<any>[]) {
10 // Prettier parsers and printers may be async functions at definition time.
11 // They'll be awaited when the plugin is loaded but must also be swapped out
12 // with the resolved value before returning as later Prettier internals
13 // assume that parsers and printers are objects and not functions.
14 type Init<T> = (() => Promise<T | undefined>) | T | undefined
15
16 let parsers: Record<string, Init<Parser<any>>> = Object.create(null)
17 let printers: Record<string, Init<Printer<any>>> = Object.create(null)
18
19 for (let opts of transforms) {
20 for (let [name, meta] of Object.entries(opts.parsers)) {
21 parsers[name] = async () => {
22 let plugin = await loadPlugins(meta.load ?? opts.load ?? [])
23 let original = plugin.parsers?.[name]
24 if (!original) return
25
26 parsers[name] = await createParser({
27 name,
28 original,
29 opts,
30 })
31
32 return parsers[name]
33 }
34 }
35
36 for (let [name, _meta] of Object.entries(opts.printers ?? {})) {
37 printers[name] = async () => {
38 let plugin = await loadPlugins(opts.load ?? [])
39 let original = plugin.printers?.[name]
40 if (!original) return
41
42 printers[name] = createPrinter({
43 original,
44 opts,
45 })
46
47 return printers[name]
48 }
49 }
50 }
51
52 return { parsers, printers }
53}
54
55async function createParser({
56 name,

Callers 1

index.tsFile · 0.85

Calls 3

loadPluginsFunction · 0.85
createParserFunction · 0.85
createPrinterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…