@tauri-apps/plugin-shell
Advanced tools
Comparing version 2.0.0-beta.3 to 2.0.0-beta.4
@@ -237,4 +237,2 @@ /** | ||
execute(): Promise<ChildProcess<O>>; | ||
/** @ignore */ | ||
private collectOutput; | ||
} | ||
@@ -241,0 +239,0 @@ /** |
@@ -66,29 +66,4 @@ import { invoke, Channel } from '@tauri-apps/api/core'; | ||
/** | ||
* Spawns a process. | ||
* | ||
* @ignore | ||
* @param program The name of the scoped command. | ||
* @param onEventHandler Event handler. | ||
* @param args Program arguments. | ||
* @param options Configuration for the process spawn. | ||
* @returns A promise resolving to the process id. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
async function execute(onEventHandler, program, args = [], options) { | ||
if (typeof args === "object") { | ||
Object.freeze(args); | ||
} | ||
const onEvent = new Channel(); | ||
onEvent.onmessage = onEventHandler; | ||
return await invoke("plugin:shell|execute", { | ||
program, | ||
args, | ||
options, | ||
onEvent, | ||
}); | ||
} | ||
/** | ||
* @since 2.0.0 | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -382,3 +357,10 @@ class EventEmitter { | ||
async spawn() { | ||
return await execute((event) => { | ||
const program = this.program; | ||
const args = this.args; | ||
const options = this.options; | ||
if (typeof args === "object") { | ||
Object.freeze(args); | ||
} | ||
const onEvent = new Channel(); | ||
onEvent.onmessage = (event) => { | ||
switch (event.event) { | ||
@@ -398,3 +380,9 @@ case "Error": | ||
} | ||
}, this.program, this.args, this.options).then((pid) => new Child(pid)); | ||
}; | ||
return await invoke("plugin:shell|spawn", { | ||
program, | ||
args, | ||
options, | ||
onEvent, | ||
}).then((pid) => new Child(pid)); | ||
} | ||
@@ -418,34 +406,14 @@ /** | ||
async execute() { | ||
return await new Promise((resolve, reject) => { | ||
this.on("error", reject); | ||
const stdout = []; | ||
const stderr = []; | ||
this.stdout.on("data", (line) => { | ||
stdout.push(line); | ||
}); | ||
this.stderr.on("data", (line) => { | ||
stderr.push(line); | ||
}); | ||
this.on("close", (payload) => { | ||
resolve({ | ||
code: payload.code, | ||
signal: payload.signal, | ||
stdout: this.collectOutput(stdout), | ||
stderr: this.collectOutput(stderr), | ||
}); | ||
}); | ||
this.spawn().catch(reject); | ||
const program = this.program; | ||
const args = this.args; | ||
const options = this.options; | ||
if (typeof args === "object") { | ||
Object.freeze(args); | ||
} | ||
return await invoke("plugin:shell|execute", { | ||
program, | ||
args, | ||
options, | ||
}); | ||
} | ||
/** @ignore */ | ||
collectOutput(events) { | ||
if (this.options.encoding === "raw") { | ||
return events.reduce((p, c) => { | ||
return new Uint8Array([...p, ...c, 10]); | ||
}, new Uint8Array()); | ||
} | ||
else { | ||
return events.join("\n"); | ||
} | ||
} | ||
} | ||
@@ -452,0 +420,0 @@ /** |
{ | ||
"name": "@tauri-apps/plugin-shell", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-beta.4", | ||
"license": "MIT or APACHE-2.0", | ||
@@ -5,0 +5,0 @@ "authors": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45954
1176