Skip to content

Commit

Permalink
fix(typing): fix ExternalObject type argument not found
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Nov 15, 2023
1 parent eea9d06 commit 1d726f6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 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<Array<Diagnostic>>): void
pushNativeDiagnostics(diagnostics: ExternalObject<'Diagnostic[]'>): void
getStats(): JsStats
getAssetPath(filename: string, data: PathData): string
getAssetPathWithInfo(filename: string, data: PathData): PathWithInfo
Expand Down Expand Up @@ -307,17 +307,17 @@ export interface JsLoaderContext {
* Internal additional data, contains more than `String`
* @internal
*/
additionalDataExternal: ExternalObject<AdditionalData>
additionalDataExternal: ExternalObject<'AdditionalData'>
/**
* Internal loader context
* @internal
*/
contextExternal: ExternalObject<LoaderRunnerContext>
contextExternal: ExternalObject<'LoaderRunnerContext'>
/**
* Internal loader diagnostic
* @internal
*/
diagnosticsExternal: ExternalObject<Array<Diagnostic>>
diagnosticsExternal: ExternalObject<'Diagnostic[]'>
}

export interface JsModule {
Expand Down Expand Up @@ -662,7 +662,7 @@ export interface RawExternalItemFnCtx {

export interface RawExternalItemFnResult {
externalType?: string
result?: RawExternalItemValue
result?: string | boolean | Array<string> | Record<string, Array<string>>
}

export interface RawExternalsPluginOptions {
Expand Down
4 changes: 3 additions & 1 deletion crates/rspack_binding_options/src/options/raw_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ impl From<RawExternalItemValueWrapper> for ExternalItemValue {
#[napi(object)]
pub struct RawExternalItemFnResult {
pub external_type: Option<String>,
pub result: Option<RawExternalItemValue>,
// sadly, napi.rs does not support type alias at the moment. Need to add Either here
#[allow(type_complexity)]
pub result: Option<Either4<String, bool, Vec<String>, HashMap<String, Vec<String>>>>,
}

impl From<RawExternalItemFnResult> for ExternalItemFnResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ pub struct JsLoaderContext {
pub loader_index_from_js: Option<u32>,
/// Internal additional data, contains more than `String`
/// @internal
#[napi(ts_type = "ExternalObject<'AdditionalData'>")]
pub additional_data_external: External<AdditionalData>,
/// Internal loader context
/// @internal
#[napi(ts_type = "ExternalObject<'LoaderRunnerContext'>")]
pub context_external: External<rspack_core::LoaderRunnerContext>,
/// Internal loader diagnostic
/// @internal
#[napi(ts_type = "ExternalObject<'Diagnostic[]'>")]
pub diagnostics_external: External<Vec<Diagnostic>>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_binding_values/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl JsCompilation {
self.inner.push_diagnostic(diagnostic);
}

#[napi]
#[napi(ts_args_type = r#"diagnostics: ExternalObject<'Diagnostic[]'>"#)]
pub fn push_native_diagnostics(&mut self, mut diagnostics: External<Vec<Diagnostic>>) {
while let Some(diagnostic) = diagnostics.pop() {
self.inner.push_diagnostic(diagnostic);
Expand Down

0 comments on commit 1d726f6

Please sign in to comment.