-
-
Notifications
You must be signed in to change notification settings - Fork 786
Expand file tree
/
Copy pathlib.rs
More file actions
48 lines (41 loc) · 1.15 KB
/
lib.rs
File metadata and controls
48 lines (41 loc) · 1.15 KB
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
use std::fmt::Debug;
use rspack_core::{Compilation, CompilationShouldRecord, CompilerShouldEmit, Plugin};
use rspack_error::Result;
use rspack_hook::{plugin, plugin_hook};
#[plugin]
#[derive(Debug)]
pub struct NoEmitOnErrorsPlugin {}
impl Default for NoEmitOnErrorsPlugin {
fn default() -> Self {
Self::new_inner()
}
}
#[plugin_hook(CompilerShouldEmit for NoEmitOnErrorsPlugin)]
async fn should_emit(&self, compilation: &mut Compilation) -> Result<Option<bool>> {
if compilation.get_errors().next().is_some() {
Ok(Some(false))
} else {
Ok(None)
}
}
#[plugin_hook(CompilationShouldRecord for NoEmitOnErrorsPlugin)]
async fn should_record(&self, compilation: &Compilation) -> Result<Option<bool>> {
if compilation.get_errors().next().is_some() {
Ok(Some(false))
} else {
Ok(None)
}
}
impl Plugin for NoEmitOnErrorsPlugin {
fn name(&self) -> &'static str {
"NoEmitOnErrorsPlugin"
}
fn apply(&self, ctx: &mut rspack_core::ApplyContext<'_>) -> Result<()> {
ctx.compiler_hooks.should_emit.tap(should_emit::new(self));
ctx
.compilation_hooks
.should_record
.tap(should_record::new(self));
Ok(())
}
}