From 722c7e4a1b5acda4472338f021f1a216ad9c6c08 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 23 Aug 2018 19:46:21 -0400 Subject: [PATCH] Add deno.argv. --- js/deno.ts | 1 + js/main.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/deno.ts b/js/deno.ts index f7f6c521ee..63bee0b7cb 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -2,3 +2,4 @@ // Public deno module. export { exit, readFileSync, writeFileSync } from "./os"; export { libdeno } from "./libdeno"; +export const argv: string[] = []; diff --git a/js/main.ts b/js/main.ts index 51b5790a23..133c477857 100644 --- a/js/main.ts +++ b/js/main.ts @@ -7,6 +7,7 @@ import { DenoCompiler } from "./compiler"; import { libdeno } from "./libdeno"; import * as timers from "./timers"; import { onFetchRes } from "./fetch"; +import { argv } from "./deno"; function startMsg(cmdId: number): Uint8Array { const builder = new flatbuffers.Builder(); @@ -85,13 +86,14 @@ export default function denoMain() { const cwd = startResMsg.cwd(); log("cwd", cwd); - const argv: string[] = []; - for (let i = 0; i < startResMsg.argvLength(); i++) { + // TODO handle shebang. + for (let i = 1; i < startResMsg.argvLength(); i++) { argv.push(startResMsg.argv(i)); } log("argv", argv); + Object.freeze(argv); - const inputFn = argv[1]; + const inputFn = argv[0]; if (!inputFn) { console.log("No input script specified."); os.exit(1);