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

Code before:
    if (args['--output']) {
      await outputFile(args['--output'], output)
    } else {
      println(output)
    }
  }

  let inputFile = args['--input'] && args['--input'] !== '-' ? args['--input'] : process.cwd()
  let inputBasePath = path.dirname(path.resolve(inputFile))
  let fullRebuildPaths: string[] = cssImportPaths.slice()

  function createCompiler(css: string) {
    return compile(css, {
      base: inputBasePath,
      onDependency(path) {
        fullRebuildPaths.push(path)
      },
    })
  }

  // Compile the input
  let compiler = await createCompiler(input)
  let scanner = new Scanner({
    detectSources: { base },
    sources: compiler.globs.map(({ origin, pattern }) => ({
      // Globs are relative to the input.css file
      base: origin ? path.dirname(path.resolve(inputBasePath, origin)) : inputBasePath,
      pattern,
    })),
  })

  // Watch for changes
  if (args['--watch']) {
    let cleanupWatchers = await createWatchers(
      watchDirectories(base, scanner),
      async function handle(files) {
        try {
          // If the only change happened to the output file, then we don't want to
          // trigger a rebuild because that will result in an infinite loop.
          if (files.length === 1 && files[0] === args['--output']) return

          let changedFiles: ChangedContent[] = []
          let rebuildStrategy: 'incremental' | 'full' = 'incremental'

          let resolvedFullRebuildPaths = fullRebuildPaths

          for (let file of files) {
            // If one of the changed files is related to the input CSS or JS
            // config/plugin files, then we need to do a full rebuild because
            // the theme might have changed.
            if (resolvedFullRebuildPaths.includes(file)) {

Review comment (suggestion):
I know this comment was already there but I wonder if it's misleading to say `input.css` here since the file could be named anything? And `origin` comes from a config file, not a CSS file.

Maybe these should be more like:

> Globs are relative to the CSS file or config file where they are specified

Code after:
    if (args['--output']) {
      await outputFile(args['--output'], output)
    } else {
      println(output)
    }
  }

  let inputFile = args['--input'] && args['--input'] !== '-' ? args['--input'] : process.cwd()
  let inputBasePath = path.dirname(path.resolve(inputFile))
  let fullRebuildPaths: string[] = cssImportPaths.slice()

  function createCompiler(css: string) {
    return compile(css, {
      base: inputBasePath,
      onDependency(path) {
        fullRebuildPaths.push(path)
      },
    })
  }

  // Compile the input
  let compiler = await createCompiler(input)
  let scanner = new Scanner({
    detectSources: { base },
    sources: compiler.globs.map(({ origin, pattern }) => ({
      // Ensure the glob is relative to the input CSS file or the config file
      // where it is specified.
      base: origin ? path.dirname(path.resolve(inputBasePath, origin)) : inputBasePath,
      pattern,
    })),
  })

  // Watch for changes
  if (args['--watch']) {
    let cleanupWatchers = await createWatchers(
      watchDirectories(base, scanner),
      async function handle(files) {
        try {
          // If the only change happened to the output file, then we don't want to
          // trigger a rebuild because that will result in an infinite loop.
          if (files.length === 1 && files[0] === args['--output']) return

          let changedFiles: ChangedContent[] = []
          let rebuildStrategy: 'incremental' | 'full' = 'incremental'

          let resolvedFullRebuildPaths = fullRebuildPaths

          for (let file of files) {
            // If one of the changed files is related to the input CSS or JS
            // config/plugin files, then we need to do a full rebuild because
            // the theme might have changed.