From a21a5ad2fa4dcbad58fe63c298c69f8607705bf4 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 13 Feb 2019 02:08:56 +1100 Subject: Add Deno global namespace (#1748) Resolves #1705 This PR adds the Deno APIs as a global namespace named `Deno`. For backwards compatibility, the ability to `import * from "deno"` is preserved. I have tried to convert every test and internal code the references the module to use the namespace instead, but because I didn't break compatibility I am not sure. On the REPL, `deno` no longer exists, replaced only with `Deno` to align with the regular runtime. The runtime type library includes both the namespace and module. This means it duplicates the whole type information. When we remove the functionality from the runtime, it will be a one line change to the library generator to remove the module definition from the type library. I marked a `TODO` in a couple places where to remove the `"deno"` module, but there are additional places I know I didn't mark. --- tests/016_double_await.ts | 6 ++---- tests/cat.ts | 2 +- tests/echo_server.ts | 2 +- tests/exit_error42.ts | 4 +--- tests/http_bench.ts | 7 +++---- tests/is_tty.ts | 3 +-- tests/types.out | 7 ++++--- tests/unbuffered_stderr.ts | 2 +- tests/unbuffered_stdout.ts | 2 +- 9 files changed, 15 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/016_double_await.ts b/tests/016_double_await.ts index 367767736..12dfeeba4 100644 --- a/tests/016_double_await.ts +++ b/tests/016_double_await.ts @@ -1,10 +1,8 @@ -import * as deno from "deno"; - // This is to test if Deno would die at 2nd await // See https://github.com/denoland/deno/issues/919 (async () => { - const currDirInfo = await deno.stat("."); - const parentDirInfo = await deno.stat(".."); + const currDirInfo = await Deno.stat("."); + const parentDirInfo = await Deno.stat(".."); console.log(currDirInfo.isDirectory()); console.log(parentDirInfo.isFile()); })(); diff --git a/tests/cat.ts b/tests/cat.ts index 66df14794..deb2be2f3 100644 --- a/tests/cat.ts +++ b/tests/cat.ts @@ -1,4 +1,4 @@ -import { stdout, open, copy, args } from "deno"; +const { stdout, open, copy, args } = Deno; async function main() { for (let i = 1; i < args.length; i++) { diff --git a/tests/echo_server.ts b/tests/echo_server.ts index 7761c1ad7..15c3112ce 100644 --- a/tests/echo_server.ts +++ b/tests/echo_server.ts @@ -1,4 +1,4 @@ -import { args, listen, copy } from "deno"; +const { args, listen, copy } = Deno; const addr = args[1] || "127.0.0.1:4544"; const listener = listen("tcp", addr); console.log("listening on", addr); diff --git a/tests/exit_error42.ts b/tests/exit_error42.ts index c55cf0ece..e4db41f3a 100644 --- a/tests/exit_error42.ts +++ b/tests/exit_error42.ts @@ -1,5 +1,3 @@ -import * as deno from "deno"; - console.log("before"); -deno.exit(42); +Deno.exit(42); console.log("after"); diff --git a/tests/http_bench.ts b/tests/http_bench.ts index 0c7970691..5b61bd4cd 100644 --- a/tests/http_bench.ts +++ b/tests/http_bench.ts @@ -2,14 +2,13 @@ // TODO Replace this with a real HTTP server once // https://github.com/denoland/deno/issues/726 is completed. // Note: this is a keep-alive server. -import * as deno from "deno"; -const addr = deno.args[1] || "127.0.0.1:4500"; -const listener = deno.listen("tcp", addr); +const addr = Deno.args[1] || "127.0.0.1:4500"; +const listener = Deno.listen("tcp", addr); const response = new TextEncoder().encode( "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" ); -async function handle(conn: deno.Conn): Promise { +async function handle(conn: Deno.Conn): Promise { const buffer = new Uint8Array(1024); try { while (true) { diff --git a/tests/is_tty.ts b/tests/is_tty.ts index a571aee18..2e3fdb49f 100644 --- a/tests/is_tty.ts +++ b/tests/is_tty.ts @@ -1,2 +1 @@ -import { isTTY } from "deno"; -console.log(isTTY().stdin); +console.log(Deno.isTTY().stdin); diff --git a/tests/types.out b/tests/types.out index 375087051..b07e10762 100644 --- a/tests/types.out +++ b/tests/types.out @@ -2,13 +2,14 @@ /// /// -[WILDCARD] -declare module "deno" { + +declare namespace Deno { [WILDCARD] } - +[WILDCARD] declare interface Window { [WILDCARD] + Deno: typeof Deno; } declare const window: Window; diff --git a/tests/unbuffered_stderr.ts b/tests/unbuffered_stderr.ts index df6b0ceb5..f4bceb1fc 100644 --- a/tests/unbuffered_stderr.ts +++ b/tests/unbuffered_stderr.ts @@ -1,3 +1,3 @@ -import { stderr } from "deno"; +const { stderr } = Deno; stderr.write(new TextEncoder().encode("x")); diff --git a/tests/unbuffered_stdout.ts b/tests/unbuffered_stdout.ts index 9c2c2d725..fdb1a0e23 100644 --- a/tests/unbuffered_stdout.ts +++ b/tests/unbuffered_stdout.ts @@ -1,3 +1,3 @@ -import { stdout } from "deno"; +const { stdout } = Deno; stdout.write(new TextEncoder().encode("a")); -- cgit v1.2.3