Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add source(…) improvements to @tailwindcss/cli
  • Loading branch information
RobinMalfait committed Oct 29, 2024
commit f9aecf8fdbe06b8ca52ce5e174efe98739ce6b2c
38 changes: 24 additions & 14 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,29 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
fullRebuildPaths.push(path)
},
})

let sources = (() => {
// Disable auto source detection
if (compiler.root === 'none') {
return []
}

// No root specified, use the base directory
if (compiler.root === null) {
return [{ base, pattern: '**/*' }]
}

// Use the specified root
return [compiler.root]
})().concat(compiler.globs)

let scanner = new Scanner({ sources })
env.DEBUG && console.timeEnd('[@tailwindcss/cli] Setup compiler')
return compiler

return [compiler, scanner] as const
}

// Compile the input
let compiler = await createCompiler(input)
let scanner = new Scanner({
detectSources: { base },
sources: compiler.globs,
})
let [compiler, scanner] = await createCompiler(input)

// Watch for changes
if (args['--watch']) {
Expand Down Expand Up @@ -205,13 +218,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
fullRebuildPaths = inputFilePath ? [inputFilePath] : []

// Create a new compiler, given the new `input`
compiler = await createCompiler(input)

// Re-scan the directory to get the new `candidates`
scanner = new Scanner({
detectSources: { base },
sources: compiler.globs,
})
;[compiler, scanner] = await createCompiler(input)

// Scan the directory for candidates
env.DEBUG && console.time('[@tailwindcss/cli] Scan for candidates')
Expand Down Expand Up @@ -293,6 +300,9 @@ function watchDirectories(base: string, scanner: Scanner) {
// We don't want a watcher for negated globs.
if (globEntry.pattern[0] === '!') return []

// We don't want a watcher for files, only directories.
if (globEntry.pattern === '') return []

// We don't want a watcher for nested directories, these will be covered
// by the `base` directory already.
if (globEntry.base.startsWith(base)) return []
Expand Down