bundla 0.8.0

Bundle HTML, CSS, and JS/TS: prod build with minification and hashed filenames by default, dev build with sourcemaps, composable watch and serve
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
use std::{
    collections::HashMap,
    fs,
    path::{Path, PathBuf},
};

use lightningcss::rules::CssRule;
use lightningcss::stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet};
use parcel_sourcemap::SourceMap;

use super::{
    super::{BuildOptions, Minify, path},
    dist_mkdir, file_name_output_format, file_stem_extract,
};

// Threaded through the recursive bundling; grouping them keeps the
// signatures readable.
struct CssState<'a> {
    cache: &'a mut HashMap<PathBuf, String>,
    warnings: &'a mut Vec<String>,
}

pub fn css_bundle(
    asset_path: &Path,
    src: &Path,
    dist: &Path,
    dir: &Path,
    options: &BuildOptions,
    cache: &mut HashMap<PathBuf, String>,
    warnings: &mut Vec<String>,
) -> Result<String, String> {
    let mut stack: Vec<PathBuf> = Vec::new();
    let mut state = CssState { cache, warnings };
    css_bundle_rec(asset_path, src, dist, dir, options, &mut state, &mut stack)
}

// The stack carries the in-progress sources so that a cycle in the `@import`
// graph is detected instead of recursing forever
fn css_bundle_rec(
    asset_path: &Path,
    src: &Path,
    dist: &Path,
    dir: &Path,
    options: &BuildOptions,
    state: &mut CssState,
    stack: &mut Vec<PathBuf>,
) -> Result<String, String> {
    let asset_path =
        fs::canonicalize(asset_path).map_err(|err| format!("css source unreadable: {err}"))?;
    let css_code =
        fs::read_to_string(&asset_path).map_err(|err| format!("css source unreadable: {err}"))?;
    let mut stylesheet = StyleSheet::parse(&css_code, ParserOptions::default())
        .map_err(|err| format!("css parse error: {err}"))?;

    stack.push(asset_path.clone());
    let err = css_imports_rewrite(
        &mut stylesheet,
        &asset_path,
        src,
        dist,
        options,
        state,
        stack,
    );
    stack.pop();
    err?;

    if options.minify.contains(Minify::CSS) {
        stylesheet
            .minify(MinifyOptions::default())
            .map_err(|err| format!("css minify error: {err}"))?;
    }

    let file_stem = file_stem_extract(&asset_path, "styles");

    let mut map = SourceMap::new("/");
    let result = stylesheet
        .to_css(PrinterOptions {
            minify: options.minify.contains(Minify::CSS),
            source_map: options.sourcemap.then_some(&mut map),
            ..PrinterOptions::default()
        })
        .map_err(|err| format!("css print error: {err}"))?;

    let mut code = result.code;

    let name = file_name_output_format(&file_stem, "css", code.as_bytes(), options.hash);
    let out = dist_mkdir(dist, dir)?;
    if options.sourcemap {
        let map_json = map
            .to_json(None)
            .map_err(|err| format!("css sourcemap serialization error: {err}"))?;
        // The map shares the output name (`theme.css.map`, or `theme-<hash>.css.map`)
        let map_name = format!("{name}.map");
        fs::write(out.join(&map_name), map_json)
            .map_err(|err| format!("css sourcemap write error: {err}"))?;
        code.push_str(&format!("\n/*# sourceMappingURL={map_name} */"));
    }

    fs::write(out.join(&name), code).map_err(|err| format!("css output write error: {err}"))?;
    Ok(name)
}

