Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
use decache when resolving config
Brad Cornes <brad@parall.ax>
4 years ago
4 changed files, 92 additions(+), 0 deletions(-)
M packages/tailwindcss-class-names/package-lock.json -> packages/tailwindcss-class-names/package-lock.json
diff --git a/packages/tailwindcss-class-names/package-lock.json b/packages/tailwindcss-class-names/package-lock.json
index 3b01dc39ff179d1a58c62763051d86c30b21c626..3faef87f40fde821bff41d8cde1b4fe207e866b8 100644
--- a/packages/tailwindcss-class-names/package-lock.json
+++ b/packages/tailwindcss-class-names/package-lock.json
@@ -1258,6 +1258,11 @@         "union-value": "^1.0.0",
         "unset-value": "^1.0.0"
       }
     },
+    "callsite": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
+      "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
+    },
     "callsites": {
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
M packages/tailwindcss-class-names/package.json -> packages/tailwindcss-class-names/package.json
diff --git a/packages/tailwindcss-class-names/package.json b/packages/tailwindcss-class-names/package.json
index a1aafbe06c8c34588e6d7d5d2b8eca8b345b979f..96d93104867f856e1d341e549409275db92d578f 100644
--- a/packages/tailwindcss-class-names/package.json
+++ b/packages/tailwindcss-class-names/package.json
@@ -12,6 +12,7 @@   "keywords": [],
   "author": "Brad Cornes <hello@bradley.dev>",
   "license": "MIT",
   "dependencies": {
+    "callsite": "^1.0.0",
     "chokidar": "^3.3.1",
     "dlv": "^1.1.3",
     "dset": "^2.0.1",
I packages/tailwindcss-class-names/src/decache.js
diff --git a/packages/tailwindcss-class-names/src/decache.js b/packages/tailwindcss-class-names/src/decache.js
new file mode 100644
index 0000000000000000000000000000000000000000..638cd5daa2de61f52f46519d27a21ed88c39a056
--- /dev/null
+++ b/packages/tailwindcss-class-names/src/decache.js
@@ -0,0 +1,84 @@
+import * as path from 'path' // if module is locally defined we path.resolve it
+import callsite from 'callsite'
+import Module from 'module'
+
+function find(moduleName) {
+  if (moduleName[0] === '.') {
+    var stack = callsite()
+    for (var i in stack) {
+      var filename = stack[i].getFileName()
+      // if (filename !== module.filename) {
+      moduleName = path.resolve(path.dirname(filename), moduleName)
+      break
+      // }
+    }
+  }
+  try {
+    return __non_webpack_require__.resolve(moduleName)
+  } catch (e) {
+    return
+  }
+}
+
+/**
+ * Removes a module from the cache. We need this to re-load our http_request !
+ * see: http://stackoverflow.com/a/14801711/1148249
+ */
+function decache(moduleName) {
+  moduleName = find(moduleName)
+
+  if (!moduleName) {
+    return
+  }
+
+  // Run over the cache looking for the files
+  // loaded by the specified module name
+  searchCache(moduleName, function(mod) {
+    delete __non_webpack_require__.cache[mod.id]
+  })
+
+  // Remove cached paths to the module.
+  // Thanks to @bentael for pointing this out.
+  Object.keys(Module.prototype.constructor._pathCache).forEach(function(
+    cacheKey
+  ) {
+    if (cacheKey.indexOf(moduleName) > -1) {
+      delete Module.prototype.constructor._pathCache[cacheKey]
+    }
+  })
+}
+
+/**
+ * Runs over the cache to search for all the cached
+ * files
+ */
+function searchCache(moduleName, callback) {
+  // Resolve the module identified by the specified name
+  var mod = __non_webpack_require__.resolve(moduleName)
+  var visited = {}
+
+  // Check if the module has been resolved and found within
+  // the cache no else so #ignore else http://git.io/vtgMI
+  /* istanbul ignore else */
+  if (mod && (mod = __non_webpack_require__.cache[mod]) !== undefined) {
+    // Recursively go over the results
+    ;(function run(current) {
+      visited[current.id] = true
+      // Go over each of the module's children and
+      // run over it
+      current.children.forEach(function(child) {
+        // ignore .node files, decachine native modules throws a
+        // "module did not self-register" error on second require
+        if (path.extname(child.filename) !== '.node' && !visited[child.id]) {
+          run(child)
+        }
+      })
+
+      // Call the specified callback providing the
+      // found module
+      callback(current)
+    })(mod)
+  }
+}
+
+export default decache
M packages/tailwindcss-class-names/src/resolveConfig.js -> packages/tailwindcss-class-names/src/resolveConfig.js
diff --git a/packages/tailwindcss-class-names/src/resolveConfig.js b/packages/tailwindcss-class-names/src/resolveConfig.js
index 9d158c4592bbfb435335825e00b3d20e9562703a..ebd33cef749a337c6eaf48ce550a1f69175f5f8e 100644
--- a/packages/tailwindcss-class-names/src/resolveConfig.js
+++ b/packages/tailwindcss-class-names/src/resolveConfig.js
@@ -1,5 +1,6 @@
 import importFrom from 'import-from'
 import * as path from 'path'
+import decache from './decache'
 
 export default function resolveConfig({ cwd, config }) {
   let resolve = x => x
@@ -8,6 +9,7 @@   if (typeof config === 'string') {
     if (!cwd) {
       cwd = path.dirname(config)
     }
+    decache(config)
     config = __non_webpack_require__(config)
   }