Skip to content

Commit e733ca8

Browse files
committed
fix: thing
1 parent 3aff464 commit e733ca8

14 files changed

Lines changed: 266 additions & 251 deletions

File tree

.sampo/config.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
[packages]
22
linked = [["maudit", "maudit-macros"]]
3-
ignore = ["benchmarks/*", "examples/*", "maudit-website", "root", "e2e/fixtures/*", "xtask", "@maudit/e2e", "maudit-cli-packages"]
3+
ignore = [
4+
"benchmarks/*",
5+
"examples/*",
6+
"maudit-website",
7+
"root",
8+
"e2e/fixtures/*",
9+
"xtask",
10+
"@maudit/e2e",
11+
"maudit-cli-packages",
12+
]

crates/maudit-cli/src/dev/server.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,7 @@ async fn add_dev_client_script(
311311
res
312312
}
313313

314-
async fn apply_headers_file(
315-
req: Request,
316-
next: Next,
317-
headers_file: Arc<HeadersFile>,
318-
) -> Response {
314+
async fn apply_headers_file(req: Request, next: Next, headers_file: Arc<HeadersFile>) -> Response {
319315
if headers_file.is_empty() {
320316
return next.run(req).await;
321317
}

crates/maudit/src/assets.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ pub(crate) mod css;
1212
mod image;
1313
pub mod image_cache;
1414
pub mod prefetch;
15-
mod sanitize_filename;
15+
pub(crate) mod sanitize_filename;
1616
mod script;
1717
mod style;
1818
mod tailwind;
1919
pub use image::{Image, ImageFormat, ImageOptions, ImagePlaceholder, RenderWithAlt, RenderedImage};
2020
pub use prefetch::PrefetchPlugin;
2121
pub use script::Script;
22-
pub(crate) use script::make_placeholder_url as make_script_placeholder_url;
23-
pub(crate) use style::make_placeholder_url as make_style_placeholder_url;
2422
pub use style::{Style, StyleOptions};
2523
pub use tailwind::run_tailwind;
2624

crates/maudit/src/assets/css.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@ mod tests {
196196
let dir = tempfile::tempdir().unwrap();
197197

198198
// Create a simple CSS file
199-
fs::write(
200-
dir.path().join("style.css"),
201-
"body { color: red; }",
202-
)
203-
.unwrap();
199+
fs::write(dir.path().join("style.css"), "body { color: red; }").unwrap();
204200

205201
// Create a font file referenced by CSS
206202
fs::write(dir.path().join("font.woff2"), b"fake-font-data").unwrap();
@@ -213,11 +209,7 @@ mod tests {
213209
.unwrap();
214210

215211
// Create CSS files for @import testing
216-
fs::write(
217-
dir.path().join("_partial.css"),
218-
"h1 { font-size: 2em; }",
219-
)
220-
.unwrap();
212+
fs::write(dir.path().join("_partial.css"), "h1 { font-size: 2em; }").unwrap();
221213
fs::write(
222214
dir.path().join("main.css"),
223215
"@import \"_partial.css\";\nbody { color: blue; }",
@@ -250,16 +242,14 @@ mod tests {
250242
let dir = setup_css_dir();
251243
let output_dir = tempfile::tempdir().unwrap();
252244

253-
let result = bundle_css(
254-
&dir.path().join("main.css"),
255-
None,
256-
false,
257-
output_dir.path(),
258-
)
259-
.unwrap();
245+
let result =
246+
bundle_css(&dir.path().join("main.css"), None, false, output_dir.path()).unwrap();
260247

261248
// The bundled output should contain both the partial and the main styles
262-
assert!(result.code.contains("font-size"), "should contain @imported partial");
249+
assert!(
250+
result.code.contains("font-size"),
251+
"should contain @imported partial"
252+
);
263253
assert!(result.code.contains("color"), "should contain main styles");
264254
}
265255

@@ -277,7 +267,10 @@ mod tests {
277267
.unwrap();
278268

279269
// url() should have been rewritten to a fingerprinted filename
280-
assert!(!result.code.contains("url(font.woff2)"), "original url should be rewritten");
270+
assert!(
271+
!result.code.contains("url(font.woff2)"),
272+
"original url should be rewritten"
273+
);
281274
assert_eq!(result.copied_asset_filenames.len(), 1);
282275
assert!(result.copied_asset_filenames[0].contains("font"));
283276
assert!(result.copied_asset_filenames[0].ends_with(".woff2"));
@@ -305,13 +298,8 @@ mod tests {
305298
)
306299
.unwrap();
307300

308-
let minified = bundle_css(
309-
&dir.path().join("style.css"),
310-
None,
311-
true,
312-
output_dir.path(),
313-
)
314-
.unwrap();
301+
let minified =
302+
bundle_css(&dir.path().join("style.css"), None, true, output_dir.path()).unwrap();
315303

316304
assert!(
317305
minified.code.len() <= not_minified.code.len(),
@@ -338,10 +326,18 @@ mod tests {
338326
.unwrap();
339327

340328
// Should contain the tailwind output, not the original file content
341-
assert!(result.code.contains("margin"), "should use source_css content");
329+
assert!(
330+
result.code.contains("margin"),
331+
"should use source_css content"
332+
);
342333
// url() should still be rewritten and asset copied
343334
assert_eq!(result.copied_asset_filenames.len(), 1);
344-
assert!(output_dir.path().join(&result.copied_asset_filenames[0]).exists());
335+
assert!(
336+
output_dir
337+
.path()
338+
.join(&result.copied_asset_filenames[0])
339+
.exists()
340+
);
345341
}
346342

347343
#[test]

crates/maudit/src/assets/script.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::PathBuf;
22

3-
use crate::assets::{RouteAssetsOptions, make_filename, make_final_path};
3+
use crate::assets::{RouteAssetsOptions, make_filename, make_final_path, make_final_url};
44

55
#[derive(Clone, PartialEq, Eq, Hash)]
66
pub struct Script {
@@ -22,10 +22,9 @@ impl Script {
2222
) -> Self {
2323
let filename = make_filename(&path, &hash, Some("js"));
2424
let build_path = make_final_path(&route_assets_options.output_assets_dir, &filename);
25-
// URL is a deterministic placeholder; the real filename is determined by Rolldown's
26-
// content hash after bundling (so it reflects transitive asset deps like WASM imports).
27-
// A post-bundle pass rewrites these placeholders in any HTML that referenced them.
28-
let url = make_placeholder_url(&route_assets_options.assets_dir, &hash);
25+
// Library mode treats this URL as final and copies the source to `build_path`.
26+
// Coronate's post-bundle pass rewrites it to the content-hashed Rolldown filename.
27+
let url = make_final_url(&route_assets_options.assets_dir, &filename);
2928

3029
Self {
3130
path,
@@ -36,24 +35,4 @@ impl Script {
3635
build_path,
3736
}
3837
}
39-
40-
/// The chunk name passed to Rolldown's `[name]` filename pattern. Encodes the source-content
41-
/// hash so we can match `result.assets` entries back to their originating Script.
42-
pub(crate) fn chunk_name(&self) -> String {
43-
self.filename
44-
.with_extension("")
45-
.to_string_lossy()
46-
.into_owned()
47-
}
48-
}
49-
50-
/// Token embedded in HTML during render in place of a script's final URL. Replaced after
51-
/// bundling with `/<assets_dir>/<rolldown-emitted-filename>`. URL-shaped so it survives any
52-
/// templating layer that expects a path.
53-
pub(crate) fn make_placeholder_url(assets_dir: &Path, source_hash: &str) -> String {
54-
format!(
55-
"/{}/__maudit_script_{}__.js",
56-
assets_dir.display(),
57-
source_hash
58-
)
5938
}

crates/maudit/src/assets/style.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::PathBuf;
22

3-
use crate::assets::{RouteAssetsOptions, make_filename, make_final_path};
3+
use crate::assets::{RouteAssetsOptions, make_filename, make_final_path, make_final_url};
44

55
#[derive(Clone, PartialEq, Eq, Hash, Default)]
66
pub struct StyleOptions {
@@ -29,10 +29,8 @@ impl Style {
2929
) -> Self {
3030
let filename = make_filename(&path, &hash, Some("css"));
3131
let build_path = make_final_path(&route_assets_options.output_assets_dir, &filename);
32-
// Placeholder URL; replaced after CSS bundling with a content-hashed final URL
33-
// so that Tailwind-scanned classes (which change the bundled bytes without
34-
// changing the source file) cascade into a new filename.
35-
let url = make_placeholder_url(&route_assets_options.assets_dir, &hash);
32+
// See `Script::new`.
33+
let url = make_final_url(&route_assets_options.assets_dir, &filename);
3634

3735
Self {
3836
path,
@@ -45,11 +43,3 @@ impl Style {
4543
}
4644
}
4745
}
48-
49-
pub(crate) fn make_placeholder_url(assets_dir: &Path, source_hash: &str) -> String {
50-
format!(
51-
"/{}/__maudit_style_{}__.css",
52-
assets_dir.display(),
53-
source_hash
54-
)
55-
}

0 commit comments

Comments
 (0)