// - bundle every relative `@import` target and rewrite url to its output name
// - root-relative targets are bundled when they start with the base,
//   and left untouched otherwise
// - remotes are left untouched
// - missing local targets are hard errors
// - @import targets are always content-hashed, dev included,
// So editing an imported file yields a new url and the browser re-fetches it
// instead of serving a cached copy of the parent css.
fn css_imports_rewrite(
    stylesheet: &mut StyleSheet,
    asset_path: &Path,
    src: &Path,
    dist: &Path,
    options: &BuildOptions,
    state: &mut CssState,
    stack: &mut Vec<PathBuf>,
) -> Result<(), String> {
    for import in stylesheet.rules.0.iter_mut().filter_map(|rule| match rule {
        CssRule::Import(import) => Some(import),
        _ => None,
    }) {
        let import_ref = import.url.as_ref();
        let (import_ref_cleaned, _) = path::url_ref_split(import_ref);
        let Some(import_path) =
            path::asset_ref_path_resolve(src, asset_path, import_ref, options.base.as_deref())?
        else {
            if options.base.is_none() && path::is_root_relative(import_ref_cleaned.trim()) {
                state
                    .warnings
                    .push(path::asset_ref_skip_warn(import_ref, asset_path));
            }
            continue;
        };
        if stack.contains(&import_path) {
            return Err(format!(
                "css import cycle: '{}' imports {}",
                asset_path.display(),
                import_path.display()
            ));
        }

        let file_name = match state.cache.get(&import_path).cloned() {
            Some(file_name) => file_name,
            None => {
                let imported_dir = import_path
                    .strip_prefix(src)
                    .map_err(|_| {
                        format!(
                            "css import escapes source: {} (imported from {})",
                            import_path.display(),
                            asset_path.display()
                        )
                    })?
                    .parent()
                    .unwrap_or_else(|| Path::new(""))
                    .to_path_buf();
                let file_name = css_bundle_rec(
                    &import_path,
                    src,
                    dist,
                    &imported_dir,
                    &BuildOptions {
                        hash: true,
                        ..options.clone()
                    },
                    state,
                    stack,
                )?;
                state.cache.insert(import_path.clone(), file_name.clone());
                file_name
            }
        };

        let rewritten = path::asset_ref_rewrite(import_ref_cleaned, &file_name);
        import.url = rewritten.into();
    }

    Ok(())
}

#[cfg(test)]
mod tests {
    use std::fs;

    use tempfile::tempdir;

    use super::*;

    fn write_css(source: &Path, content: &str) {
        fs::create_dir_all(source.parent().unwrap()).unwrap();
        fs::write(source, content).unwrap();
    }

    fn bundle_css(
        source: &Path,
        src: &Path,
        dist: &Path,
        dir: &Path,
        options: &BuildOptions,
    ) -> Result<String, String> {
        css_bundle(
            source,
            src,
            dist,
            dir,
            options,
            &mut HashMap::new(),
            &mut Vec::new(),
        )
    }

    fn list_names(dir: &Path) -> Vec<String> {
        if !dir.exists() {
            return Vec::new();
        }
        let mut names: Vec<String> = fs::read_dir(dir)
            .unwrap()
            .filter_map(Result::ok)
            .filter(|e| e.file_type().is_ok_and(|t| t.is_file()))
            .map(|e| e.file_name().to_string_lossy().into_owned())
            .collect();
        names.sort();
        names
    }

    #[test]
    fn css_parse_error_on_invalid_rules() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        let source = src.join("styles/bad.css");
        write_css(&source, "}");

