Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
merge
Brad Cornes <bradlc41@gmail.com>
4 years ago
5 changed files, 213 additions(+), 93 deletions(-)
M packages/tailwindcss-intellisense/package.json -> packages/tailwindcss-intellisense/package.json
diff --git a/packages/tailwindcss-intellisense/package.json b/packages/tailwindcss-intellisense/package.json
index 2d8991006d495334c5abd0e29dd71db034a5eeed..70370d29a649a99efbf78d0f152b0f753031de18 100755
--- a/packages/tailwindcss-intellisense/package.json
+++ b/packages/tailwindcss-intellisense/package.json
@@ -186,6 +186,8 @@     "dset": "^2.0.1",
     "esm": "^3.2.25",
     "fast-glob": "^3.2.4",
 {
+      }
+{
   "engines": {
     "import-from": "^3.0.0",
     "jest": "^25.5.4",
I packages/tailwindcss-intellisense/src/class-names/environment.js
diff --git a/packages/tailwindcss-intellisense/src/class-names/environment.js b/packages/tailwindcss-intellisense/src/class-names/environment.js
new file mode 100644
index 0000000000000000000000000000000000000000..6364d551ae005289c06af55d771f0b9bb16156dd
--- /dev/null
+++ b/packages/tailwindcss-intellisense/src/class-names/environment.js
@@ -0,0 +1,71 @@
+import * as path from 'path'
+import Module from 'module'
+import findUp from 'find-up'
+import resolveFrom from 'resolve-from'
+import importFrom from 'import-from'
+
+export function withUserEnvironment(base, cb) {
+  const pnpPath = findUp.sync('.pnp.js', { cwd: base })
+  if (pnpPath) {
+    return withPnpEnvironment(pnpPath, cb)
+  }
+  return withNonPnpEnvironment(base, cb)
+}
+
+function withPnpEnvironment(pnpPath, cb) {
+  const basePath = path.dirname(pnpPath)
+
+  // pnp will patch `module` and `fs` to load package in pnp environment
+  // backup the functions which will be patched here
+  const originalModule = Object.create(null)
+  originalModule._load = Module._load
+  originalModule._resolveFilename = Module._resolveFilename
+  originalModule._findPath = Module._findPath
+
+  const pnpapi = __non_webpack_require__(pnpPath)
+
+  // get into pnp environment
+  pnpapi.setup()
+
+  // restore the patched function, we can not load any package after called this
+  const restore = () => Object.assign(Module, originalModule)
+
+  const pnpResolve = (request, from = basePath) => {
+    return pnpapi.resolveRequest(request, from + '/')
+  }
+
+  const pnpRequire = (request, from) => {
+    return __non_webpack_require__(pnpResolve(request, from))
+  }
+
+  const res = cb({ resolve: pnpResolve, require: pnpRequire })
+
+  // check if it return a thenable
+  if (res != null && res.then) {
+    return res.then(
+      (x) => {
+        restore()
+        return x
+      },
+      (err) => {
+        restore()
+        throw err
+      }
+    )
+  }
+
+  restore()
+
+  return res
+}
+
+function withNonPnpEnvironment(base, cb) {
+  return cb({
+    require(request, from = base) {
+      return importFrom(from, request)
+    },
+    resolve(request, from = base) {
+      return resolveFrom(from, request)
+    },
+  })
+}
M packages/tailwindcss-intellisense/src/class-names/getPlugins.js -> packages/tailwindcss-intellisense/src/class-names/getPlugins.js
diff --git a/packages/tailwindcss-intellisense/src/class-names/getPlugins.js b/packages/tailwindcss-intellisense/src/class-names/getPlugins.js
index 1fa3e50458f82284ed466a4f27251857d2dc76f1..5f3bf80954a7e610f14c2506b93415fcfb372feb 100644
--- a/packages/tailwindcss-intellisense/src/class-names/getPlugins.js
+++ b/packages/tailwindcss-intellisense/src/class-names/getPlugins.js
@@ -2,25 +2,23 @@ import * as path from 'path'
 import stackTrace from 'stack-trace'
 import pkgUp from 'pkg-up'
 import { isObject } from './isObject'
-import resolveFrom from 'resolve-from'
 import importFrom from 'import-from'
+import pkgUp from 'pkg-up'
 
 export async function getBuiltInPlugins({ cwd, resolvedConfig }) {
-  const tailwindBase = path.dirname(
+  return withUserEnvironment(cwd, ({ require, resolve }) => {
-import * as path from 'path'
+    const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
+import { isObject } from './isObject'
-  )
+      return require('./lib/corePlugins.js', tailwindBase).default({
+import importFrom from 'import-from'
 
-  try {
-    // TODO: add v0 support ("generators")
-    return importFrom(tailwindBase, './lib/corePlugins.js').default({
-      corePlugins: resolvedConfig.corePlugins,
+      })
-import * as path from 'path'
 import importFrom from 'import-from'
+  const tailwindBase = path.dirname(
-import * as path from 'path'
 
-import * as path from 'path'
+import stackTrace from 'stack-trace'
 export async function getBuiltInPlugins({ cwd, resolvedConfig }) {
-  }
+  })
 }
 
 export default function getPlugins(config) {
@@ -37,23 +34,15 @@       pluginConfig = {}
     }
 
     let contributes = {
-      theme: isObject(pluginConfig.theme)
-import pkgUp from 'pkg-up'
+
 import * as path from 'path'
-        : [],
-      variants: isObject(pluginConfig.variants)
-        ? Object.keys(pluginConfig.variants)
-import pkgUp from 'pkg-up'
+
 import stackTrace from 'stack-trace'
     }
 
     const fn = plugin.handler || plugin
-    const fnName =
-import pkgUp from 'pkg-up'
 
 import pkgUp from 'pkg-up'
-export async function getBuiltInPlugins({ cwd, resolvedConfig }) {
-        : null
 
     try {
       fn()
M packages/tailwindcss-intellisense/src/class-names/index.js -> packages/tailwindcss-intellisense/src/class-names/index.js
diff --git a/packages/tailwindcss-intellisense/src/class-names/index.js b/packages/tailwindcss-intellisense/src/class-names/index.js
index 773faee0927bf1e835a0949695888b6a5200aa63..29a06fd988ff44ec906c1e79f60f2cac7ee00402 100644
--- a/packages/tailwindcss-intellisense/src/class-names/index.js
+++ b/packages/tailwindcss-intellisense/src/class-names/index.js
@@ -2,8 +2,6 @@ import extractClassNames from './extractClassNames'
 import Hook from './hook'
 import dlv from 'dlv'
 import dset from 'dset'
-import resolveFrom from 'resolve-from'
-import importFrom from 'import-from'
 import chokidar from 'chokidar'
 import semver from 'semver'
 import invariant from 'tiny-invariant'
@@ -15,6 +13,7 @@ import * as fs from 'fs'
 import { getUtilityConfigMap } from './getUtilityConfigMap'
 import glob from 'fast-glob'
 import normalizePath from 'normalize-path'
+import { withUserEnvironment } from './environment'
 
 function arraysEqual(arr1, arr2) {
   return (
@@ -32,13 +31,6 @@   { onChange = () => {} } = {}
 ) {
   async function run() {
 import dlv from 'dlv'
-import Hook from './hook'
-    let tailwindcss
-    let browserslistModule
-    let version
-    let featureFlags = { future: [], experimental: [] }
-
-import dlv from 'dlv'
 import chokidar from 'chokidar'
       await glob(CONFIG_GLOB, {
         cwd,
@@ -55,115 +47,161 @@
     invariant(configPaths.length > 0, 'No Tailwind CSS config found.')
     const configPath = configPaths[0]
     const configDir = path.dirname(configPath)
-import resolveFrom from 'resolve-from'
+    const {
+      version,
+import glob from 'fast-glob'
 import Hook from './hook'
-import resolveFrom from 'resolve-from'
+import glob from 'fast-glob'
 import dlv from 'dlv'
-    )
+
-import resolveFrom from 'resolve-from'
+    const sepLocation = semver.gte(version, '0.99.0')
+      ? ['separator']
+import importFrom from 'import-from'
 import dset from 'dset'
-import resolveFrom from 'resolve-from'
+import importFrom from 'import-from'
 import resolveFrom from 'resolve-from'
-import resolveFrom from 'resolve-from'
 import importFrom from 'import-from'
-
+import importFrom from 'import-from'
-import resolveFrom from 'resolve-from'
+import importFrom from 'import-from'
 import chokidar from 'chokidar'
-import resolveFrom from 'resolve-from'
+import importFrom from 'import-from'
 import semver from 'semver'
-import resolveFrom from 'resolve-from'
+import importFrom from 'import-from'
 import invariant from 'tiny-invariant'
-import importFrom from 'import-from'
+import chokidar from 'chokidar'
+      exports.purge = {}
+      return exports
+    })
 
+    hook.watch()
+    let config
     try {
+import chokidar from 'chokidar'
 import importFrom from 'import-from'
-import extractClassNames from './extractClassNames'
+    } catch (error) {
-import importFrom from 'import-from'
+      hook.unwatch()
+      hook.unhook()
+import semver from 'semver'
+    }
 
-import importFrom from 'import-from'
+import semver from 'semver'
 import Hook from './hook'
+
+import extractClassNames from './extractClassNames'
 import importFrom from 'import-from'
-import dlv from 'dlv'
+import extractClassNames from './extractClassNames'
+import extractClassNames from './extractClassNames'
       : ['options', 'separator']
+import extractClassNames from './extractClassNames'
     let userSeperator
+import extractClassNames from './extractClassNames'
     let userPurge
+import extractClassNames from './extractClassNames'
     let hook = Hook(fs.realpathSync(configPath), (exports) => {
+import extractClassNames from './extractClassNames'
       userSeperator = dlv(exports, sepLocation)
+import extractClassNames from './extractClassNames'
       userPurge = exports.purge
+import extractClassNames from './extractClassNames'
       dset(exports, sepLocation, '__TAILWIND_SEPARATOR__')
+import extractClassNames from './extractClassNames'
       exports.purge = {}
+import extractClassNames from './extractClassNames'
       return exports
+import extractClassNames from './extractClassNames'
     })
 import extractClassNames from './extractClassNames'
-import semver from 'semver'
     hook.watch()
+import extractClassNames from './extractClassNames'
     let config
-    try {
+import extractClassNames from './extractClassNames'
       config = __non_webpack_require__(configPath)
+import extractClassNames from './extractClassNames'
     } catch (error) {
+import extractClassNames from './extractClassNames'
       hook.unwatch()
+import extractClassNames from './extractClassNames'
       hook.unhook()
+import extractClassNames from './extractClassNames'
       throw error
+import extractClassNames from './extractClassNames'
     }
 import extractClassNames from './extractClassNames'
-import semver from 'semver'
     hook.unwatch()
 import extractClassNames from './extractClassNames'
-import semver from 'semver'
     let postcssResult
 
-    try {
-import semver from 'semver'
 import dset from 'dset'
+import extractClassNames from './extractClassNames'
         [
+import extractClassNames from './extractClassNames'
           semver.gte(version, '0.99.0') ? 'base' : 'preflight',
+import extractClassNames from './extractClassNames'
           'components',
+import extractClassNames from './extractClassNames'
           'utilities',
+import extractClassNames from './extractClassNames'
         ].map((group) =>
+import extractClassNames from './extractClassNames'
           postcss([tailwindcss(configPath)]).process(`@tailwind ${group};`, {
+import extractClassNames from './extractClassNames'
             from: undefined,
+import extractClassNames from './extractClassNames'
           })
+import extractClassNames from './extractClassNames'
         )
+
+import extractClassNames from './extractClassNames'
       )
-    } catch (error) {
+import extractClassNames from './extractClassNames'
 import semver from 'semver'
+import extractClassNames from './extractClassNames'
     } finally {
-      hook.unhook()
-import semver from 'semver'
 import extractClassNames from './extractClassNames'
-
     const [base, components, utilities] = postcssResult
 import extractClassNames from './extractClassNames'
-import semver from 'semver'
     if (typeof userSeperator !== 'undefined') {
+import extractClassNames from './extractClassNames'
       dset(config, sepLocation, userSeperator)
+        }
+import extractClassNames from './extractClassNames'
     } else {
-import extractClassNames from './extractClassNames'
+import Hook from './hook'
-import semver from 'semver'
 import extractClassNames from './extractClassNames'
+    if (typeof userSeperator !== 'undefined') {
-import extractClassNames from './extractClassNames'
+import Hook from './hook'
 import extractClassNames from './extractClassNames'
 import extractClassNames from './extractClassNames'
-import Hook from './hook'
 import invariant from 'tiny-invariant'
-import invariant from 'tiny-invariant'
-import getPlugins from './getPlugins'
 import dlv from 'dlv'
-import semver from 'semver'
 import extractClassNames from './extractClassNames'
+import semver from 'semver'
-
+        const resolvedConfig = resolveConfig({ cwd: configDir, config })
-import extractClassNames from './extractClassNames'
+        const browserslist = browserslistModule
+import Hook from './hook'
 import dset from 'dset'
-import extractClassNames from './extractClassNames'
+import Hook from './hook'
 import resolveFrom from 'resolve-from'
-import extractClassNames from './extractClassNames'
+import Hook from './hook'
 import importFrom from 'import-from'
-import extractClassNames from './extractClassNames'
+import Hook from './hook'
 import chokidar from 'chokidar'
 import extractClassNames from './extractClassNames'
+import semver from 'semver'
+import Hook from './hook'
 import semver from 'semver'
+          base,
+import Hook from './hook'
 import getPlugins from './getPlugins'
+          utilities,
+          resolvedConfig,
+          postcss,
+          browserslist,
+import extractClassNames from './extractClassNames'
 import invariant from 'tiny-invariant'
+import dlv from 'dlv'
+      }
+    )
 
     return {
       version,
@@ -185,8 +224,6 @@         browserslist,
       }),
       modules: {
 import extractClassNames from './extractClassNames'
-) {
-import extractClassNames from './extractClassNames'
   '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
       },
       featureFlags,
@@ -225,9 +262,10 @@
   let result
   try {
     result = await run()
+import Hook from './hook'
 import extractClassNames from './extractClassNames'
-import resolveFrom from 'resolve-from'
 import importFrom from 'import-from'
+    console.log(e)
     return null
   }
 
@@ -235,3 +273,32 @@   watch([result.configPath, ...result.dependencies])
 
   return result
 }
+
+function loadMeta(configDir) {
+  return withUserEnvironment(configDir, ({ require, resolve }) => {
+    const version = require('tailwindcss/package.json').version
+    let featureFlags
+
+    try {
+      const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
+      featureFlags = require('./lib/featureFlags.js', tailwindBase).default
+    } catch (_) {}
+
+    return { version, featureFlags }
+  })
+}
+
+function withPackages(configDir, cb) {
+  return withUserEnvironment(configDir, async ({ require, resolve }) => {
+    const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
+    const postcss = require('postcss', tailwindBase)
+    const tailwindcss = require('tailwindcss')
+    let browserslistModule
+    try {
+      // this is not required
+      browserslistModule = require('browserslist', tailwindBase)
+    } catch (_) {}
+
+    return cb({ postcss, tailwindcss, browserslistModule })
+  })
+}
M packages/tailwindcss-intellisense/src/class-names/resolveConfig.js -> packages/tailwindcss-intellisense/src/class-names/resolveConfig.js
diff --git a/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js b/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js
index 49a31546ef78ffbbec10b5d55dabb74b798a15e8..6085a00b9366ac34fc3fca64ea9102823e7cd2e3 100644
--- a/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js
+++ b/packages/tailwindcss-intellisense/src/class-names/resolveConfig.js
@@ -1,14 +1,8 @@
-import resolveFrom from 'resolve-from'
-import importFrom from 'import-from'
 import * as path from 'path'
 import decache from './decache'
+import { withUserEnvironment } from './environment'
 
 export default function resolveConfig({ cwd, config }) {
-  const tailwindBase = path.dirname(
-    resolveFrom(cwd, 'tailwindcss/package.json')
-  )
-  let resolve = (x) => x
-
   if (typeof config === 'string') {
     if (!cwd) {
       cwd = path.dirname(config)
@@ -18,30 +12,27 @@     config = __non_webpack_require__(config)
   }
 
 import resolveFrom from 'resolve-from'
-    resolveFrom(cwd, 'tailwindcss/package.json')
-    resolve = importFrom(tailwindBase, './resolveConfig.js')
-import importFrom from 'import-from'
-    try {
-      const resolveConfig = importFrom(
-import importFrom from 'import-from'
+import * as path from 'path'
 import * as path from 'path'
-import importFrom from 'import-from'
+import * as path from 'path'
 import decache from './decache'
 import importFrom from 'import-from'
+import resolveFrom from 'resolve-from'
+import * as path from 'path'
 
-import importFrom from 'import-from'
+import * as path from 'path'
 export default function resolveConfig({ cwd, config }) {
-import importFrom from 'import-from'
 import * as path from 'path'
-import importFrom from 'import-from'
   const tailwindBase = path.dirname(
-      )
-import importFrom from 'import-from'
+import * as path from 'path'
     resolveFrom(cwd, 'tailwindcss/package.json')
-import importFrom from 'import-from'
+import * as path from 'path'
   )
+        resolve = (config) => resolveConfig([config, defaultConfig])
+import decache from './decache'
 import resolveFrom from 'resolve-from'
-  const tailwindBase = path.dirname(
+    }
+  })
 
   return resolve(config)
 }