Home

tailwind-ctp-intellisense @3a01ebd1731374a3abd9bf16fd6d757f34d17b98 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-intellisense / src / class-names / getPlugins.js
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as path from 'path'
import stackTrace from 'stack-trace'
import pkgUp from 'pkg-up'
import { isObject } from './isObject'
import { withUserEnvironment } from './environment'

export async function getBuiltInPlugins({ base, root, resolvedConfig }) {
  return withUserEnvironment(base, root, ({ require, resolve }) => {
    const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
    try {
      return require('./lib/corePlugins.js', tailwindBase).default({
        corePlugins: resolvedConfig.corePlugins,
      })
    } catch (_) {
      return []
    }
  })
}

export default function getPlugins(config) {
  let plugins = config.plugins

  if (!Array.isArray(plugins)) {
    return []
  }

  return plugins.map((plugin) => {
    let pluginConfig = plugin.config
    if (!isObject(pluginConfig)) {
      pluginConfig = {}
    }

    let contributes = {
      theme: isObject(pluginConfig.theme)
        ? Object.keys(pluginConfig.theme)
        : [],
      variants: isObject(pluginConfig.variants)
        ? Object.keys(pluginConfig.variants)
        : [],
    }

    const fn = plugin.handler || plugin
    const fnName =
      typeof fn.name === 'string' && fn.name !== 'handler' && fn.name !== ''
        ? fn.name
        : null

    try {
      fn()
    } catch (e) {
      const trace = stackTrace.parse(e)
      if (trace.length === 0)
        return {
          name: fnName,
        }
      const file = trace[0].fileName
      const dir = path.dirname(file)
      let pkg = pkgUp.sync({ cwd: dir })
      if (!pkg)
        return {
          name: fnName,
        }
      try {
        pkg = __non_webpack_require__(pkg)
      } catch (_) {
        return {
          name: fnName,
        }
      }
      if (pkg.name && path.resolve(dir, pkg.main || 'index.js') === file) {
        return {
          name: pkg.name,
          homepage: pkg.homepage,
          contributes,
        }
      }
    }
    return {
      name: fnName,
    }
  })
}