        let err = bundle_css(
            &source,
            &src,
            &src.join("out"),
            Path::new("styles"),
            &BuildOptions::DEV,
        )
        .unwrap_err();
        assert!(err.contains("css parse error"), "got: {err}");
    }

    #[test]
    fn css_source_unreadable_errs() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        let source = src.join("missing.css");

        let err = bundle_css(
            &source,
            &src,
            &src.join("out"),
            Path::new(""),
            &BuildOptions::DEV,
        )
        .unwrap_err();
        assert!(err.contains("css source unreadable"), "got: {err}");
    }

    #[test]
    fn css_dev_emits_map_and_sourcemap_tail() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        let source = src.join("styles/theme.css");
        write_css(&source, "body { color: red; }\n");
        let dist = src.join("out");

        let name = bundle_css(
            &source,
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::DEV,
        )
        .unwrap();
        assert_eq!(name, "theme.css");
        let code = fs::read_to_string(dist.join("styles/theme.css")).unwrap();
        assert!(
            code.ends_with("/*# sourceMappingURL=theme.css.map */"),
            "got: {code}"
        );
        assert!(dist.join("styles/theme.css.map").is_file());
    }

    #[test]
    fn css_hash_sourcemap_pair_maps_output() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        let source = src.join("styles/theme.css");
        write_css(&source, "body { color: red; }\n");
        let dist = src.join("out");
        let options = BuildOptions {
            minify: Minify::ALL,
            sourcemap: true,
            hash: true,
            base: None,
        };

        let name = bundle_css(&source, &src, &dist, Path::new("styles"), &options).unwrap();
        assert!(
            name.starts_with("theme-") && name.ends_with(".css"),
            "got: {name}"
        );
        let map_name = format!("{name}.map");
        assert!(
            dist.join("styles").join(&map_name).is_file(),
            "missing paired sourcemap {map_name}"
        );
        let code = fs::read_to_string(dist.join("styles").join(&name)).unwrap();
        assert!(
            code.ends_with(&format!("/*# sourceMappingURL={map_name} */")),
            "css must end with a patched sourceMappingURL comment, got: {code:?}"
        );
        assert!(
            !dist.join("styles/theme.map").exists(),
            "unpaired theme.map must not remain"
        );
    }

    #[test]
    fn css_prod_minifies_and_hashes_without_map() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        let source = src.join("styles/theme.css");
        write_css(&source, "body { color: red; }\n");
        let dist = src.join("out");

        let name = bundle_css(
            &source,
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
        )
        .unwrap();
        assert!(
            name.starts_with("theme-") && name.ends_with(".css"),
            "got: {name}"
        );
        assert!(!dist.join("styles/theme.map").exists());
        let code = fs::read_to_string(dist.join("styles").join(&name)).unwrap();
        assert!(code.contains("color"), "got: {code}");
        assert!(
            !code.contains(char::is_whitespace),
            "expected minified output, got: {code}"
        );
    }

    #[test]
    fn css_import_rewritten_in_prod() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/sub")).unwrap();
        write_css(
            &src.join("styles/main.css"),
            "@import url(\"https://cdn.example.com/remote.css\");\n@import url(\"./sub/reset.css\");\nbody { color: red; }\n",
        );
        write_css(&src.join("styles/sub/reset.css"), "p { margin: 0; }\n");
        let dist = src.join("out");

        bundle_css(
            &src.join("styles/main.css"),
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
        )
        .unwrap();

        let resets = list_names(&dist.join("styles/sub"));
        assert_eq!(resets.len(), 1, "expected one reset output: {resets:?}");
        let reset_name = &resets[0];
        assert!(
            reset_name.starts_with("reset-") && reset_name.ends_with(".css"),
            "{reset_name}"
        );
        assert!(
            dist.join("styles/sub").join(reset_name).is_file(),
            "missing {}",
            dist.join("styles/sub").join(reset_name).display()
        );

        let mains = list_names(&dist.join("styles"));
        assert_eq!(mains.len(), 1, "expected one main output: {mains:?}");
        let out_code = fs::read_to_string(dist.join("styles").join(&mains[0])).unwrap();
        assert!(out_code.contains(reset_name), "got: {out_code}");
        assert!(
            out_code.contains("cdn.example.com/remote.css"),
            "remote import must be left as-is, got: {out_code}"
        );
    }

    #[test]
    fn css_import_preserves_media_query() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/sub")).unwrap();
        write_css(
            &src.join("styles/main.css"),
            "@import url(\"./sub/reset.css\") (min-width: 100px);\nbody { color: red; }\n",
        );
        write_css(&src.join("styles/sub/reset.css"), "p { margin: 0; }\n");
        let dist = src.join("out");

        bundle_css(
            &src.join("styles/main.css"),
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::DEV,
        )
        .unwrap();

        let resets: Vec<String> = list_names(&dist.join("styles/sub"))
            .into_iter()
            .filter(|n| n.ends_with(".css"))
            .collect();
        assert_eq!(resets.len(), 1, "{resets:?}");
        assert!(
            resets[0].starts_with("reset-") && resets[0].ends_with(".css"),
            "dev import target must be content-hashed: {}",
            resets[0]
        );
        let out_code = fs::read_to_string(dist.join("styles/main.css")).unwrap();
        assert!(out_code.contains(&resets[0]), "got: {out_code}");
        assert!(
            out_code.contains("width"),
            "media condition kept, got: {out_code}"
        );
        assert!(
            out_code.contains("100px"),
            "media condition kept, got: {out_code}"
        );
        let reset_code = fs::read_to_string(dist.join("styles/sub").join(&resets[0])).unwrap();
        assert!(reset_code.contains("margin"), "got: {reset_code}");
    }

    #[test]
    fn css_import_dev_hashes_import_targets() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/sub")).unwrap();
        let main_source = src.join("styles/main.css");
        let reset_source = src.join("styles/sub/reset.css");
        write_css(&main_source, "@import url(\"./sub/reset.css\");\nbody{}\n");
        let first_dist = src.join("out1");

        write_css(&reset_source, "p { margin: 0; }\n");
        bundle_css(
            &main_source,
            &src,
            &first_dist,
            Path::new("styles"),
            &BuildOptions::DEV,
        )
        .unwrap();
        let first_resets: Vec<String> = list_names(&first_dist.join("styles/sub"))
            .into_iter()
            .filter(|n| n.ends_with(".css"))
            .collect();
        assert_eq!(first_resets.len(), 1, "{first_resets:?}");
        assert!(
            first_resets[0].starts_with("reset-") && first_resets[0].ends_with(".css"),
            "dev import target must be content-hashed: {}",
            first_resets[0]
        );
        let first_main = fs::read_to_string(first_dist.join("styles/main.css")).unwrap();
        assert!(first_main.contains(&first_resets[0]), "got: {first_main}");

        let second_dist = src.join("out2");
        write_css(&reset_source, "p { margin: 0 0 1rem; }\n");
        bundle_css(
            &main_source,
            &src,
            &second_dist,
            Path::new("styles"),
            &BuildOptions::DEV,
        )
        .unwrap();
        let second_resets: Vec<String> = list_names(&second_dist.join("styles/sub"))
            .into_iter()
            .filter(|n| n.ends_with(".css"))
            .collect();
        assert_eq!(second_resets.len(), 1, "{second_resets:?}");
        assert!(
            second_resets[0].starts_with("reset-") && second_resets[0].ends_with(".css"),
            "got: {}",
            second_resets[0]
        );
        assert_ne!(
            second_resets[0], first_resets[0],
            "editing the imported file must change its output name so browsers re-fetch it"
        );
        let second_main = fs::read_to_string(second_dist.join("styles/main.css")).unwrap();
        assert!(
            second_main.contains(&second_resets[0]),
            "got: {second_main}"
        );
    }

    #[test]
    fn css_import_dedup_across_parents() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/shared")).unwrap();
        write_css(
            &src.join("styles/main.css"),
            "@import url(\"./shared/reset.css\");\nbody{}\n",
        );
        write_css(
            &src.join("styles/theme.css"),
            "@import url(\"./shared/reset.css\");\np{}\n",
        );
        write_css(&src.join("styles/shared/reset.css"), "a{}\n");
        let dist = src.join("out");

        let mut cache = HashMap::new();
        css_bundle(
            &src.join("styles/main.css"),
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
            &mut cache,
            &mut Vec::new(),
        )
        .unwrap();
        css_bundle(
            &src.join("styles/theme.css"),
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
            &mut cache,
            &mut Vec::new(),
        )
        .unwrap();

        let resets = list_names(&dist.join("styles/shared"));
        assert_eq!(
            resets.len(),
            1,
            "expected the shared import bundled once: {resets:?}"
        );

        let mains = list_names(&dist.join("styles"));
        assert_eq!(mains.len(), 2, "expected both parents' outputs: {mains:?}");
        for main_name in &mains {
            let main_code = fs::read_to_string(dist.join("styles").join(main_name)).unwrap();
            assert!(
                main_code.contains(&resets[0]),
                "{main_name} must reference {}: {main_code}",
                resets[0]
            );
        }
    }

    #[test]
    fn css_import_cycle_detected() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("sub")).unwrap();
        write_css(
            &src.join("a.css"),
            "@import url(\"./sub/b.css\");\nbody{}\n",
        );
        write_css(&src.join("sub/b.css"), "@import url(\"../a.css\");\np{}\n");
        let dist = src.join("out");

        let err = bundle_css(
            &src.join("a.css"),
            &src,
            &dist,
            Path::new(""),
            &BuildOptions::PROD,
        )
        .unwrap_err();
        assert!(err.contains("css import cycle"), "got: {err}");
    }

    #[test]
    fn css_import_missing_target_errs() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        write_css(
            &src.join("styles/main.css"),
            "@import url(\"./nope.css\");\nbody{}\n",
        );
        let dist = src.join("out");

        let err = bundle_css(
            &src.join("styles/main.css"),
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
        )
        .unwrap_err();
        assert!(err.contains("asset not found"), "got: {err}");
    }

    #[test]
    fn css_import_root_relative_under_base_bundled() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/sub")).unwrap();
        write_css(
            &src.join("styles/main.css"),
            "@import url(\"/app/styles/sub/reset.css\");\n@import url(\"/other/theme.css\");\nbody{}\n",
        );
        write_css(&src.join("styles/sub/reset.css"), "p { margin: 0; }\n");
        let dist = src.join("out");
        let options = BuildOptions {
            base: Some("/app".into()),
            ..BuildOptions::PROD
        };

        bundle_css(
            &src.join("styles/main.css"),
            &src,
            &dist,
            Path::new("styles"),
            &options,
        )
        .unwrap();

        let resets = list_names(&dist.join("styles/sub"));
        assert_eq!(resets.len(), 1, "expected one reset output: {resets:?}");
        assert!(
            resets[0].starts_with("reset-") && resets[0].ends_with(".css"),
            "{resets:?}"
        );
        let mains = list_names(&dist.join("styles"));
        assert_eq!(mains.len(), 1, "expected one main output: {mains:?}");
        let out_code = fs::read_to_string(dist.join("styles").join(&mains[0])).unwrap();
        // under the base: bundled, rewritten keeping the base prefix
        assert!(
            out_code.contains(&format!("/app/styles/sub/{}", resets[0])),
            "got: {out_code}"
        );
        // outside the base: left verbatim for the browser
        assert!(out_code.contains("/other/theme.css"), "got: {out_code}");
    }

    #[test]
    fn css_import_root_relative_without_base_warns() {
        let dir = tempdir().unwrap();
        let src = fs::canonicalize(dir.path()).unwrap();
        fs::create_dir_all(src.join("styles/sub")).unwrap();
        let main = src.join("styles/main.css");
        write_css(&main, "@import url(\"/styles/sub/reset.css\");\nbody{}\n");
        write_css(&src.join("styles/sub/reset.css"), "p{}\n");
        let dist = src.join("out");

        let mut warnings = Vec::new();
        css_bundle(
            &main,
            &src,
            &dist,
            Path::new("styles"),
            &BuildOptions::PROD,
            &mut HashMap::new(),
            &mut warnings,
        )
        .unwrap();

        assert_eq!(warnings.len(), 1, "got: {warnings:?}");
        assert!(
            warnings[0].contains("skipping root-relative reference"),
            "got: {}",
            warnings[0]
        );
        assert!(
            warnings[0].contains("/styles/sub/reset.css"),
            "got: {}",
            warnings[0]
        );

        // the import is left verbatim and the target is not bundled
        let mains = list_names(&dist.join("styles"));
        assert_eq!(mains.len(), 1, "{mains:?}");
        let out_code = fs::read_to_string(dist.join("styles").join(&mains[0])).unwrap();
        assert!(
            out_code.contains("/styles/sub/reset.css"),
            "got: {out_code}"
        );
        assert!(
            !dist.join("styles/sub").exists(),
            "target must not be bundled"
        );
    }
}