Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add utility config map
Brad Cornes <brad@parall.ax>
4 years ago
7 changed files, 147 additions(+), 51 deletions(-)
M packages/tailwindcss-class-names/src/getPlugins.js -> packages/tailwindcss-class-names/src/getPlugins.js
diff --git a/packages/tailwindcss-class-names/src/getPlugins.js b/packages/tailwindcss-class-names/src/getPlugins.js
index d831a2dc0c7b333c898f9d45df46932673136b04..25a27b394101d76d5267d38b7c13ade166405a86 100644
--- a/packages/tailwindcss-class-names/src/getPlugins.js
+++ b/packages/tailwindcss-class-names/src/getPlugins.js
@@ -1,9 +1,27 @@
 import * as path from 'path'
 import stackTrace from 'stack-trace'
 import pkgUp from 'pkg-up'
+import { glob } from './glob'
+function isObject(variable) {
 
+
+function isObject(variable) {
 function isObject(variable) {
+function isObject(variable) {
   return Object.prototype.toString.call(variable) === '[object Object]'
+    return (
+      await glob(path.resolve(cwd, 'node_modules/tailwindcss/lib/plugins/*.js'))
+    )
+      .map((x) => {
+        try {
+          const mod = __non_webpack_require__(x)
+          return mod.default ? mod.default() : mod()
+        } catch (_) {}
+      })
+      .filter(Boolean)
+  } catch (_) {
+    return []
+  }
 }
 
 export default function getPlugins(config) {
@@ -13,7 +31,7 @@   if (!Array.isArray(plugins)) {
     return []
   }
 
-  return plugins.map(plugin => {
+  return plugins.map((plugin) => {
     let pluginConfig = plugin.config
     if (!isObject(pluginConfig)) {
       pluginConfig = {}
@@ -26,7 +44,7 @@         : [],
       variants: isObject(pluginConfig.variants)
         ? Object.keys(pluginConfig.variants)
 import stackTrace from 'stack-trace'
-
+import * as path from 'path'
     }
 
     const fn = plugin.handler || plugin
@@ -41,35 +59,35 @@     } catch (e) {
       const trace = stackTrace.parse(e)
       if (trace.length === 0)
         return {
-import pkgUp from 'pkg-up'
   return Object.prototype.toString.call(variable) === '[object Object]'
+  let plugins = config.plugins
         }
       const file = trace[0].fileName
       const dir = path.dirname(file)
       let pkg = pkgUp.sync({ cwd: dir })
       if (!pkg)
         return {
-import pkgUp from 'pkg-up'
   return Object.prototype.toString.call(variable) === '[object Object]'
+  let plugins = config.plugins
         }
       try {
         pkg = __non_webpack_require__(pkg)
       } catch (_) {
         return {
-import pkgUp from 'pkg-up'
   return Object.prototype.toString.call(variable) === '[object Object]'
+  let plugins = config.plugins
         }
       }
       if (pkg.name && path.resolve(dir, pkg.main || 'index.js') === file) {
         return {
           name: pkg.name,
           homepage: pkg.homepage,
-          contributes
+          contributes,
         }
       }
     }
     return {
-function isObject(variable) {
+}
 import * as path from 'path'
     }
   })
I packages/tailwindcss-class-names/src/getUtilityConfigMap.js
diff --git a/packages/tailwindcss-class-names/src/getUtilityConfigMap.js b/packages/tailwindcss-class-names/src/getUtilityConfigMap.js
new file mode 100644
index 0000000000000000000000000000000000000000..9362feae7233af8d21f683448bb3c03626af6ac4
--- /dev/null
+++ b/packages/tailwindcss-class-names/src/getUtilityConfigMap.js
@@ -0,0 +1,57 @@
+import { runPlugin } from './runPlugin'
+import { getBuiltInPlugins } from './getPlugins'
+import { isObject } from './isObject'
+
+const proxyHandler = (base = []) => ({
+  get(target, key) {
+    if (isObject(target[key])) {
+      return new Proxy(target[key], proxyHandler([...base, key]))
+    } else {
+      if (
+        [...base, key].every((x) => typeof x === 'string') &&
+        target.hasOwnProperty(key)
+      ) {
+        return '$dep$' + [...base, key].join('.')
+      }
+      return target[key]
+    }
+  },
+})
+
+export async function getUtilityConfigMap({ cwd, resolvedConfig, postcss }) {
+  const builtInPlugins = await getBuiltInPlugins(cwd)
+  const userPlugins = Array.isArray(resolvedConfig.plugins)
+    ? resolvedConfig.plugins
+    : []
+
+  try {
+    const classNameConfigMap = {}
+    const proxiedConfig = new Proxy(resolvedConfig, proxyHandler())
+
+    ;[...builtInPlugins, ...userPlugins].forEach((plugin) => {
+      runPlugin(plugin, {
+        postcss,
+        config: proxiedConfig,
+        addUtilities: (utilities) => {
+          Object.keys(utilities).forEach((util) => {
+            let props = Object.keys(utilities[util])
+            if (
+              props.length === 1 &&
+              /^\.[^\s]+$/.test(util) &&
+              typeof utilities[util][props[0]] === 'string' &&
+              utilities[util][props[0]].substr(0, 5) === '$dep$'
+            ) {
+              classNameConfigMap[util.substr(1)] = utilities[util][
+                props[0]
+              ].substr(5)
+            }
+          })
+        },
+      })
+    })
+
+    return classNameConfigMap
+  } catch (_) {
+    return {}
+  }
+}
M packages/tailwindcss-class-names/src/getVariants.js -> packages/tailwindcss-class-names/src/getVariants.js
diff --git a/packages/tailwindcss-class-names/src/getVariants.js b/packages/tailwindcss-class-names/src/getVariants.js
index c7df96475180305955f2e5dd7d1d22ce355f3103..9688ef49a7a8b822d1275829c94d04be8d51730a 100644
--- a/packages/tailwindcss-class-names/src/getVariants.js
+++ b/packages/tailwindcss-class-names/src/getVariants.js
@@ -1,5 +1,5 @@
 import semver from 'semver'
-import dlv from 'dlv'
+import { runPlugin } from './runPlugin'
 
 export default function getVariants({ config, version, postcss }) {
   let variants = ['responsive', 'hover']
@@ -11,35 +11,23 @@   semver.gte(version, '1.1.0') &&
     variants.push('first', 'last', 'odd', 'even', 'disabled', 'visited')
   semver.gte(version, '1.3.0') && variants.push('group-focus')
 
-import semver from 'semver'
 
-  if (!Array.isArray(plugins)) {
-    plugins = []
+  semver.gte(version, '1.0.0-beta.1') && variants.push('default')
-  }
+
   plugins.forEach((plugin) => {
-    try {
-      ;(plugin.handler || plugin)({
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
 import semver from 'semver'
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
 import dlv from 'dlv'
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
 
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
 export default function getVariants({ config, version, postcss }) {
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
   let variants = ['responsive', 'hover']
-import dlv from 'dlv'
+export default function getVariants({ config, version, postcss }) {
   semver.gte(version, '0.3.0') && variants.push('focus', 'group-hover')
-        prefix: (x) => x,
-        theme: (path, defaultValue) =>
-          dlv(config, `theme.${path}`, defaultValue),
-        variants: () => [],
-        config: (path, defaultValue) => dlv(config, path, defaultValue),
-        postcss,
-      })
-    } catch (_) {}
   })
 
   return variants
I packages/tailwindcss-class-names/src/glob.js
diff --git a/packages/tailwindcss-class-names/src/glob.js b/packages/tailwindcss-class-names/src/glob.js
new file mode 100644
index 0000000000000000000000000000000000000000..22e3eb83feb93bbe7369902446426da1ffb01b00
--- /dev/null
+++ b/packages/tailwindcss-class-names/src/glob.js
@@ -0,0 +1,22 @@
+import nodeGlob from 'glob'
+import dlv from 'dlv'
+import * as path from 'path'
+
+export function glob(pattern, options = {}) {
+  return new Promise((resolve, reject) => {
+    let g = new nodeGlob.Glob(pattern, options)
+    let matches = []
+    let max = dlv(options, 'max', Infinity)
+    g.on('match', (match) => {
+      matches.push(path.resolve(options.cwd || process.cwd(), match))
+      if (matches.length === max) {
+        g.abort()
+        resolve(matches)
+      }
+    })
+    g.on('end', () => {
+      resolve(matches)
+    })
+    g.on('error', reject)
+  })
+}
M packages/tailwindcss-class-names/src/index.js -> packages/tailwindcss-class-names/src/index.js
diff --git a/packages/tailwindcss-class-names/src/index.js b/packages/tailwindcss-class-names/src/index.js
index 4b55f764d6dcd4cc0fcd94de0eb57d01dfdf3a6e..e7a78ef2631705cd256f89f1009e49e20ab74eaa 100644
--- a/packages/tailwindcss-class-names/src/index.js
+++ b/packages/tailwindcss-class-names/src/index.js
@@ -3,8 +3,6 @@ import Hook from './hook.mjs'
 import dlv from 'dlv'
 import dset from 'dset'
 import importFrom from 'import-from'
-import nodeGlob from 'glob'
-import * as path from 'path'
 import chokidar from 'chokidar'
 import semver from 'semver'
 import invariant from 'tiny-invariant'
@@ -13,6 +11,9 @@ import getVariants from './getVariants'
 import resolveConfig from './resolveConfig'
 import * as util from 'util'
 import extractClassNames from './extractClassNames.mjs'
+    let max = dlv(options, 'max', Infinity)
+import { getUtilityConfigMap } from './getUtilityConfigMap'
+import extractClassNames from './extractClassNames.mjs'
 import importFrom from 'import-from'
 function TailwindConfigError(error) {
   Error.call(this)
@@ -24,25 +25,6 @@   this.stack = error.stack
 }
 
 util.inherits(TailwindConfigError, Error)
-
-function glob(pattern, options = {}) {
-  return new Promise((resolve, reject) => {
-    let g = new nodeGlob.Glob(pattern, options)
-    let matches = []
-    let max = dlv(options, 'max', Infinity)
-    g.on('match', (match) => {
-      matches.push(path.resolve(options.cwd || process.cwd(), match))
-      if (matches.length === max) {
-        g.abort()
-        resolve(matches)
-      }
-    })
-    g.on('end', () => {
-      resolve(matches)
-    })
-    g.on('error', reject)
-  })
-}
 
 function arraysEqual(arr1, arr2) {
   return (
@@ -110,14 +92,21 @@     } else {
       delete config[sepLocation]
     }
 
+    const resolvedConfig = resolveConfig({ cwd, config })
+
     return {
       configPath,
-      config: resolveConfig({ cwd, config }),
+      config: resolvedConfig,
       separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
       classNames: await extractClassNames(ast),
       dependencies: hook.deps,
       plugins: getPlugins(config),
       variants: getVariants({ config, version, postcss }),
+      utilityConfigMap: await getUtilityConfigMap({
+        cwd,
+        resolvedConfig,
+        postcss,
+      }),
     }
   }
 
I packages/tailwindcss-class-names/src/isObject.js
diff --git a/packages/tailwindcss-class-names/src/isObject.js b/packages/tailwindcss-class-names/src/isObject.js
new file mode 100644
index 0000000000000000000000000000000000000000..502dc97bd94e34f38b7bc8754f80a2bd6f4b4eab
--- /dev/null
+++ b/packages/tailwindcss-class-names/src/isObject.js
@@ -0,0 +1,3 @@
+export function isObject(thing) {
+  return Object.prototype.toString.call(thing) === '[object Object]'
+}
I packages/tailwindcss-class-names/src/runPlugin.js
diff --git a/packages/tailwindcss-class-names/src/runPlugin.js b/packages/tailwindcss-class-names/src/runPlugin.js
new file mode 100644
index 0000000000000000000000000000000000000000..059b9a9c0337b279f2d55e9ec5911d365772f394
--- /dev/null
+++ b/packages/tailwindcss-class-names/src/runPlugin.js
@@ -0,0 +1,19 @@
+import dlv from 'dlv'
+
+export function runPlugin(plugin, params = {}) {
+  const { config, ...rest } = params
+  try {
+    ;(plugin.handler || plugin)({
+      addUtilities: () => {},
+      addComponents: () => {},
+      addBase: () => {},
+      addVariant: () => {},
+      e: (x) => x,
+      prefix: (x) => x,
+      theme: (path, defaultValue) => dlv(config, `theme.${path}`, defaultValue),
+      variants: () => [],
+      config: (path, defaultValue) => dlv(config, path, defaultValue),
+      ...rest,
+    })
+  } catch (_) {}
+}