Skip to content

Commit

Permalink
feat: align module error
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Dec 5, 2023
1 parent 2155d7d commit 8253343
Show file tree
Hide file tree
Showing 46 changed files with 589 additions and 381 deletions.
4 changes: 2 additions & 2 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class JsCompilation {
getMissingDependencies(): Array<string>
getBuildDependencies(): Array<string>
pushDiagnostic(severity: "error" | "warning", title: string, message: string): void
pushNativeDiagnostics(diagnostics: ExternalObject<'Diagnostic[]'>): void
pushNativeDiagnostics(diagnostics: ExternalObject<'RspackDiagnostic[]'>): void
getStats(): JsStats
getAssetPath(filename: string, data: PathData): string
getAssetPathWithInfo(filename: string, data: PathData): PathWithInfo
Expand Down Expand Up @@ -345,7 +345,7 @@ export interface JsLoaderContext {
* Internal loader diagnostic
* @internal
*/
diagnosticsExternal: ExternalObject<'Diagnostic[]'>
diagnosticsExternal: ExternalObject<'RspackDiagnostic[]'>
}

export interface JsModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use napi_derive::napi;
use rspack_core::{rspack_sources::SourceMap, Content, ResourceData};
use rspack_error::Diagnostic;
use rspack_error::RspackDiagnostic;
use rspack_loader_runner::AdditionalData;
use rustc_hash::FxHashSet as HashSet;
use tracing::{span_enabled, Level};
Expand Down Expand Up @@ -261,8 +261,8 @@ pub struct JsLoaderContext {
pub context_external: External<rspack_core::LoaderRunnerContext>,
/// Internal loader diagnostic
/// @internal
#[napi(ts_type = "ExternalObject<'Diagnostic[]'>")]
pub diagnostics_external: External<Vec<Diagnostic>>,
#[napi(ts_type = "ExternalObject<'RspackDiagnostic[]'>")]
pub diagnostics_external: External<Vec<RspackDiagnostic>>,
}

impl TryFrom<&rspack_core::LoaderContext<'_, rspack_core::LoaderRunnerContext>>
Expand Down Expand Up @@ -322,7 +322,10 @@ impl TryFrom<&rspack_core::LoaderContext<'_, rspack_core::LoaderRunnerContext>>

additional_data_external: External::new(cx.additional_data.clone()),
context_external: External::new(cx.context.clone()),
diagnostics_external: External::new(cx.__diagnostics.clone()),
diagnostics_external: External::new({
eprintln!("Should be able to pipe diagnostic errors");
vec![]
}),
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/rspack_binding_values/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rspack_core::rspack_sources::BoxSource;
use rspack_core::AssetInfo;
use rspack_core::ModuleIdentifier;
use rspack_core::{rspack_sources::SourceExt, NormalModuleSource};
use rspack_error::Diagnostic;
use rspack_error::RspackDiagnostic;
use rspack_identifier::Identifier;
use rspack_napi_shared::NapiResultExt;

Expand Down Expand Up @@ -315,14 +315,14 @@ impl JsCompilation {
#[napi(ts_args_type = r#"severity: "error" | "warning", title: string, message: string"#)]
pub fn push_diagnostic(&mut self, severity: String, title: String, message: String) {
let diagnostic = match severity.as_str() {
"warning" => rspack_error::Diagnostic::warn(title, message, 0, 0),
_ => rspack_error::Diagnostic::error(title, message, 0, 0),
"warning" => rspack_error::RspackDiagnostic::warn(title, message, 0, 0),
_ => rspack_error::RspackDiagnostic::error(title, message, 0, 0),
};
self.inner.push_diagnostic(diagnostic);
}

#[napi(ts_args_type = r#"diagnostics: ExternalObject<'Diagnostic[]'>"#)]
pub fn push_native_diagnostics(&mut self, mut diagnostics: External<Vec<Diagnostic>>) {
#[napi(ts_args_type = r#"diagnostics: ExternalObject<'RspackDiagnostic[]'>"#)]
pub fn push_native_diagnostics(&mut self, mut diagnostics: External<Vec<RspackDiagnostic>>) {
while let Some(diagnostic) = diagnostics.pop() {
self.inner.push_diagnostic(diagnostic);
}
Expand Down
15 changes: 9 additions & 6 deletions crates/rspack_core/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ mod snapshot;
mod storage;
pub use local::*;
use occasion::{
BuildModuleOccasion, CodeGenerateOccasion, CreateChunkAssetsOccasion, ResolveModuleOccasion,
// BuildModuleOccasion,
CodeGenerateOccasion,
CreateChunkAssetsOccasion,
ResolveModuleOccasion,
};
use snapshot::SnapshotManager;
use storage::new_storage;
Expand All @@ -24,7 +27,7 @@ pub struct Cache {
is_idle: AtomicBool,
snapshot_manager: Arc<SnapshotManager>,
pub resolve_module_occasion: ResolveModuleOccasion,
pub build_module_occasion: BuildModuleOccasion,
// pub build_module_occasion: BuildModuleOccasion,
pub code_generate_occasion: CodeGenerateOccasion,
pub create_chunk_assets_occasion: CreateChunkAssetsOccasion,
}
Expand All @@ -39,10 +42,10 @@ impl Cache {
new_storage(&options.cache),
snapshot_manager.clone(),
),
build_module_occasion: BuildModuleOccasion::new(
new_storage(&options.cache),
snapshot_manager,
),
// build_module_occasion: BuildModuleOccasion::new(
// new_storage(&options.cache),
// snapshot_manager,
// ),
code_generate_occasion: CodeGenerateOccasion::new(new_storage(&options.cache)),
create_chunk_assets_occasion: CreateChunkAssetsOccasion::new(new_storage(&options.cache)),
}
Expand Down
Loading

0 comments on commit 8253343

Please sign in to comment.