diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-28 03:12:25 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2020-01-27 21:12:25 -0500 |
commit | ac10d79d231d3b66b918764b9706597321850687 (patch) | |
tree | 6a781c58075ee0c68091e71d2ffd2bb898dc9dfd /cli/js/os.ts | |
parent | f604becaba0c747fdf8dd9d0d744c7bd19322e41 (diff) |
refactor: isomorphic snapshot for CLI (#3728)
Diffstat (limited to 'cli/js/os.ts')
-rw-r--r-- | cli/js/os.ts | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/cli/js/os.ts b/cli/js/os.ts index cf522f857..554d4f78d 100644 --- a/cli/js/os.ts +++ b/cli/js/os.ts @@ -1,11 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { core } from "./core.ts"; import * as dispatch from "./dispatch.ts"; import { sendSync } from "./dispatch_json.ts"; import { ErrorKind } from "./errors.ts"; -import { assert } from "./util.ts"; import * as util from "./util.ts"; -import { OperatingSystem, Arch } from "./build.ts"; /** Check if running in terminal. * @@ -67,71 +64,6 @@ export function env( }); } -interface Start { - cwd: string; - pid: number; - argv: string[]; - mainModule: string; // Absolute URL. - debugFlag: boolean; - depsFlag: boolean; - typesFlag: boolean; - versionFlag: boolean; - denoVersion: string; - v8Version: string; - tsVersion: string; - noColor: boolean; - os: OperatingSystem; - arch: Arch; -} - -// TODO(bartlomieju): temporary solution, must be fixed when moving -// dispatches to separate crates -export function initOps(): void { - const ops = core.ops(); - for (const [name, opId] of Object.entries(ops)) { - const opName = `OP_${name.toUpperCase()}`; - // Assign op ids to actual variables - // TODO(ry) This type casting is gross and should be fixed. - ((dispatch as unknown) as { [key: string]: number })[opName] = opId; - core.setAsyncHandler(opId, dispatch.getAsyncHandler(opName)); - } -} - -// This function bootstraps an environment within Deno, it is shared both by -// the runtime and the compiler environments. -// @internal -export function start(preserveDenoNamespace = true, source?: string): Start { - initOps(); - // First we send an empty `Start` message to let the privileged side know we - // are ready. The response should be a `StartRes` message containing the CLI - // args and other info. - const startResponse = sendSync(dispatch.OP_START); - const { pid, noColor, debugFlag } = startResponse; - - util.setLogDebug(debugFlag, source); - - // pid and noColor need to be set in the Deno module before it's set to be - // frozen. - util.immutableDefine(globalThis.Deno, "pid", pid); - util.immutableDefine(globalThis.Deno, "noColor", noColor); - Object.freeze(globalThis.Deno); - - if (preserveDenoNamespace) { - util.immutableDefine(globalThis, "Deno", globalThis.Deno); - // Deno.core could ONLY be safely frozen here (not in globals.ts) - // since shared_queue.js will modify core properties. - Object.freeze(globalThis.Deno.core); - // core.sharedQueue is an object so we should also freeze it. - Object.freeze(globalThis.Deno.core.sharedQueue); - } else { - // Remove globalThis.Deno - delete globalThis.Deno; - assert(globalThis.Deno === undefined); - } - - return startResponse; -} - type DirKind = | "home" | "cache" |