Home

tailwind-ctp-intellisense @b6d257c8434ac9cd2f48caf47124b342e2957c83 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-server / src / util / resolveFrom.ts
- 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
import * as fs from 'fs'
import { CachedInputFileSystem, ResolverFactory, Resolver, ResolveOptions } from 'enhanced-resolve-301'
import { equal } from 'tailwindcss-language-service/src/util/array'

let pnpApi: any
let extensions = Object.keys(require.extensions)

function createResolver(options: Partial<ResolveOptions> = {}): Resolver {
  return ResolverFactory.createResolver({
    fileSystem: new CachedInputFileSystem(fs, 4000),
    useSyncFileSystemCalls: true,
    // cachePredicate: () => false,
    conditionNames: ['node', 'require'],
    extensions,
    pnpApi,
    ...options,
  })
}

let resolver = createResolver()

export function setPnpApi(newPnpApi: any): void {
  pnpApi = newPnpApi
  resolver = createResolver()
}

export default function resolveFrom(from?: string, id?: string): string {
  if (id.startsWith('\\\\')) return id

  let newExtensions = Object.keys(require.extensions)
  if (!equal(newExtensions, extensions)) {
    extensions = newExtensions
    resolver = createResolver()
  }

  let result = resolver.resolveSync({}, from, id)
  if (result === false) throw Error()
  // https://github.com/webpack/enhanced-resolve/issues/282
  return result.replace(/\0#/g, '#')
}