mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat: Support file URLs in Deno.run for executable (#6994)
This commit is contained in:
parent
452693256c
commit
18ec1290af
3 changed files with 28 additions and 2 deletions
2
cli/dts/lib.deno.ns.d.ts
vendored
2
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -1896,7 +1896,7 @@ declare namespace Deno {
|
||||||
export interface RunOptions {
|
export interface RunOptions {
|
||||||
/** Arguments to pass. Note, the first element needs to be a path to the
|
/** Arguments to pass. Note, the first element needs to be a path to the
|
||||||
* binary */
|
* binary */
|
||||||
cmd: string[];
|
cmd: string[] | [URL, ...string[]];
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
env?: {
|
env?: {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
const { close } = window.__bootstrap.resources;
|
const { close } = window.__bootstrap.resources;
|
||||||
const { readAll } = window.__bootstrap.buffer;
|
const { readAll } = window.__bootstrap.buffer;
|
||||||
const { sendSync, sendAsync } = window.__bootstrap.dispatchJson;
|
const { sendSync, sendAsync } = window.__bootstrap.dispatchJson;
|
||||||
const { assert } = window.__bootstrap.util;
|
const { assert, pathFromURL } = window.__bootstrap.util;
|
||||||
|
|
||||||
function opKill(pid, signo) {
|
function opKill(pid, signo) {
|
||||||
sendSync("op_kill", { pid, signo });
|
sendSync("op_kill", { pid, signo });
|
||||||
|
@ -98,6 +98,9 @@
|
||||||
stderr = "inherit",
|
stderr = "inherit",
|
||||||
stdin = "inherit",
|
stdin = "inherit",
|
||||||
}) {
|
}) {
|
||||||
|
if (cmd[0] != null) {
|
||||||
|
cmd[0] = pathFromURL(cmd[0]);
|
||||||
|
}
|
||||||
const res = opRun({
|
const res = opRun({
|
||||||
cmd: cmd.map(String),
|
cmd: cmd.map(String),
|
||||||
cwd,
|
cwd,
|
||||||
|
|
|
@ -26,6 +26,29 @@ unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
|
||||||
p.stdout.close();
|
p.stdout.close();
|
||||||
p.close();
|
p.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest({ perms: { run: true } }, async function runUrl(): Promise<void> {
|
||||||
|
const q = Deno.run({
|
||||||
|
cmd: ["python", "-c", "import sys; print sys.executable"],
|
||||||
|
stdout: "piped",
|
||||||
|
});
|
||||||
|
await q.status();
|
||||||
|
const pythonPath = new TextDecoder().decode(await q.output()).trim();
|
||||||
|
q.close();
|
||||||
|
|
||||||
|
const p = Deno.run({
|
||||||
|
cmd: [new URL(`file:///${pythonPath}`), "-c", "print('hello world')"],
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "null",
|
||||||
|
});
|
||||||
|
const status = await p.status();
|
||||||
|
assertEquals(status.success, true);
|
||||||
|
assertEquals(status.code, 0);
|
||||||
|
assertEquals(status.signal, undefined);
|
||||||
|
p.stdout.close();
|
||||||
|
p.close();
|
||||||
|
});
|
||||||
|
|
||||||
unitTest({ perms: { run: true } }, async function runStdinRid0(): Promise<
|
unitTest({ perms: { run: true } }, async function runStdinRid0(): Promise<
|
||||||
void
|
void
|
||||||
> {
|
> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue