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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/*!
# A library to generate change detection instructions during build time

## Legal

Dual-licensed under `MIT` or the [UNLICENSE](http://unlicense.org/).

## Features

Automates task of generating change detection instructions for your static files.

<https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection>

## Usage

Add dependency to Cargo.toml:

```toml
[dependencies]
change-detection = "1.2"
```

Add a call to `build.rs`:

```rust
use change_detection::ChangeDetection;

fn main() {
    ChangeDetection::path("src/hello.c").generate();
}
```

This is basically the same, as just write:

```rust
fn main() {
    println!("cargo:rerun-if-changed=src/hello.c");
}
```

You can also use a directory. For example, if your resources are in `static` directory:

```rust
use change_detection::ChangeDetection;

fn main() {
    ChangeDetection::path("static").generate();
}
```

One call to generate can have multiple `path` components:

```rust
use change_detection::ChangeDetection;

fn main() {
    ChangeDetection::path("static")
        .path("another_path")
        .path("build.rs")
        .generate();
}
```

Using `path-matchers` library you can specify include / exclude filters:

```rust
#[cfg(features = "glob")]
use change_detection::{path_matchers::glob, ChangeDetection};

fn main() {
    #[cfg(features = "glob")]
    ChangeDetection::exclude(glob("another_path/**/*.tmp").unwrap())
        .path("static")
        .path("another_path")
        .path("build.rs")
        .generate();
}
```

You can find generated result with this command:

```bash
find . -name output | xargs cat
```

*/
use ::path_matchers::PathMatcher;
use path_slash::PathExt;
use std::path::{Path, PathBuf};

/// Reexport `path-matchers`.
pub mod path_matchers {
    pub use ::path_matchers::*;
}

/// A change detection entry point.
///
/// Creates a builder to generate change detection instructions.
///
/// # Examples
///
/// ```
/// use change_detection::ChangeDetection;
///
/// fn main() {
///     ChangeDetection::path("src/hello.c").generate();
/// }
/// ```
///
/// This is the same as just write:
///
/// ```ignore
/// fn main() {
///     println!("cargo:rerun-if-changed=src/hello.c");
/// }
/// ```
///
/// You can collect resources from a path:
///
/// ```
/// # use change_detection::ChangeDetection;
///
/// fn main() {
///     ChangeDetection::path("some_path").generate();
/// }
/// ```
///
/// To chain multiple directories and files:
///
/// ```
/// # use change_detection::ChangeDetection;
///
/// fn main() {
///     ChangeDetection::path("src/hello.c")
///         .path("static")
///         .path("build.rs")
///         .generate();
/// }
/// ```
pub struct ChangeDetection;

impl ChangeDetection {
    /// Collects change detection instructions from a `path`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::path("static").generate();
    /// ```
    ///
    /// To generate change instructions for the file with the name `build.rs`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::path("build.rs").generate();
    /// ```
    pub fn path<P>(path: P) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
    {
        ChangeDetectionBuilder::default().path(path)
    }

    /// Collects change detection instructions from a `path` applying include `filter`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` but only for files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::path_include("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_include<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default().path_include(path, filter)
    }

    /// Collects change detection instructions from a `path` applying exclude `filter`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` but without files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::path_exclude("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_exclude<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default().path_exclude(path, filter)
    }

    /// Collects change detection instructions from a `path` applying `include` and `exclude` filters.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` including only files starting with `a` but without files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::path_filter("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().starts_with("a"))
    ///         .unwrap_or(false)
    /// }, |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_filter<P, F1, F2>(path: P, include: F1, exclude: F2) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F1: PathMatcher + 'static,
        F2: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default().path_filter(path, include, exclude)
    }

    /// Applies a global `include` filter to all paths.
    ///
    /// # Examples:
    ///
    /// To included only files starting with `a` for paths `static1`, `static2` and `static3`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::include(|path: &std::path::Path| {
    ///         path.file_name()
    ///             .map(|filename| filename.to_str().unwrap().starts_with("a"))
    ///             .unwrap_or(false)
    ///     })
    ///     .path("static1")
    ///     .path("static2")
    ///     .path("static3")
    ///     .generate();
    /// ```
    pub fn include<F>(filter: F) -> ChangeDetectionBuilder
    where
        F: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default().include(filter)
    }

    /// Applies a global `exclude` filter to all paths.
    ///
    /// # Examples:
    ///
    /// To exclude files starting with `a` for paths `static1`, `static2` and `static3`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::exclude(|path: &std::path::Path| {
    ///         path.file_name()
    ///             .map(|filename| filename.to_str().unwrap().starts_with("a"))
    ///             .unwrap_or(false)
    ///     })
    ///     .path("static1")
    ///     .path("static2")
    ///     .path("static3")
    ///     .generate();
    /// ```
    pub fn exclude<F>(filter: F) -> ChangeDetectionBuilder
    where
        F: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default().exclude(filter)
    }

    /// Applies a global `include` and `exclude` filters to all paths.
    ///
    /// # Examples:
    ///
    /// To include files starting with `a` for paths `static1`, `static2` and `static3`, but whose names do not end in `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetection;
    /// ChangeDetection::filter(|path: &std::path::Path| {
    ///         path.file_name()
    ///             .map(|filename| filename.to_str().unwrap().starts_with("a"))
    ///             .unwrap_or(false)
    ///     }, |path: &std::path::Path| {
    ///         path.file_name()
    ///             .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///             .unwrap_or(false)
    ///     })
    ///     .path("static1")
    ///     .path("static2")
    ///     .path("static3")
    ///     .generate();
    /// ```
    pub fn filter<F1, F2>(include: F1, exclude: F2) -> ChangeDetectionBuilder
    where
        F1: PathMatcher + 'static,
        F2: PathMatcher + 'static,
    {
        ChangeDetectionBuilder::default()
            .include(include)
            .exclude(exclude)
    }
}

/// A change detection builder.
///
/// A builder to generate change detection instructions.
/// You should not use this directly, use [`ChangeDetection`] as an entry point instead.
#[derive(Default)]
pub struct ChangeDetectionBuilder {
    include: Option<Box<dyn PathMatcher>>,
    exclude: Option<Box<dyn PathMatcher>>,
    paths: Vec<ChangeDetectionPath>,
}

impl ChangeDetectionBuilder {
    /// Collects change detection instructions from a `path`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static`:
    ///
    /// ```
    /// # use change_detection::ChangeDetectionBuilder;
    /// # let builder = ChangeDetectionBuilder::default();
    /// builder.path("static").generate();
    /// ```
    ///
    /// To generate change instructions for the file with the name `build.rs`:
    ///
    /// ```
    /// # use change_detection::ChangeDetectionBuilder;
    /// # let builder = ChangeDetectionBuilder::default();
    /// builder.path("build.rs").generate();
    /// ```
    pub fn path<P>(mut self, path: P) -> ChangeDetectionBuilder
    where
        P: Into<ChangeDetectionPath>,
    {
        self.paths.push(path.into());
        self
    }

    /// Collects change detection instructions from a `path` applying include `filter`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` but only for files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetectionBuilder;
    /// # let builder = ChangeDetectionBuilder::default();
    /// builder.path_include("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_include<P, F>(mut self, path: P, filter: F) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F: PathMatcher + 'static,
    {
        self.paths.push(ChangeDetectionPath::PathInclude(
            path.as_ref().into(),
            Box::new(filter),
        ));
        self
    }

    /// Collects change detection instructions from a `path` applying exclude `filter`.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` but without files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetectionBuilder;
    /// # let builder = ChangeDetectionBuilder::default();
    /// builder.path_exclude("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_exclude<P, F>(mut self, path: P, filter: F) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F: PathMatcher + 'static,
    {
        self.paths.push(ChangeDetectionPath::PathExclude(
            path.as_ref().into(),
            Box::new(filter),
        ));
        self
    }

    /// Collects change detection instructions from a `path` applying `include` and `exclude` filters.
    ///
    /// A `path` can be a single file or a directory.
    ///
    /// # Examples:
    ///
    /// To generate change instructions for the directory with the name `static` including only files starting with `a` but without files ending with `b`:
    ///
    /// ```
    /// # use change_detection::ChangeDetectionBuilder;
    /// # let builder = ChangeDetectionBuilder::default();
    /// builder.path_filter("static", |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().starts_with("a"))
    ///         .unwrap_or(false)
    /// }, |path: &std::path::Path| {
    ///     path.file_name()
    ///         .map(|filename| filename.to_str().unwrap().ends_with("b"))
    ///         .unwrap_or(false)
    /// }).generate();
    /// ```
    pub fn path_filter<P, F1, F2>(
        mut self,
        path: P,
        include: F1,
        exclude: F2,
    ) -> ChangeDetectionBuilder
    where
        P: AsRef<Path>,
        F1: PathMatcher + 'static,
        F2: PathMatcher + 'static,
    {
        self.paths.push(ChangeDetectionPath::PathIncludeExclude {
            path: path.as_ref().into(),
            include: Box::new(include),
            exclude: Box::new(exclude),
        });
        self
    }

    fn include<F>(mut self, filter: F) -> ChangeDetectionBuilder
    where
        F: PathMatcher + 'static,
    {
        self.include = Some(Box::new(filter));
        self
    }

    fn exclude<F>(mut self, filter: F) -> ChangeDetectionBuilder
    where
        F: PathMatcher + 'static,
    {
        self.exclude = Some(Box::new(filter));
        self
    }

    pub fn generate(self) {
        self.generate_extended(print_change_detection_instruction)
    }

    fn generate_extended<F>(self, mut f: F)
    where
        F: FnMut(&Path),
    {
        for path in &self.paths {
            path.generate(&self, &mut f);
        }
    }

    fn filter_include_exclude(&self, path: &Path) -> bool {
        self.include
            .as_ref()
            .map_or(true, |filter| filter.matches(path))
            && self
                .exclude
                .as_ref()
                .map_or(true, |filter| !filter.matches(path))
    }
}

pub enum ChangeDetectionPath {
    Path(PathBuf),
    PathInclude(PathBuf, Box<dyn PathMatcher>),
    PathExclude(PathBuf, Box<dyn PathMatcher>),
    PathIncludeExclude {
        path: PathBuf,
        include: Box<dyn PathMatcher>,
        exclude: Box<dyn PathMatcher>,
    },
}

fn print_change_detection_instruction(path: &Path) {
    println!(
        "cargo:rerun-if-changed={}",
        path.to_slash().expect("can't convert path to utf-8 string")
    );
}

impl ChangeDetectionPath {
    fn collect(&self, builder: &ChangeDetectionBuilder) -> std::io::Result<Vec<PathBuf>> {
        let filter_fn: Box<dyn Fn(&_) -> bool> =
            Box::new(|path: &std::path::Path| builder.filter_include_exclude(path));

        let (path, filter): (&PathBuf, Box<dyn Fn(&_) -> bool>) = match self {
            ChangeDetectionPath::Path(path) => (path, filter_fn),
            ChangeDetectionPath::PathInclude(path, include_filter) => (
                path,
                Box::new(move |p: &Path| filter_fn(p.as_ref()) && include_filter.matches(p)),
            ),
            ChangeDetectionPath::PathExclude(path, exclude_filter) => (
                path,
                Box::new(move |p: &Path| filter_fn(p.as_ref()) && !exclude_filter.matches(p)),
            ),
            ChangeDetectionPath::PathIncludeExclude {
                path,
                include,
                exclude,
            } => (
                path,
                Box::new(move |p: &Path| {
                    filter_fn(p.as_ref()) && include.matches(p) && !exclude.matches(p)
                }),
            ),
        };

        collect_resources(path, &filter)
    }

    fn generate<F>(&self, builder: &ChangeDetectionBuilder, printer: &mut F)
    where
        F: FnMut(&Path),
    {
        for path in self.collect(builder).expect("error collecting resources") {
            printer(path.as_ref());
        }
    }
}

impl<T> From<T> for ChangeDetectionPath
where
    T: AsRef<Path>,
{
    fn from(path: T) -> Self {
        ChangeDetectionPath::Path(path.as_ref().into())
    }
}

fn collect_resources(path: &Path, filter: &dyn PathMatcher) -> std::io::Result<Vec<PathBuf>> {
    let mut result = vec![];

    if filter.matches(path.as_ref()) {
        result.push(path.into());
    }

    if !path.is_dir() {
        return Ok(result);
    }

    for entry in std::fs::read_dir(&path)? {
        let entry = entry?;
        let path = entry.path();

        let nested = collect_resources(path.as_ref(), filter)?;
        result.extend(nested);
    }

    Ok(result)
}

#[cfg(test)]
mod tests {
    use super::{ChangeDetection, ChangeDetectionBuilder};
    use std::path::{Path, PathBuf};

