deno/js/main.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
/// <reference path="./plugins.d.ts" />
import "./globals";
2019-02-13 02:14:02 +00:00
import { assert, log } from "./util";
import * as os from "./os";
import { args } from "./deno";
import { replLoop } from "./repl";
2019-05-03 20:24:09 +00:00
import { xevalMain, XevalFunc } from "./xeval";
import { setVersions } from "./version";
2019-05-03 20:24:09 +00:00
import { window } from "./window";
2019-02-13 02:14:02 +00:00
import { setLocation } from "./location";
2018-06-12 01:54:55 +00:00
// builtin modules
import * as deno from "./deno";
export default function denoMain(name?: string): void {
const startResMsg = os.start(name);
setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
// handle `--version`
if (startResMsg.versionFlag()) {
console.log("deno:", deno.version.deno);
console.log("v8:", deno.version.v8);
console.log("typescript:", deno.version.typescript);
os.exit(0);
}
2019-02-13 02:14:02 +00:00
const mainModule = startResMsg.mainModule();
if (mainModule) {
assert(mainModule.length > 0);
setLocation(mainModule);
}
const cwd = startResMsg.cwd();
log("cwd", cwd);
2018-06-13 23:40:35 +00:00
2018-08-23 23:46:21 +00:00
for (let i = 1; i < startResMsg.argvLength(); i++) {
args.push(startResMsg.argv(i));
2018-06-13 23:40:35 +00:00
}
log("args", args);
Object.freeze(args);
2019-05-03 20:24:09 +00:00
if (window["_xevalWrapper"] !== undefined) {
xevalMain(window["_xevalWrapper"] as XevalFunc, startResMsg.xevalDelim());
} else if (!mainModule) {
replLoop();
}
2018-07-22 01:14:52 +00:00
}