Home

tailwind-ctp-intellisense @dce390d98ca75bc6a0cf19d29e16ca6422faa924 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-server / src / watcher / index.js
- 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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const os = require('os')
const path = require('path')
const fs = require('fs')

const vars = (process.config && process.config.variables) || {}
const arch = os.arch()
const platform = os.platform()
const abi = process.versions.modules
const runtime = isElectron() ? 'electron' : 'node'
const libc = process.env.LIBC || (isAlpine(platform) ? 'musl' : 'glibc')
const armv = process.env.ARM_VERSION || (arch === 'arm64' ? '8' : vars.arm_version) || ''
const uv = (process.versions.uv || '').split('.')[0]

const prebuilds = {
  'darwin-x64': {
    'node.napi.glibc.node': () =>
      require('@parcel/watcher/prebuilds/darwin-x64/node.napi.glibc.node'),
  },
  'linux-x64': {
    'node.napi.glibc.node': () =>
      require('@parcel/watcher/prebuilds/linux-x64/node.napi.glibc.node'),
    'node.napi.musl.node': () => require('@parcel/watcher/prebuilds/linux-x64/node.napi.musl.node'),
  },
  'win32-x64': {
    'node.napi.glibc.node': () =>
      require('@parcel/watcher/prebuilds/win32-x64/node.napi.glibc.node'),
  },
}

let getBinding = () => {
  let resolved = resolve()
  getBinding = () => resolved
  return resolved
}

exports.getBinding = getBinding

exports.writeSnapshot = (dir, snapshot, opts) => {
  return getBinding().writeSnapshot(
    path.resolve(dir),
    path.resolve(snapshot),
    normalizeOptions(dir, opts)
  )
}

exports.getEventsSince = (dir, snapshot, opts) => {
  return getBinding().getEventsSince(
    path.resolve(dir),
    path.resolve(snapshot),
    normalizeOptions(dir, opts)
  )
}

exports.subscribe = async (dir, fn, opts) => {
  dir = path.resolve(dir)
  opts = normalizeOptions(dir, opts)
  await getBinding().subscribe(dir, fn, opts)

  return {
    unsubscribe() {
      return getBinding().unsubscribe(dir, fn, opts)
    },
  }
}

exports.unsubscribe = (dir, fn, opts) => {
  return getBinding().unsubscribe(path.resolve(dir), fn, normalizeOptions(dir, opts))
}

function resolve() {
  // Find most specific flavor first
  var list = prebuilds[platform + '-' + arch]
  if (!list) return
  var builds = Object.keys(list)
  var parsed = builds.map(parseTags)
  var candidates = parsed.filter(matchTags(runtime, abi))
  var winner = candidates.sort(compareTags(runtime))[0]
  if (winner) {
    try {
      return list[winner.file]()
    } catch (_error) {}
  }
}

function parseTags(file) {
  var arr = file.split('.')
  var extension = arr.pop()
  var tags = { file: file, specificity: 0 }

  if (extension !== 'node') return

  for (var i = 0; i < arr.length; i++) {
    var tag = arr[i]

    if (tag === 'node' || tag === 'electron' || tag === 'node-webkit') {
      tags.runtime = tag
    } else if (tag === 'napi') {
      tags.napi = true
    } else if (tag.slice(0, 3) === 'abi') {
      tags.abi = tag.slice(3)
    } else if (tag.slice(0, 2) === 'uv') {
      tags.uv = tag.slice(2)
    } else if (tag.slice(0, 4) === 'armv') {
      tags.armv = tag.slice(4)
    } else if (tag === 'glibc' || tag === 'musl') {
      tags.libc = tag
    } else {
      continue
    }

    tags.specificity++
  }

  return tags
}

function matchTags(runtime, abi) {
  return function (tags) {
    if (tags == null) return false
    if (tags.runtime !== runtime && !runtimeAgnostic(tags)) return false
    if (tags.abi !== abi && !tags.napi) return false
    if (tags.uv && tags.uv !== uv) return false
    if (tags.armv && tags.armv !== armv) return false
    if (tags.libc && tags.libc !== libc) return false

    return true
  }
}

function runtimeAgnostic(tags) {
  return tags.runtime === 'node' && tags.napi
}

function compareTags(runtime) {
  // Precedence: non-agnostic runtime, abi over napi, then by specificity.
  return function (a, b) {
    if (a.runtime !== b.runtime) {
      return a.runtime === runtime ? -1 : 1
    } else if (a.abi !== b.abi) {
      return a.abi ? -1 : 1
    } else if (a.specificity !== b.specificity) {
      return a.specificity > b.specificity ? -1 : 1
    } else {
      return 0
    }
  }
}

function normalizeOptions(dir, opts = {}) {
  if (Array.isArray(opts.ignore)) {
    opts = Object.assign({}, opts, {
      ignore: opts.ignore.map((ignore) => path.resolve(dir, ignore)),
    })
  }

  return opts
}

function isElectron() {
  if (process.versions && process.versions.electron) return true
  if (process.env.ELECTRON_RUN_AS_NODE) return true
  return typeof window !== 'undefined' && window.process && window.process.type === 'renderer'
}

function isAlpine(platform) {
  return platform === 'linux' && fs.existsSync('/etc/alpine-release')
}