Home

tailwind-ctp-intellisense @1c26324860dbfa4de8d4888115be0b57aeb0a59f - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-class-names / src / hook.mjs
- 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
83
84
85
86
/**
 * Adapted from: https://github.com/elastic/require-in-the-middle
 */
import Module from 'module'

export default function Hook(find, onrequire) {
  if (!(this instanceof Hook)) return new Hook(find, onrequire)

  if (typeof Module._resolveFilename !== 'function') {
    throw new Error(
      `Error: Expected Module._resolveFilename to be a function (was: ${typeof Module._resolveFilename}) - aborting!`
    )
  }

  this.cache = {}
  this.deps = []
  this._unhooked = false
  this._origRequire = Module.prototype.require

  let self = this
  let patching = {}

  this._require = Module.prototype.require = function(request) {
    if (self._unhooked) {
      // if the patched require function could not be removed because
      // someone else patched it after it was patched here, we just
      // abort and pass the request onwards to the original require
      return self._origRequire.apply(this, arguments)
    }

    let filename = Module._resolveFilename(request, this)

    // return known patched modules immediately
    if (self.cache.hasOwnProperty(filename)) {
      return self.cache[filename]
    }

    // Check if this module has a patcher in-progress already.
    // Otherwise, mark this module as patching in-progress.
    let patched = patching[filename]
    if (!patched) {
      patching[filename] = true
    }

    let exports = self._origRequire.apply(this, arguments)

    if (filename !== find) {
      if (self._watching) {
        self.deps.push(filename)
      }
      return exports
    }

    // If it's already patched, just return it as-is.
    if (patched) return exports

    // The module has already been loaded,
    // so the patching mark can be cleaned up.
    delete patching[filename]

    // only call onrequire the first time a module is loaded
    if (!self.cache.hasOwnProperty(filename)) {
      // ensure that the cache entry is assigned a value before calling
      // onrequire, in case calling onrequire requires the same module.
      self.cache[filename] = exports
      self.cache[filename] = onrequire(exports)
    }

    return self.cache[filename]
  }
}

Hook.prototype.unhook = function() {
  this._unhooked = true
  if (this._require === Module.prototype.require) {
    Module.prototype.require = this._origRequire
  }
}

Hook.prototype.watch = function() {
  this._watching = true
}

Hook.prototype.unwatch = function() {
  this._watching = false
}