11#!/usr/bin/env node
22
3+ import { Scanner } from '@tailwindcss/oxide'
34import { globby } from 'globby'
45import fs from 'node:fs/promises'
56import path from 'node:path'
@@ -19,7 +20,6 @@ import { help } from './commands/help'
1920import { Stylesheet } from './stylesheet'
2021import { args , type Arg } from './utils/args'
2122import { isRepoDirty } from './utils/git'
22- import { hoistStaticGlobParts } from './utils/hoist-static-glob-parts'
2323import { pkg } from './utils/packages'
2424import { eprintln , error , header , highlight , info , relative , success } from './utils/renderer'
2525import * as version from './utils/version'
@@ -227,38 +227,67 @@ async function run() {
227227 }
228228 }
229229
230+ let tailwindRootStylesheets = stylesheets . filter ( ( sheet ) => sheet . isTailwindRoot && sheet . file )
231+
230232 // Migrate source files
231- if ( configBySheet . size > 0 ) {
233+ if ( tailwindRootStylesheets . length > 0 ) {
232234 info ( 'Migrating templates…' )
233235 }
234236 {
237+ let seenFiles = new Set ( )
238+
235239 // 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+ }
244252
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 } ]
247256 }
248- }
249257
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+ }
252270
253271 // Migrate each file
254272 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+ ) ,
256276 )
257277
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+ }
262291 }
263292 }
264293 }
0 commit comments