Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ indexmap = { version = "2.7.0" }
indoc = { version = "2.0.5" }
insta = { version = "1.42.0" }
itertools = { version = "0.14.0" }
itoa = { version = "1.0.14" }
json = { version = "0.12.4" }
lightningcss = { version = "1.0.0-alpha.64", default-features = false, features = ["grid", "serde"] }
linked_hash_set = { version = "0.1.5" }
Expand Down Expand Up @@ -138,6 +139,7 @@ rspack_loader_react_refresh = { version = "0.2.0", path = "crates/rsp
rspack_loader_runner = { version = "0.2.0", path = "crates/rspack_loader_runner" }
rspack_loader_swc = { version = "0.2.0", path = "crates/rspack_loader_swc" }
rspack_loader_testing = { version = "0.2.0", path = "crates/rspack_loader_testing" }
rspack_location = { version = "0.2.0", path = "crates/rspack_location" }
rspack_macros = { version = "0.2.0", path = "crates/rspack_macros" }
rspack_napi = { version = "0.2.0", path = "crates/rspack_napi" }
rspack_napi_macros = { version = "0.2.0", path = "crates/rspack_napi_macros" }
Expand Down
36 changes: 19 additions & 17 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface ContextModule extends Module {
export interface ExternalModule extends Module {
readonly userRequest: string;
}

export type DependencyLocation = SyntheticDependencyLocation | RealDependencyLocation;
/* -- banner.d.ts end -- */

/* -- napi-rs generated below -- */
Expand Down Expand Up @@ -398,11 +400,7 @@ export declare class JsStats {
}

export declare class KnownBuildInfo {
get _assets(): Assets
get _fileDependencies(): Array<string>
get _contextDependencies(): Array<string>
get _missingDependencies(): Array<string>
get _buildDependencies(): Array<string>

}

export declare class Module {
Expand Down Expand Up @@ -678,7 +676,7 @@ export interface JsChunkAssetArgs {
export interface JsChunkGroupOrigin {
module?: Module | undefined
request?: string
loc?: string | JsRealDependencyLocation
loc?: string | RealDependencyLocation
}

export interface JsChunkOptionNameCtx {
Expand Down Expand Up @@ -958,11 +956,6 @@ export interface JsPathDataChunkLike {
id?: string
}

export interface JsRealDependencyLocation {
start: JsSourcePosition
end?: JsSourcePosition
}

export interface JsResolveArgs {
request: string
context: string
Expand Down Expand Up @@ -1150,7 +1143,7 @@ export interface JsRspackError {
name: string
message: string
moduleIdentifier?: string
loc?: string
loc?: DependencyLocation
file?: string
stack?: string
hideStack?: boolean
Expand Down Expand Up @@ -1187,11 +1180,6 @@ export interface JsRuntimeRequirementInTreeResult {
allRuntimeRequirements: JsRuntimeGlobals
}

export interface JsSourcePosition {
line: number
column: number
}

export interface JsStatsAsset {
type: string
name: string
Expand Down Expand Up @@ -2574,6 +2562,11 @@ export interface RawTrustedTypes {
onPolicyCreationFailure?: string
}

export interface RealDependencyLocation {
start: SourcePosition
end?: SourcePosition
}

/**
* Some code is modified based on
* https://github.com/swc-project/swc/blob/d1d0607158ab40463d1b123fed52cc526eba8385/bindings/binding_core_node/src/util.rs#L29-L58
Expand Down Expand Up @@ -2713,6 +2706,11 @@ export interface SourceMapDevToolPluginOptions {
debugIds?: boolean
}

export interface SourcePosition {
line: number
column?: number
}

/**
* Start the async runtime manually.
*
Expand All @@ -2721,6 +2719,10 @@ export interface SourceMapDevToolPluginOptions {
*/
export declare function startAsyncRuntime(): void

export interface SyntheticDependencyLocation {
name: string
}

export interface ThreadsafeNodeFS {
writeFile: (name: string, content: Buffer) => Promise<void>
removeFile: (name: string) => Promise<void>
Expand Down
2 changes: 2 additions & 0 deletions crates/node_binding/scripts/banner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface ContextModule extends Module {
export interface ExternalModule extends Module {
readonly userRequest: string;
}

export type DependencyLocation = SyntheticDependencyLocation | RealDependencyLocation;
/* -- banner.d.ts end -- */

/* -- napi-rs generated below -- */
42 changes: 5 additions & 37 deletions crates/node_binding/src/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ use std::{cell::RefCell, ptr::NonNull};

use napi::{bindgen_prelude::ToNapiValue, Either, Env, JsString};
use napi_derive::napi;
use rspack_core::{
ChunkGroup, ChunkGroupUkey, Compilation, CompilationId, DependencyLocation,
RealDependencyLocation, SourcePosition,
};
use rspack_core::{ChunkGroup, ChunkGroupUkey, Compilation, CompilationId};
use rspack_napi::OneShotRef;
use rustc_hash::FxHashMap as HashMap;

use crate::{JsChunkWrapper, ModuleObject, ModuleObjectRef};
use crate::{location::RealDependencyLocation, JsChunkWrapper, ModuleObject, ModuleObjectRef};

#[napi]
pub struct JsChunkGroup {
Expand Down Expand Up @@ -72,8 +69,8 @@ impl JsChunkGroup {
for origin in origins {
let loc = if let Some(loc) = &origin.loc {
Some(match loc {
DependencyLocation::Real(real) => Either::B(real.clone().into()),
DependencyLocation::Synthetic(synthetic) => {
rspack_core::DependencyLocation::Real(real) => Either::B(real.into()),
rspack_core::DependencyLocation::Synthetic(synthetic) => {
Either::A(env.create_string(&synthetic.name)?)
}
})
Expand Down Expand Up @@ -248,34 +245,5 @@ pub struct JsChunkGroupOrigin<'a> {
#[napi(ts_type = "Module | undefined")]
pub module: Option<ModuleObject>,
pub request: Option<JsString<'a>>,
pub loc: Option<Either<JsString<'a>, JsRealDependencyLocation>>,
}

#[napi(object, object_from_js = false)]
pub struct JsRealDependencyLocation {
pub start: JsSourcePosition,
pub end: Option<JsSourcePosition>,
}

impl From<RealDependencyLocation> for JsRealDependencyLocation {
fn from(value: RealDependencyLocation) -> Self {
Self {
start: value.start.into(),
end: value.end.map(JsSourcePosition::from),
}
}
}
#[napi(object, object_from_js = false)]
pub struct JsSourcePosition {
pub line: u32,
pub column: u32,
}

impl From<SourcePosition> for JsSourcePosition {
fn from(value: SourcePosition) -> Self {
Self {
line: value.line as u32,
column: value.column as u32,
}
}
pub loc: Option<Either<JsString<'a>, RealDependencyLocation>>,
}
13 changes: 12 additions & 1 deletion crates/node_binding/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@ pub fn format_diagnostic(diagnostic: JsDiagnostic) -> Result<External<Diagnostic
Ok(External::new(
Diagnostic::from(error)
.with_file(file.map(Into::into))
.with_loc(loc.map(|l| l.to_string()))
.with_loc(loc.map(|l| {
rspack_core::DependencyLocation::Real(rspack_core::RealDependencyLocation {
start: rspack_core::SourcePosition {
line: l.sl as usize + 1,
column: l.sc as usize,
},
end: Some(rspack_core::SourcePosition {
line: l.el as usize + 1,
column: l.ec as usize,
}),
})
}))
.with_module_identifier(module_identifier.map(Into::into)),
))
}
6 changes: 4 additions & 2 deletions crates/node_binding/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use napi_derive::napi;
use rspack_error::{miette, Diagnostic, Error, Result, RspackSeverity};

use crate::DependencyLocation;

pub enum ErrorCode {
Napi(napi::Status),
Custom(String),
Expand Down Expand Up @@ -63,7 +65,7 @@ pub struct JsRspackError {
pub name: String,
pub message: String,
pub module_identifier: Option<String>,
pub loc: Option<String>,
pub loc: Option<DependencyLocation>,
pub file: Option<String>,
pub stack: Option<String>,
pub hide_stack: Option<bool>,
Expand All @@ -84,7 +86,7 @@ impl JsRspackError {
}),
message,
module_identifier: diagnostic.module_identifier().map(|d| d.to_string()),
loc: diagnostic.loc(),
loc: diagnostic.loc().map(Into::into),
file: diagnostic.file().map(|f| f.as_str().to_string()),
stack: diagnostic.stack(),
hide_stack: diagnostic.hide_stack(),
Expand Down
2 changes: 2 additions & 0 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod filename;
mod fs_node;
mod html;
mod identifier;
mod location;
mod module;
mod module_graph;
mod module_graph_connection;
Expand Down Expand Up @@ -83,6 +84,7 @@ pub use error::*;
pub use exports_info::*;
pub use filename::*;
pub use html::*;
pub use location::*;
pub use module::*;
pub use module_graph::*;
pub use module_graph_connection::*;
Expand Down
Loading
Loading