@@ -69,6 +69,7 @@ import { getDocumentColors } from 'tailwindcss-language-service/src/documentColo
6969import { fromRatio , names as namedColors } from '@ctrl/tinycolor'
7070import { debounce } from 'debounce'
7171import { getModuleDependencies } from './util/getModuleDependencies'
72+ import assert from 'assert'
7273// import postcssLoadConfig from 'postcss-load-config'
7374
7475const CONFIG_FILE_GLOB = '{tailwind,tailwind.config}.{js,cjs}'
@@ -132,6 +133,19 @@ function getConfigId(configPath: string, configDependencies: string[]): string {
132133 )
133134}
134135
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+
135149interface ProjectService {
136150 state : State
137151 tryInit : ( ) => Promise < void >
@@ -442,23 +456,38 @@ async function createProjectService(
442456 let tailwindDirectives = new Set ( )
443457 let root = postcss . root ( )
444458 let result = { opts : { } , messages : [ ] }
459+ let registerDependency = ( ) => { }
445460
446461 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+ )
462491
463492 jitModules = {
464493 generateRules : {
0 commit comments