    fn assert_change_detection(builder: ChangeDetectionBuilder, expected: &[&str]) {
        let mut result: Vec<PathBuf> = vec![];
        let r = &mut result;

        builder.generate_extended(move |path| r.push(path.into()));

        let mut expected = expected
            .iter()
            .map(|s| PathBuf::from(s))
            .collect::<Vec<_>>();

        expected.sort();
        result.sort();

        assert_eq!(result, expected);
    }

    #[test]
    fn single_file() {
        assert_change_detection(ChangeDetection::path("src/lib.rs"), &["src/lib.rs"]);
    }

    #[test]
    fn single_path() {
        assert_change_detection(ChangeDetection::path("src"), &["src", "src/lib.rs"]);
    }

    #[test]
    fn fixture_01() {
        assert_change_detection(
            ChangeDetection::path("fixtures-01"),
            &[
                "fixtures-01",
                "fixtures-01/a",
                "fixtures-01/ab",
                "fixtures-01/b",
                "fixtures-01/bc",
                "fixtures-01/c",
                "fixtures-01/cd",
            ],
        );
    }

    #[test]
    fn fixture_01_global_include() {
        assert_change_detection(
            ChangeDetection::include(|path: &Path| {
                path.file_name()
                    .map(|filename| filename.to_str().unwrap().ends_with("b"))
                    .unwrap_or(false)
            })
            .path("fixtures-01"),
            &["fixtures-01/ab", "fixtures-01/b"],
        );
    }

    #[test]
    fn fixture_01_global_exclude() {
        assert_change_detection(
            ChangeDetection::exclude(|path: &Path| {
                path.file_name()
                    .map(|filename| filename.to_str().unwrap().ends_with("b"))
                    .unwrap_or(false)
            })
            .path("fixtures-01"),
            &[
                "fixtures-01",
                "fixtures-01/a",
                "fixtures-01/bc",
                "fixtures-01/c",
                "fixtures-01/cd",
            ],
        );
    }

    #[test]
    fn fixture_01_global_filter() {
        assert_change_detection(
            ChangeDetection::filter(
                |path: &Path| {
                    path.file_name()
                        .map(|filename| filename.to_str().unwrap().ends_with("b"))
                        .unwrap_or(false)
                },
                |path: &Path| {
                    path.file_name()
                        .map(|filename| filename.to_str().unwrap().starts_with("a"))
                        .unwrap_or(false)
                },
            )
            .path("fixtures-01"),
            &["fixtures-01/b"],
        );
    }

    #[test]
    fn fixture_02() {
        assert_change_detection(
            ChangeDetection::path("fixtures-02"),
            &[
                "fixtures-02",
                "fixtures-02/abc",
                "fixtures-02/def",
                "fixtures-02/ghk",
            ],
        );
    }

    #[test]
    fn fixture_03() {
        assert_change_detection(
            ChangeDetection::path("fixtures-03"),
            &[
                "fixtures-03",
                "fixtures-03/hello",
                "fixtures-03/hello.c",
                "fixtures-03/hello.js",
            ],
        );
    }

    #[test]
    fn all_fixtures() {
        assert_change_detection(
            ChangeDetection::path("fixtures-01")
                .path("fixtures-02")
                .path("fixtures-03"),
            &[
                "fixtures-01",
                "fixtures-01/a",
                "fixtures-01/ab",
                "fixtures-01/b",
                "fixtures-01/bc",
                "fixtures-01/c",
                "fixtures-01/cd",
                "fixtures-02",
                "fixtures-02/abc",
                "fixtures-02/def",
                "fixtures-02/ghk",
                "fixtures-03",
                "fixtures-03/hello",
                "fixtures-03/hello.c",
                "fixtures-03/hello.js",
            ],
        );
    }

    #[test]
    #[cfg(feature = "glob")]
    fn path_matchers() {
        use path_matchers::glob;
        assert_change_detection(
            ChangeDetection::include(glob("**/a*").unwrap())
                .path("fixtures-01")
                .path("fixtures-02")
                .path("fixtures-03"),
            &["fixtures-01/a", "fixtures-01/ab", "fixtures-02/abc"],
        );
    }

    #[test]
    fn npm_example() {
        assert_change_detection(
            ChangeDetection::path_exclude("fixtures-04", |path: &Path| {
                path.to_str() == Some("fixtures-04") || !path.is_dir()
            }),
            &[
                "fixtures-04/dist",
                "fixtures-04/dist/imgs",
                "fixtures-04/src",
                "fixtures-04/src/imgs",
            ],
        );
    }
}