2019-01-09 17:59:46 +00:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-09 17:30:38 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
|
2019-01-29 01:41:28 +00:00
|
|
|
/// <reference path="./plugins.d.ts" />
|
2018-11-09 00:09:18 +00:00
|
|
|
|
2019-01-29 01:41:28 +00:00
|
|
|
import "./globals";
|
|
|
|
|
2019-02-13 02:14:02 +00:00
|
|
|
import { assert, log } from "./util";
|
2018-08-17 20:34:30 +00:00
|
|
|
import * as os from "./os";
|
2018-09-22 12:47:44 +00:00
|
|
|
import { args } from "./deno";
|
2018-11-05 17:55:59 +00:00
|
|
|
import { replLoop } from "./repl";
|
2019-05-03 20:24:09 +00:00
|
|
|
import { xevalMain, XevalFunc } from "./xeval";
|
2019-02-18 23:43:02 +00:00
|
|
|
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
|
|
|
|
2019-01-09 17:59:46 +00:00
|
|
|
// builtin modules
|
|
|
|
import * as deno from "./deno";
|
2019-01-06 19:17:13 +00:00
|
|
|
|
2019-04-01 19:09:59 +00:00
|
|
|
export default function denoMain(name?: string): void {
|
|
|
|
const startResMsg = os.start(name);
|
2018-08-02 17:13:32 +00:00
|
|
|
|
2019-02-18 23:43:02 +00:00
|
|
|
setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
|
|
|
|
|
2018-10-16 00:52:33 +00:00
|
|
|
// handle `--version`
|
|
|
|
if (startResMsg.versionFlag()) {
|
2019-02-18 23:43:02 +00:00
|
|
|
console.log("deno:", deno.version.deno);
|
|
|
|
console.log("v8:", deno.version.v8);
|
|
|
|
console.log("typescript:", deno.version.typescript);
|
2019-01-29 01:41:28 +00:00
|
|
|
os.exit(0);
|
|
|
|
}
|
|
|
|
|
2019-02-13 02:14:02 +00:00
|
|
|
const mainModule = startResMsg.mainModule();
|
|
|
|
if (mainModule) {
|
|
|
|
assert(mainModule.length > 0);
|
|
|
|
setLocation(mainModule);
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:27:36 +00:00
|
|
|
const cwd = startResMsg.cwd();
|
2018-07-13 07:24:07 +00:00
|
|
|
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++) {
|
2018-09-22 12:47:44 +00:00
|
|
|
args.push(startResMsg.argv(i));
|
2018-06-13 23:40:35 +00:00
|
|
|
}
|
2018-09-22 12:47:44 +00:00
|
|
|
log("args", args);
|
|
|
|
Object.freeze(args);
|
2018-08-17 20:34:30 +00:00
|
|
|
|
2019-05-03 20:24:09 +00:00
|
|
|
if (window["_xevalWrapper"] !== undefined) {
|
|
|
|
xevalMain(window["_xevalWrapper"] as XevalFunc, startResMsg.xevalDelim());
|
|
|
|
} else if (!mainModule) {
|
2018-11-05 17:55:59 +00:00
|
|
|
replLoop();
|
|
|
|
}
|
2018-07-22 01:14:52 +00:00
|
|
|
}
|