diff --git a/packages/cli/src/tailwind.rs b/packages/cli/src/tailwind.rs index f81c31029..f668f64ed 100644 --- a/packages/cli/src/tailwind.rs +++ b/packages/cli/src/tailwind.rs @@ -24,7 +24,7 @@ impl TailwindCli { input_path: Option, output_path: Option, ) -> Result<()> { - let Some(tailwind) = Self::autodetect(&manifest_dir) else { + let Some(tailwind) = Self::autodetect(&manifest_dir, &input_path) else { return Ok(()); }; @@ -54,7 +54,7 @@ impl TailwindCli { output_path: Option, ) -> tokio::task::JoinHandle> { tokio::spawn(async move { - let Some(tailwind) = Self::autodetect(&manifest_dir) else { + let Some(tailwind) = Self::autodetect(&manifest_dir, &input_path) else { return Ok(()); }; @@ -81,16 +81,22 @@ impl TailwindCli { /// /// Note that v3 still uses the tailwind.css file, but usually the accompanying js file indicates /// that the project is using v3. - pub(crate) fn autodetect(manifest_dir: &Path) -> Option { - if manifest_dir.join("tailwind.config.js").exists() { + pub(crate) fn autodetect(manifest_dir: &Path, input_path: &Option) -> Option { + let dir = input_path + .as_ref() + .map(|p| manifest_dir.join(p)) + .and_then(|p| p.parent().map(|parent| parent.to_path_buf())) + .unwrap_or(manifest_dir.to_path_buf()); + + if dir.join("tailwind.config.js").exists() || dir.join("tailwind.config.ts").exists() { return Some(Self::v3()); } - if manifest_dir.join("tailwind.config.ts").exists() { - return Some(Self::v3()); - } - - if manifest_dir.join("tailwind.css").exists() { + if input_path + .as_ref() + .map(|p| manifest_dir.join(p).exists()) + .unwrap_or_else(|| manifest_dir.join("tailwind.css").exists()) + { return Some(Self::v4()); }