Repository: tailwindlabs/tailwindcss
File: packages/@tailwindcss-upgrade/src/index.ts (TypeScript)

Code before:

    // Discover CSS files in case no files were provided
    if (files.length === 0) {
      info('Searching for CSS files in the current directory and its subdirectories…')

      files = await globby(['**/*.css'], {
        absolute: true,
        gitignore: true,
      })
    }

    // Ensure we are only dealing with CSS files
    files = files.filter((file) => file.endsWith('.css'))

    // Load the stylesheets and their imports
    let sheetsByFile = new Map<string, Stylesheet>()
    let isIgnored = await isGitIgnored()
    let queue = files.slice()
    while (queue.length > 0) {
      let file = queue.shift()!

      // Already handled
      if (sheetsByFile.has(file)) continue

      // We don't want to process ignored files (like node_modules)
      if (isIgnored(file)) continue

      let sheet = await Stylesheet.load(file).catch((e) => {
        error(`${e}`)
        return null
      })
      if (!sheet) continue

      // Track the sheet by its file
      sheetsByFile.set(file, sheet)

      // We process the stylesheet which will also process its imports and
      // inline everything. We still want to handle the imports separately, so
      // we just use the postcss-import messages to find the imported files.
      //
      // We can't use the `sheet.root` directly because this will mutate the
      // `sheet.root`
      let processed = await postcss().use(atImport()).process(sheet.root.toString(), { from: file })

      for (let msg of processed.messages) {
        if (msg.type === 'dependency' && msg.plugin === 'postcss-import') {
          queue.push(msg.file)
        }
      }
    }


Review comment (suggestion):
When you don't pass any files, then we used globby with the `gitignore: true` option, so I wanted to add that here as well.

I added an explicitly ignored CSS file to the integration tests to make sure we don't touch it.

Code after:
    // Discover CSS files in case no files were provided
    if (files.length === 0) {
      info('Searching for CSS files in the current directory and its subdirectories…')

      files = await globby(['**/*.css'], {
        absolute: true,
        gitignore: true,
      })
    }

    // Ensure we are only dealing with CSS files
    files = files.filter((file) => file.endsWith('.css'))

    // Analyze the stylesheets
    let loadResults = await Promise.allSettled(files.map((filepath) => Stylesheet.load(filepath)))

    // Load and parse all stylesheets
    for (let result of loadResults) {
      if (result.status === 'rejected') {
        error(`${result.reason}`)
      }
    }

    let stylesheets = loadResults
      .filter((result) => result.status === 'fulfilled')
      .map((result) => result.value)

    // Analyze the stylesheets
    try {
      await analyzeStylesheets(stylesheets)
    } catch (e: unknown) {
      error(`${e}`)
    }

    // Ensure stylesheets are linked to configs
    try {
      await linkConfigsToStylesheets(stylesheets, {
        configPath: flags['--config'],
        base,
      })
    } catch (e: unknown) {
      error(`${e}`)
    }

    // Migrate js config files, linked to stylesheets
    info('Migrating JavaScript configuration files using the provided configuration file.')
    let configBySheet = new Map<Stylesheet, Awaited<ReturnType<typeof prepareConfig>>>()
    let jsConfigMigrationBySheet = new Map<
      Stylesheet,
      Awaited<ReturnType<typeof migrateJsConfig>>
    >()