@@ -206,62 +206,7 @@ export class ProjectLocator {
206
206
// Look for the package root for the config
207
207
config . packageRoot = await getPackageRoot ( path . dirname ( config . path ) , this . base )
208
208
209
- let selectors : DocumentSelector [ ] = [ ]
210
-
211
- // selectors:
212
- // - CSS files
213
- for ( let entry of config . entries ) {
214
- if ( entry . type !== 'css' ) continue
215
- selectors . push ( {
216
- pattern : entry . path ,
217
- priority : DocumentSelectorPriority . CSS_FILE ,
218
- } )
219
- }
220
-
221
- // - Config File
222
- selectors . push ( {
223
- pattern : config . path ,
224
- priority : DocumentSelectorPriority . CONFIG_FILE ,
225
- } )
226
-
227
- // - Content patterns from config
228
- for ( let selector of await calculateDocumnetSelectors (
229
- config ,
230
- tailwind . features ,
231
- this . resolver ,
232
- ) ) {
233
- selectors . push ( selector )
234
- }
235
-
236
- // - Directories containing the CSS files
237
- for ( let entry of config . entries ) {
238
- if ( entry . type !== 'css' ) continue
239
- selectors . push ( {
240
- pattern : normalizePath ( path . join ( path . dirname ( entry . path ) , '**' ) ) ,
241
- priority : DocumentSelectorPriority . CSS_DIRECTORY ,
242
- } )
243
- }
244
-
245
- // - Directory containing the config
246
- selectors . push ( {
247
- pattern : normalizePath ( path . join ( path . dirname ( config . path ) , '**' ) ) ,
248
- priority : DocumentSelectorPriority . CONFIG_DIRECTORY ,
249
- } )
250
-
251
- // - Root of package that contains the config
252
- selectors . push ( {
253
- pattern : normalizePath ( path . join ( config . packageRoot , '**' ) ) ,
254
- priority : DocumentSelectorPriority . PACKAGE_DIRECTORY ,
255
- } )
256
-
257
- // Reorder selectors from most specific to least specific
258
- selectors . sort ( ( a , z ) => a . priority - z . priority )
259
-
260
- // Eliminate duplicate selector patterns
261
- selectors = selectors . filter (
262
- ( { pattern } , index , documentSelectors ) =>
263
- documentSelectors . findIndex ( ( { pattern : p } ) => p === pattern ) === index ,
264
- )
209
+ let selectors = await calculateDocumentSelectors ( config , tailwind . features , this . resolver )
265
210
266
211
return {
267
212
config,
@@ -795,26 +740,66 @@ function requiresPreprocessor(filepath: string) {
795
740
return ext === '.scss' || ext === '.sass' || ext === '.less' || ext === '.styl' || ext === '.pcss'
796
741
}
797
742
798
- export async function calculateDocumnetSelectors (
799
- entry : ConfigEntry ,
743
+ export async function calculateDocumentSelectors (
744
+ config : ConfigEntry ,
800
745
features : Feature [ ] ,
801
746
resolver : Resolver ,
802
- existing ?: DocumentSelector [ ] ,
803
747
actualConfig ?: any ,
804
748
) {
805
- let selectors = [ ]
749
+ let selectors : DocumentSelector [ ] = [ ]
806
750
807
- for ( let selector of existing ?? [ ] ) {
808
- if ( selector . priority === DocumentSelectorPriority . CONTENT_FILE ) {
809
- continue
810
- }
751
+ // selectors:
752
+ // - CSS files
753
+ for ( let entry of config . entries ) {
754
+ if ( entry . type !== 'css' ) continue
811
755
812
- selectors . push ( selector )
756
+ selectors . push ( {
757
+ pattern : entry . path ,
758
+ priority : DocumentSelectorPriority . CSS_FILE ,
759
+ } )
813
760
}
814
761
815
- for await ( let selector of contentSelectorsFromConfig ( entry , features , resolver , actualConfig ) ) {
762
+ // - Config File
763
+ selectors . push ( {
764
+ pattern : config . path ,
765
+ priority : DocumentSelectorPriority . CONFIG_FILE ,
766
+ } )
767
+
768
+ // - Content patterns from config
769
+ for await ( let selector of contentSelectorsFromConfig ( config , features , resolver , actualConfig ) ) {
816
770
selectors . push ( selector )
817
771
}
818
772
773
+ // - Directories containing the CSS files
774
+ for ( let entry of config . entries ) {
775
+ if ( entry . type !== 'css' ) continue
776
+
777
+ selectors . push ( {
778
+ pattern : normalizePath ( path . join ( path . dirname ( entry . path ) , '**' ) ) ,
779
+ priority : DocumentSelectorPriority . CSS_DIRECTORY ,
780
+ } )
781
+ }
782
+
783
+ // - Directory containing the config
784
+ selectors . push ( {
785
+ pattern : normalizePath ( path . join ( path . dirname ( config . path ) , '**' ) ) ,
786
+ priority : DocumentSelectorPriority . CONFIG_DIRECTORY ,
787
+ } )
788
+
789
+ // - Root of package that contains the config
790
+ selectors . push ( {
791
+ pattern : normalizePath ( path . join ( config . packageRoot , '**' ) ) ,
792
+ priority : DocumentSelectorPriority . PACKAGE_DIRECTORY ,
793
+ } )
794
+
795
+ // Reorder selectors from most specific to least specific
796
+ selectors . sort ( ( a , z ) => a . priority - z . priority )
797
+
798
+ // Eliminate duplicate selector patterns
799
+ selectors = selectors . filter (
800
+ ( { pattern } , index , documentSelectors ) =>
801
+ documentSelectors . findIndex ( ( { pattern : p } ) => p === pattern ) === index ,
802
+ )
803
+
819
804
return selectors
820
805
}
0 commit comments