Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
fix pnp config module resolution
Brad Cornes <bradlc41@gmail.com>
4 years ago
2 changed files, 31 additions(+), 32 deletions(-)
packages/tailwindcss-intellisense/src/class-names/environment.jspackages/tailwindcss-intellisense/src/class-names/index.js
M packages/tailwindcss-intellisense/src/class-names/environment.jspackages/tailwindcss-intellisense/src/class-names/environment.js
  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
diff --git a/packages/tailwindcss-intellisense/src/class-names/environment.js b/packages/tailwindcss-intellisense/src/class-names/environment.js
index 2eb5dbd055c602bc3010f2f98b27043d2bedac72..c18806cfeccf37f39a33224beb87e398f02636e5 100644
--- a/packages/tailwindcss-intellisense/src/class-names/environment.js
+++ b/packages/tailwindcss-intellisense/src/class-names/environment.js
@@ -1,13 +1,27 @@
 import * as path from 'path'
-import Module from 'module'
 import findUp from 'find-up'
 import resolveFrom from 'resolve-from'
 import importFrom from 'import-from'
+
+let isPnp
+let pnpApi
 
 export function withUserEnvironment(base, root, cb) {
+  if (isPnp === true) {
+    return withPnpEnvironment(base, cb)
+  }
+
+  if (isPnp === false) {
+    return withNonPnpEnvironment(base, cb)
+  }
+
   const pnpPath = findUp.sync(
     (dir) => {
-      const pnpFile = path.join(dir, '.pnp.js')
+      let pnpFile = path.join(dir, '.pnp.js')
+      if (findUp.sync.exists(pnpFile)) {
+        return pnpFile
+      }
+      pnpFile = path.join(dir, '.pnp.cjs')
       if (findUp.sync.exists(pnpFile)) {
         return pnpFile
       }
@@ -17,62 +31,47 @@       }
     },
     { cwd: base }
   )
+
   if (pnpPath) {
-    return withPnpEnvironment(pnpPath, cb)
+    isPnp = true
+    pnpApi = __non_webpack_require__(pnpPath)
+    pnpApi.setup()
+  } else {
+    isPnp = false
   }
-  return withNonPnpEnvironment(base, cb)
+
+  return withUserEnvironment(base, root, 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 + '/')
+function withPnpEnvironment(base, cb) {
+  const pnpResolve = (request, from = base) => {
+    return pnpApi.resolveRequest(request, from.replace(/\/$/, '') + '/')
   }
 
   const pnpRequire = (request, from) => {
     return __non_webpack_require__(pnpResolve(request, from))
   }
 
-  const res = cb({ isPnP: true, resolve: pnpResolve, require: pnpRequire })
+  const res = cb({ isPnp: true, 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({
-    isPnP: false,
+    isPnp: false,
     require(request, from = base) {
       return importFrom(from, request)
     },
M packages/tailwindcss-intellisense/src/class-names/index.jspackages/tailwindcss-intellisense/src/class-names/index.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
diff --git a/packages/tailwindcss-intellisense/src/class-names/index.js b/packages/tailwindcss-intellisense/src/class-names/index.js
index 98d3dc0b4856787f1c1800e23120ba5464125478..7dedcdf3b7794926419940010372a08991f75d8b 100644
--- a/packages/tailwindcss-intellisense/src/class-names/index.js
+++ b/packages/tailwindcss-intellisense/src/class-names/index.js
@@ -259,7 +259,7 @@ function withPackages(configDir, root, cb) {
   return withUserEnvironment(
     configDir,
     root,
-    async ({ isPnP, require, resolve }) => {
+    async ({ isPnp, require, resolve }) => {
       const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
       const postcss = require('postcss', tailwindBase)
       const tailwindcss = require('tailwindcss')
@@ -274,7 +274,7 @@             require('browserslist/package.json', tailwindBase).bin.browserslist
           ),
           tailwindBase
         )
-        if (isPnP) {
+        if (isPnp) {
           browserslistCommand = 'yarn'
           browserslistArgs = ['node', browserslistBin]
         } else {