1
1
#!/usr/bin/env node
2
2
3
+ import { Scanner } from '@tailwindcss/oxide'
3
4
import { globby } from 'globby'
4
5
import fs from 'node:fs/promises'
5
6
import path from 'node:path'
@@ -19,7 +20,6 @@ import { help } from './commands/help'
19
20
import { Stylesheet } from './stylesheet'
20
21
import { args , type Arg } from './utils/args'
21
22
import { isRepoDirty } from './utils/git'
22
- import { hoistStaticGlobParts } from './utils/hoist-static-glob-parts'
23
23
import { pkg } from './utils/packages'
24
24
import { eprintln , error , header , highlight , info , relative , success } from './utils/renderer'
25
25
import * as version from './utils/version'
@@ -227,38 +227,67 @@ async function run() {
227
227
}
228
228
}
229
229
230
+ let tailwindRootStylesheets = stylesheets . filter ( ( sheet ) => sheet . isTailwindRoot && sheet . file )
231
+
230
232
// Migrate source files
231
- if ( configBySheet . size > 0 ) {
233
+ if ( tailwindRootStylesheets . length > 0 ) {
232
234
info ( 'Migrating templates…' )
233
235
}
234
236
{
237
+ let seenFiles = new Set ( )
238
+
235
239
// Template migrations
236
- for ( let config of configBySheet . values ( ) ) {
237
- let set = new Set < string > ( )
238
- for ( let globEntry of config . sources . flatMap ( ( entry ) => hoistStaticGlobParts ( entry ) ) ) {
239
- let files = await globby ( [ globEntry . pattern ] , {
240
- absolute : true ,
241
- gitignore : true ,
242
- cwd : globEntry . base ,
243
- } )
240
+ for ( let sheet of tailwindRootStylesheets ) {
241
+ let compiler = await sheet . compiler ( )
242
+ if ( ! compiler ) continue
243
+ let designSystem = await sheet . designSystem ( )
244
+ if ( ! designSystem ) continue
245
+
246
+ // Figure out the source files to migrate
247
+ let sources = ( ( ) => {
248
+ // Disable auto source detection
249
+ if ( compiler . root === 'none' ) {
250
+ return [ ]
251
+ }
244
252
245
- for ( let file of files ) {
246
- set . add ( file )
253
+ // No root specified, use the base directory
254
+ if ( compiler . root === null ) {
255
+ return [ { base, pattern : '**/*' , negated : false } ]
247
256
}
248
- }
249
257
250
- let files = Array . from ( set )
251
- files . sort ( )
258
+ // Use the specified root
259
+ return [ { ...compiler . root , negated : false } ]
260
+ } ) ( ) . concat ( compiler . sources )
261
+
262
+ let config = configBySheet . get ( sheet )
263
+ let scanner = new Scanner ( { sources } )
264
+ let filesToMigrate = [ ]
265
+ for ( let file of scanner . files ) {
266
+ if ( seenFiles . has ( file ) ) continue
267
+ seenFiles . add ( file )
268
+ filesToMigrate . push ( file )
269
+ }
252
270
253
271
// Migrate each file
254
272
await Promise . allSettled (
255
- files . map ( ( file ) => migrateTemplate ( config . designSystem , config . userConfig , file ) ) ,
273
+ filesToMigrate . map ( ( file ) =>
274
+ migrateTemplate ( designSystem , config ?. userConfig ?? null , file ) ,
275
+ ) ,
256
276
)
257
277
258
- success (
259
- `Migrated templates for configuration file: ${ highlight ( relative ( config . configFilePath , base ) ) } ` ,
260
- { prefix : '↳ ' } ,
261
- )
278
+ if ( config ?. configFilePath ) {
279
+ success (
280
+ `Migrated templates for configuration file: ${ highlight ( relative ( config . configFilePath , base ) ) } ` ,
281
+ { prefix : '↳ ' } ,
282
+ )
283
+ } else {
284
+ success (
285
+ `Migrated templates for: ${ highlight ( relative ( sheet . file ?? '<unknown>' , base ) ) } ` ,
286
+ {
287
+ prefix : '↳ ' ,
288
+ } ,
289
+ )
290
+ }
262
291
}
263
292
}
264
293
}
0 commit comments