@@ -69,6 +69,7 @@ import { getDocumentColors } from 'tailwindcss-language-service/src/documentColo
69
69
import { fromRatio , names as namedColors } from '@ctrl/tinycolor'
70
70
import { debounce } from 'debounce'
71
71
import { getModuleDependencies } from './util/getModuleDependencies'
72
+ import assert from 'assert'
72
73
// import postcssLoadConfig from 'postcss-load-config'
73
74
74
75
const CONFIG_FILE_GLOB = '{tailwind,tailwind.config}.{js,cjs}'
@@ -132,6 +133,19 @@ function getConfigId(configPath: string, configDependencies: string[]): string {
132
133
)
133
134
}
134
135
136
+ function first < T > ( ...options : Array < ( ) => T > ) : T {
137
+ for ( let i = 0 ; i < options . length ; i ++ ) {
138
+ let option = options [ i ]
139
+ if ( i === options . length - 1 ) {
140
+ return option ( )
141
+ } else {
142
+ try {
143
+ return option ( )
144
+ } catch ( _ ) { }
145
+ }
146
+ }
147
+ }
148
+
135
149
interface ProjectService {
136
150
state : State
137
151
tryInit : ( ) => Promise < void >
@@ -442,23 +456,38 @@ async function createProjectService(
442
456
let tailwindDirectives = new Set ( )
443
457
let root = postcss . root ( )
444
458
let result = { opts : { } , messages : [ ] }
459
+ let registerDependency = ( ) => { }
445
460
446
461
try {
447
- let createContext
448
-
449
- try {
450
- let createContextFn = __non_webpack_require__ (
451
- resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContextUtils' )
452
- ) . createContext
453
- createContext = ( state ) => createContextFn ( state . config )
454
- } catch ( _ ) {
455
- // TODO: only for canary releases so can probably remove
456
- let setupContext = __non_webpack_require__ (
457
- resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContext' )
458
- ) . default
459
- createContext = ( state ) =>
460
- setupContext ( state . configPath , tailwindDirectives ) ( result , root )
461
- }
462
+ let createContext = first (
463
+ ( ) => {
464
+ let createContextFn = __non_webpack_require__ (
465
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContextUtils' )
466
+ ) . createContext
467
+ assert . strictEqual ( typeof createContextFn , 'function' )
468
+ return ( state ) => createContextFn ( state . config )
469
+ } ,
470
+ // TODO: the next two are canary releases only so can probably be removed
471
+ ( ) => {
472
+ let setupTrackingContext = __non_webpack_require__ (
473
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupTrackingContext' )
474
+ ) . default
475
+ assert . strictEqual ( typeof setupTrackingContext , 'function' )
476
+ return ( state ) =>
477
+ setupTrackingContext (
478
+ state . configPath ,
479
+ tailwindDirectives ,
480
+ registerDependency
481
+ ) ( result , root )
482
+ } ,
483
+ ( ) => {
484
+ let setupContext = __non_webpack_require__ (
485
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContext' )
486
+ ) . default
487
+ assert . strictEqual ( typeof setupContext , 'function' )
488
+ return ( state ) => setupContext ( state . configPath , tailwindDirectives ) ( result , root )
489
+ }
490
+ )
462
491
463
492
jitModules = {
464
493
generateRules : {
0 commit comments