@@ -16,6 +16,7 @@ import { normalizeDriveLetter, normalizePath, pathToFileURL } from './utils'
1616import postcss from 'postcss'
1717import * as oxide from './oxide'
1818import { analyzeStylesheet , TailwindStylesheet } from './version-guesser'
19+ import { OxideSession } from './oxide-session'
1920
2021export interface ProjectConfig {
2122 /** The folder that contains the project */
@@ -60,7 +61,10 @@ export class ProjectLocator {
6061 let configs = await this . findConfigs ( )
6162
6263 // Create a project for each of the config files
63- let results = await Promise . allSettled ( configs . map ( ( config ) => this . createProject ( config ) ) )
64+ let session = new OxideSession ( )
65+ let results = await Promise . allSettled (
66+ configs . map ( ( config ) => this . createProject ( config , session ) ) ,
67+ )
6468 let projects : ProjectConfig [ ] = [ ]
6569
6670 for ( let result of results ) {
@@ -71,6 +75,8 @@ export class ProjectLocator {
7175 }
7276 }
7377
78+ console . log ( projects [ 0 ] )
79+
7480 if ( projects . length === 1 ) {
7581 projects [ 0 ] . additionalSelectors . push ( {
7682 pattern : normalizePath ( path . join ( this . base , '**' ) ) ,
@@ -98,6 +104,8 @@ export class ProjectLocator {
98104 }
99105 }
100106
107+ await session . stop ( )
108+
101109 return projects
102110 }
103111
@@ -148,7 +156,10 @@ export class ProjectLocator {
148156 }
149157 }
150158
151- private async createProject ( config : ConfigEntry ) : Promise < ProjectConfig | null > {
159+ private async createProject (
160+ config : ConfigEntry ,
161+ session : OxideSession ,
162+ ) : Promise < ProjectConfig | null > {
152163 let tailwind = await this . detectTailwindVersion ( config )
153164
154165 let possibleVersions = config . entries . flatMap ( ( entry ) => entry . meta ?. versions ?? [ ] )
@@ -218,7 +229,12 @@ export class ProjectLocator {
218229 // Look for the package root for the config
219230 config . packageRoot = await getPackageRoot ( path . dirname ( config . path ) , this . base )
220231
221- let selectors = await calculateDocumentSelectors ( config , tailwind . features , this . resolver )
232+ let selectors = await calculateDocumentSelectors (
233+ config ,
234+ tailwind . features ,
235+ this . resolver ,
236+ session ,
237+ )
222238
223239 return {
224240 config,
@@ -520,10 +536,11 @@ function contentSelectorsFromConfig(
520536 entry : ConfigEntry ,
521537 features : Feature [ ] ,
522538 resolver : Resolver ,
539+ session : OxideSession ,
523540 actualConfig ?: any ,
524541) : AsyncIterable < DocumentSelector > {
525542 if ( entry . type === 'css' ) {
526- return contentSelectorsFromCssConfig ( entry , resolver )
543+ return contentSelectorsFromCssConfig ( entry , resolver , session )
527544 }
528545
529546 if ( entry . type === 'js' ) {
@@ -582,6 +599,7 @@ async function* contentSelectorsFromJsConfig(
582599async function * contentSelectorsFromCssConfig (
583600 entry : ConfigEntry ,
584601 resolver : Resolver ,
602+ session : OxideSession ,
585603) : AsyncIterable < DocumentSelector > {
586604 let auto = false
587605 for ( let item of entry . content ) {
@@ -606,6 +624,7 @@ async function* contentSelectorsFromCssConfig(
606624 entry . path ,
607625 sources ,
608626 resolver ,
627+ session ,
609628 ) ) {
610629 yield {
611630 pattern,
@@ -621,14 +640,15 @@ async function* detectContentFiles(
621640 inputFile : string ,
622641 sources : SourcePattern [ ] ,
623642 resolver : Resolver ,
643+ session : OxideSession ,
624644) : AsyncIterable < string > {
625645 try {
626646 let oxidePath = await resolver . resolveJsId ( '@tailwindcss/oxide' , base )
627647 oxidePath = pathToFileURL ( oxidePath ) . href
628648 let oxidePackageJsonPath = await resolver . resolveJsId ( '@tailwindcss/oxide/package.json' , base )
629649 let oxidePackageJson = JSON . parse ( await fs . readFile ( oxidePackageJsonPath , 'utf8' ) )
630650
631- let result = await oxide . scan ( {
651+ let result = await session . scan ( {
632652 oxidePath,
633653 oxideVersion : oxidePackageJson . version ,
634654 basePath : base ,
@@ -654,8 +674,8 @@ async function* detectContentFiles(
654674 base = normalizeDriveLetter ( base )
655675 yield `${ base } /${ pattern } `
656676 }
657- } catch {
658- //
677+ } catch ( err ) {
678+ console . log ( { err } )
659679 }
660680}
661681
@@ -812,8 +832,15 @@ export async function calculateDocumentSelectors(
812832 config : ConfigEntry ,
813833 features : Feature [ ] ,
814834 resolver : Resolver ,
835+ session ?: OxideSession ,
815836 actualConfig ?: any ,
816837) {
838+ let hasTemporarySession = false
839+ if ( ! session ) {
840+ hasTemporarySession = true
841+ session = new OxideSession ( )
842+ }
843+
817844 let selectors : DocumentSelector [ ] = [ ]
818845
819846 // selectors:
@@ -834,7 +861,13 @@ export async function calculateDocumentSelectors(
834861 } )
835862
836863 // - Content patterns from config
837- for await ( let selector of contentSelectorsFromConfig ( config , features , resolver , actualConfig ) ) {
864+ for await ( let selector of contentSelectorsFromConfig (
865+ config ,
866+ features ,
867+ resolver ,
868+ session ,
869+ actualConfig ,
870+ ) ) {
838871 selectors . push ( selector )
839872 }
840873
@@ -876,5 +909,9 @@ export async function calculateDocumentSelectors(
876909 return 0
877910 } )
878911
912+ if ( hasTemporarySession ) {
913+ await session . stop ( )
914+ }
915+
879916 return selectors
880917}
0 commit comments