Skip to content
Merged
Show file tree
Hide file tree
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
make base path optional
When you don't provide a `base` path, we disable auto content detection.
This is currently only done in the `@tailwindcss/vite` package.

Note: you can't enable/disable auto content detection from user land
yet. That will be a separate PR.
  • Loading branch information
RobinMalfait committed Aug 7, 2024
commit 2c43ac6a0733c37240612d7e28e24d217d73da97
4 changes: 2 additions & 2 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl From<ChangedContent> for tailwindcss_oxide::ChangedContent {
pub struct ScanResult {
// Private information necessary for incremental rebuilds. Note: these fields are not exposed
// to JS
base: String,
base: Option<String>,
sources: Vec<GlobEntry>,

// Public API:
Expand Down Expand Up @@ -77,7 +77,7 @@ impl From<tailwindcss_oxide::GlobEntry> for GlobEntry {
#[napi(object)]
pub struct ScanOptions {
/// Base path to start scanning from
pub base: String,
pub base: Option<String>,
/// Glob sources
pub sources: Option<Vec<GlobEntry>>,
}
Expand Down
16 changes: 11 additions & 5 deletions crates/oxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct ChangedContent {
#[derive(Debug, Clone)]
pub struct ScanOptions {
/// Base path to start scanning from
pub base: String,
pub base: Option<String>,
/// Glob sources
pub sources: Vec<GlobEntry>,
}
Expand All @@ -68,11 +68,17 @@ pub fn clear_cache() {
pub fn scan_dir(opts: ScanOptions) -> ScanResult {
init_tracing();

let base = Path::new(&opts.base);

let (mut files, dirs) = resolve_files(base);
let (mut files, mut globs) = match opts.base {
Some(base) => {
// Only enable auto content detection when `base` is provided.
let base = Path::new(&base);
let (files, dirs) = resolve_files(base);
let globs = resolve_globs(base, dirs);

let mut globs = resolve_globs(base, dirs);
(files, globs)
}
None => (vec![], vec![]),
};

// If we have additional sources, then we have to resolve them as well.
if !opts.sources.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxide/tests/scan_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod scan_dir {

// Resolve all content paths for the (temporary) current working directory
let result = scan_dir(ScanOptions {
base: base.clone(),
base: Some(base.clone()),
sources: globs
.iter()
.map(|x| GlobEntry {
Expand Down
3 changes: 0 additions & 3 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ export default function tailwindcss(): Plugin[] {
})

scanDirResult = scanDir({
// TODO: This might not be necessary if we enable/disabled auto content
// detection.
base: config!.root, // Root directory, mainly used for auto content detection
sources: globs.map((pattern) => ({
base: inputBasePath, // Globs are relative to the input.css file
pattern,
Expand Down