Skip to content

Auto source detection improvements #14820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support specifying the base path for automatic source detection using a `source(…)` function on `@tailwind utilities` or `@import "tailwindcss"` ([#14820](https://github.com/tailwindlabs/tailwindcss/pull/14820))
- Support disabling automatic source detection with `source(none)` ([#14820](https://github.com/tailwindlabs/tailwindcss/pull/14820))
- Support passing directories to `@source` without needing to pass a complete glob ([#14820](https://github.com/tailwindlabs/tailwindcss/pull/14820))
- _Upgrade (experimental)_: Bump `prettier-plugin-tailwindcss` to latest version during upgrade ([#14808](https://github.com/tailwindlabs/tailwindcss/pull/14808))

### Fixed
Expand All @@ -18,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Use logical `*-inline` and `*-block` properties for all x/y utilities like `px-*`, `my-*`, `scroll-px-*`, and `inset-y-*` ([#14805](https://github.com/tailwindlabs/tailwindcss/pull/14805))
- Respect automatic source detection heuristics in sources registered with `@source` ([#14820](https://github.com/tailwindlabs/tailwindcss/pull/14820))

## [4.0.0-alpha.30] - 2024-10-24

Expand Down
113 changes: 46 additions & 67 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ pub struct ChangedContent {
pub extension: String,
}

#[derive(Debug, Clone)]
#[napi(object)]
pub struct DetectSources {
/// Base path to start scanning from
pub base: String,
}

#[derive(Debug, Clone)]
#[napi(object)]
pub struct GlobEntry {
Expand Down Expand Up @@ -62,20 +55,11 @@ impl From<tailwindcss_oxide::GlobEntry> for GlobEntry {
}
}

impl From<DetectSources> for tailwindcss_oxide::scanner::detect_sources::DetectSources {
fn from(detect_sources: DetectSources) -> Self {
Self::new(detect_sources.base.into())
}
}

// ---

#[derive(Debug, Clone)]
#[napi(object)]
pub struct ScannerOptions {
/// Automatically detect sources in the base path
pub detect_sources: Option<DetectSources>,

/// Glob sources
pub sources: Option<Vec<GlobEntry>>,
}
Expand All @@ -102,7 +86,6 @@ impl Scanner {
pub fn new(opts: ScannerOptions) -> Self {
Self {
scanner: tailwindcss_oxide::Scanner::new(
opts.detect_sources.map(Into::into),
opts
.sources
.map(|x| x.into_iter().map(Into::into).collect()),
Expand All @@ -128,7 +111,7 @@ impl Scanner {
input: ChangedContent,
) -> Vec<CandidateWithPosition> {
let content = input.content.unwrap_or_else(|| {
std::fs::read_to_string(&input.file.unwrap()).expect("Failed to read file")
std::fs::read_to_string(input.file.unwrap()).expect("Failed to read file")
});

let input = ChangedContent {
Expand Down
12 changes: 3 additions & 9 deletions crates/node/src/utf16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ impl<'a> IndexConverter<'a> {
// will only ever be incremented up to the length of the input string.
//
// This eliminates a "potential" panic that cannot actually happen
let slice = unsafe {
self.input.get_unchecked(self.curr_utf8..)
};
let slice = unsafe { self.input.get_unchecked(self.curr_utf8..) };

for c in slice.chars() {
if self.curr_utf8 >= pos {
break
break;
}

self.curr_utf8 += c.len_utf8();
self.curr_utf16 += c.len_utf16();
}

return self.curr_utf16 as i64;
self.curr_utf16 as i64
}
}

Expand All @@ -66,19 +64,16 @@ mod test {
(4, 4),
(5, 5),
(6, 6),

// inside the 🔥
(7, 8),
(8, 8),
(9, 8),
(10, 8),

// inside the 🥳
(11, 10),
(12, 10),
(13, 10),
(14, 10),

// <space>world!
(15, 11),
(16, 12),
Expand All @@ -87,7 +82,6 @@ mod test {
(19, 15),
(20, 16),
(21, 17),

// Past the end should return the last utf-16 character index
(22, 17),
(100, 17),
Expand Down
3 changes: 2 additions & 1 deletion crates/oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ tracing = { version = "0.1.40", features = [] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
walkdir = "2.5.0"
ignore = "0.4.23"
glob-match = "0.2.1"
dunce = "1.0.5"
bexpand = "1.2.0"
glob-match = "0.2.1"

[dev-dependencies]
tempfile = "3.13.0"
Loading