Skip to content
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

Handle new source(…) #14767

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
23147ff
handle `source(…)`
RobinMalfait Oct 23, 2024
a62b010
add integration test for `source(…)`
RobinMalfait Oct 23, 2024
7b45b77
forward correct `source(…)` to the oxide scanner
RobinMalfait Oct 23, 2024
165718a
update test
RobinMalfait Oct 25, 2024
d0731d1
fix turbo input paths
RobinMalfait Oct 25, 2024
9b25bf8
fix some clippy warnings
RobinMalfait Oct 25, 2024
fcf0a9d
promote sources to auto source detection
RobinMalfait Oct 25, 2024
dea08ba
refactor, remove a level of nesting
RobinMalfait Oct 25, 2024
77e8bf9
merge `globs` and `detectSources`
RobinMalfait Oct 25, 2024
c3c82eb
Remove @tailwind utility nodes with parameters
philipp-spiess Oct 25, 2024
98f74f4
validate existence `source(…)` base path
RobinMalfait Oct 25, 2024
193e7bc
provide base and pattern separately
RobinMalfait Oct 25, 2024
2cc2a33
add `bexpand` for expanding glob expressions
RobinMalfait Oct 25, 2024
d612e66
expand patterns in `GlobEntry`
RobinMalfait Oct 25, 2024
9e46992
run prettier
RobinMalfait Oct 25, 2024
810d98a
update test name
RobinMalfait Oct 25, 2024
ec70c4c
refactor: use variable directly
RobinMalfait Oct 25, 2024
1c140a8
update `@tailwindcss/postcss` with new `source(…)` setup
RobinMalfait Oct 25, 2024
894290a
update `@tailwindcss/vite` with new `source(…)` setup
RobinMalfait Oct 25, 2024
6a3159e
cleanup `console.log`
RobinMalfait Oct 25, 2024
9f6ab1a
add todo for follow up PR
RobinMalfait Oct 25, 2024
86e9e4d
add CLI watch mode tests for `@source` and `source(…)`
RobinMalfait Oct 25, 2024
5747d1c
migrate detect sources to sources
RobinMalfait Oct 25, 2024
f3fe3ce
resolves base path in tests
RobinMalfait Oct 25, 2024
d600964
update all instances of `new Scanner(…)`
RobinMalfait Oct 25, 2024
bf39acd
Update crates/oxide/src/lib.rs
RobinMalfait Oct 25, 2024
d549337
Update packages/@tailwindcss-vite/src/index.ts
RobinMalfait Oct 25, 2024
d5b724c
Update packages/@tailwindcss-vite/src/index.ts
RobinMalfait Oct 25, 2024
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
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
1 change: 1 addition & 0 deletions crates/oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ walkdir = "2.5.0"
ignore = "0.4.23"
glob-match = "0.2.1"
dunce = "1.0.5"
bexpand = "1.2.0"

[dev-dependencies]
tempfile = "3.13.0"
Loading