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 crates/akua-napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ export declare function check(args: NapiCheckArgs): any

export declare function diff(args: NapiDiffArgs): any

/**
* Execute any supported package command through the same parser and
* dispatcher as the standalone `akuapkg` binary.
*
* Output is intentionally written by the package command itself, preserving
* its documented JSON/text streams. The numeric result is the package
* contract's stable exit code, not a Node or shell-process exit status.
*/
export declare function execute(args: Array<string>): number

export declare function export(args: NapiExportArgs): any

export declare function fmt(args: NapiFmtArgs): any
Expand Down
1 change: 1 addition & 0 deletions crates/akua-napi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ module.exports = nativeBinding
module.exports.add = nativeBinding.add
module.exports.check = nativeBinding.check
module.exports.diff = nativeBinding.diff
module.exports.execute = nativeBinding.execute
module.exports.export = nativeBinding.export
module.exports.fmt = nativeBinding.fmt
module.exports.inspect = nativeBinding.inspect
Expand Down
22 changes: 22 additions & 0 deletions crates/akua-napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ pub fn version() -> Result<serde_json::Value> {
invoke_verb(|ctx, stdout| verbs::version::run(ctx, stdout).map_err(into_napi_io))
}

/// Execute any supported package command through the same parser and
/// dispatcher as the standalone `akuapkg` binary.
///
/// Output is intentionally written by the package command itself, preserving
/// its documented JSON/text streams. The numeric result is the package
/// contract's stable exit code, not a Node or shell-process exit status.
#[napi]
pub fn execute(args: Vec<String>) -> Result<i32> {
Ok(akuapkg_cli::entrypoint::run_embedded_from(
std::iter::once("akuapkg".to_string()).chain(args),
)
.code())
}

/// Point the embedded helm/kustomize engines at a directory holding
/// their `.wasm`/`.cwasm` artifacts. The JS loader calls this with the
/// resolved `@akua-dev/native-engines` directory at module-load time.
Expand Down Expand Up @@ -697,6 +711,14 @@ edition = "akua.dev/v1alpha1"
dir
}

#[test]
fn execute_returns_the_package_contract_exit_code() {
assert_eq!(
execute(vec!["not-a-command".to_string()]).unwrap(),
ExitCode::UserError.code()
);
}

#[test]
fn version_returns_object_with_version_field() {
let v = version().unwrap();
Expand Down
Loading