diff options
author | John Gardner <gardnerjohng@gmail.com> | 2020-06-11 13:00:29 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 23:00:29 -0400 |
commit | ca5b5ba530eccd1a4ed34bc475250daae489190a (patch) | |
tree | daf31cb89b47943707ca0590174a4fd4750f006c /cli/js | |
parent | a1b37f177be848ce3c3248b6b835f8999e36afff (diff) |
feat: Add Deno.mainModule (#6180)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/lib.deno.unstable.d.ts | 3 | ||||
-rw-r--r-- | cli/js/ops/runtime.ts | 4 | ||||
-rw-r--r-- | cli/js/runtime_main.ts | 2 |
3 files changed, 9 insertions, 0 deletions
diff --git a/cli/js/lib.deno.unstable.d.ts b/cli/js/lib.deno.unstable.d.ts index aebd7f964..dc50416fc 100644 --- a/cli/js/lib.deno.unstable.d.ts +++ b/cli/js/lib.deno.unstable.d.ts @@ -1245,4 +1245,7 @@ declare namespace Deno { * Requires `allow-env` permission. */ export function hostname(): string; + + /** **UNSTABLE**: The URL of the file that was originally executed from the command-line. */ + export const mainModule: string; } diff --git a/cli/js/ops/runtime.ts b/cli/js/ops/runtime.ts index 632424327..70addf469 100644 --- a/cli/js/ops/runtime.ts +++ b/cli/js/ops/runtime.ts @@ -21,6 +21,10 @@ export function opStart(): Start { return sendSync("op_start"); } +export function opMainModule(): string { + return sendSync("op_main_module"); +} + export interface Metrics { opsDispatched: number; opsDispatchedSync: number; diff --git a/cli/js/runtime_main.ts b/cli/js/runtime_main.ts index 58405f673..25a6b0f93 100644 --- a/cli/js/runtime_main.ts +++ b/cli/js/runtime_main.ts @@ -9,6 +9,7 @@ import * as denoNs from "./deno.ts"; import * as denoUnstableNs from "./deno_unstable.ts"; +import { opMainModule } from "./ops/runtime.ts"; import { exit } from "./ops/os.ts"; import { readOnly, @@ -106,6 +107,7 @@ export function bootstrapMainRuntime(): void { if (unstableFlag) { Object.defineProperties(globalThis, unstableMethods); Object.defineProperties(globalThis, unstableProperties); + Object.defineProperty(denoNs, "mainModule", getterOnly(opMainModule)); Object.assign(denoNs, denoUnstableNs); } |