From f90f62fa52eccd020026b6899de1b3c7ae0288b6 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 8 Mar 2019 09:25:16 +0900 Subject: [PATCH] Use Deno global var instead of built-in "deno" module (denoland/deno_std#247) Original: https://github.com/denoland/deno_std/commit/395392912d69fe320d74c1f95a27be8e4adc0fa6 --- examples/cat.ts | 8 +++----- fs/glob.ts | 1 - fs/glob_test.ts | 2 +- fs/walk.ts | 2 +- fs/walk_test.ts | 2 +- http/file_server.ts | 5 ++--- http/http_bench.ts | 3 +-- http/server.ts | 4 +++- io/bufio.ts | 4 +++- io/bufio_test.ts | 3 ++- io/iotest.ts | 4 ++-- io/ioutil.ts | 3 ++- io/ioutil_test.ts | 3 ++- io/readers.ts | 3 ++- io/util.ts | 3 ++- io/writers.ts | 2 +- log/handlers.ts | 3 ++- multipart/multipart.ts | 5 ++++- ws/mod.ts | 3 ++- 19 files changed, 36 insertions(+), 27 deletions(-) diff --git a/examples/cat.ts b/examples/cat.ts index 38fdbb2cce..ba8b42bdf1 100644 --- a/examples/cat.ts +++ b/examples/cat.ts @@ -1,12 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import * as deno from "deno"; - async function cat(filenames: string[]): Promise { for (let filename of filenames) { - let file = await deno.open(filename); - await deno.copy(deno.stdout, file); + let file = await Deno.open(filename); + await Deno.copy(Deno.stdout, file); file.close(); } } -cat(deno.args.slice(1)); +cat(Deno.args.slice(1)); diff --git a/fs/glob.ts b/fs/glob.ts index 8c64c45b35..4d4ccc7ce9 100644 --- a/fs/glob.ts +++ b/fs/glob.ts @@ -1,4 +1,3 @@ -import { FileInfo } from "deno"; import { globrex } from "./globrex.ts"; export interface GlobOptions { diff --git a/fs/glob_test.ts b/fs/glob_test.ts index 8691d2c339..2dc509deee 100644 --- a/fs/glob_test.ts +++ b/fs/glob_test.ts @@ -1,5 +1,5 @@ const { mkdir, open } = Deno; -import { FileInfo } from "deno"; +type FileInfo = Deno.FileInfo; import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { glob } from "./glob.ts"; diff --git a/fs/walk.ts b/fs/walk.ts index c76803a2e5..24c800e59f 100644 --- a/fs/walk.ts +++ b/fs/walk.ts @@ -1,5 +1,5 @@ const { readDir, readDirSync, readlink, readlinkSync, stat, statSync } = Deno; -import { FileInfo } from "deno"; +type FileInfo = Deno.FileInfo; export interface WalkOptions { maxDepth?: number; diff --git a/fs/walk_test.ts b/fs/walk_test.ts index 7e6384a60b..93073c6207 100644 --- a/fs/walk_test.ts +++ b/fs/walk_test.ts @@ -1,5 +1,5 @@ const { cwd, chdir, makeTempDir, mkdir, open, build, remove, symlink } = Deno; -import { FileInfo } from "deno"; +type FileInfo = Deno.FileInfo; import { walk, walkSync, WalkOptions } from "./walk.ts"; import { test, TestFunction } from "../testing/mod.ts"; import { assert, assertEquals } from "../testing/asserts.ts"; diff --git a/http/file_server.ts b/http/file_server.ts index 20ad45be64..19a94c6aaa 100755 --- a/http/file_server.ts +++ b/http/file_server.ts @@ -7,7 +7,6 @@ // https://github.com/indexzero/http-server/blob/master/test/http-server-test.js const { ErrorKind, cwd, args, stat, readDir, open } = Deno; -import { DenoError } from "deno"; import { listenAndServe, ServerRequest, @@ -181,8 +180,8 @@ async function serveFile(req: ServerRequest, filename: string) { async function serveFallback(req: ServerRequest, e: Error) { if ( - e instanceof DenoError && - (e as DenoError).kind === ErrorKind.NotFound + e instanceof Deno.DenoError && + (e as Deno.DenoError).kind === ErrorKind.NotFound ) { return { status: 404, diff --git a/http/http_bench.ts b/http/http_bench.ts index c7c2bdf2d0..fa7d40bbcd 100644 --- a/http/http_bench.ts +++ b/http/http_bench.ts @@ -1,8 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import * as deno from "deno"; import { serve } from "./server.ts"; -const addr = deno.args[1] || "127.0.0.1:4500"; +const addr = Deno.args[1] || "127.0.0.1:4500"; const server = serve(addr); const body = new TextEncoder().encode("Hello World"); diff --git a/http/server.ts b/http/server.ts index d391730458..f3b92ee907 100644 --- a/http/server.ts +++ b/http/server.ts @@ -1,6 +1,8 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { listen, toAsyncIterator, copy } = Deno; -import { Conn, Reader, Writer } from "deno"; +type Conn = Deno.Conn; +type Reader = Deno.Reader; +type Writer = Deno.Writer; import { BufReader, BufState, BufWriter } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { STATUS_TEXT } from "./http_status.ts"; diff --git a/io/bufio.ts b/io/bufio.ts index f583a2ff94..f057952fe6 100644 --- a/io/bufio.ts +++ b/io/bufio.ts @@ -3,7 +3,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -import { Reader, ReadResult, Writer } from "deno"; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; +type Writer = Deno.Writer; import { charCode, copyBytes } from "./util.ts"; import { assert } from "../testing/asserts.ts"; diff --git a/io/bufio_test.ts b/io/bufio_test.ts index aed58d9ed0..1351b7e370 100644 --- a/io/bufio_test.ts +++ b/io/bufio_test.ts @@ -4,7 +4,8 @@ // license that can be found in the LICENSE file. const { Buffer } = Deno; -import { Reader, ReadResult } from "deno"; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; import { test } from "../testing/mod.ts"; import { assert, assertEquals } from "../testing/asserts.ts"; import { BufReader, BufWriter } from "./bufio.ts"; diff --git a/io/iotest.ts b/io/iotest.ts index e3a42f58a2..9973562a72 100644 --- a/io/iotest.ts +++ b/io/iotest.ts @@ -2,8 +2,8 @@ // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - -import { Reader, ReadResult } from "deno"; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; /** OneByteReader returns a Reader that implements * each non-empty Read by reading one byte from r. diff --git a/io/ioutil.ts b/io/ioutil.ts index 2d189620d0..484aba2812 100644 --- a/io/ioutil.ts +++ b/io/ioutil.ts @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { BufReader } from "./bufio.ts"; -import { Reader, Writer } from "deno"; +type Reader = Deno.Reader; +type Writer = Deno.Writer; import { assert } from "../testing/asserts.ts"; /** copy N size at the most. If read size is lesser than N, then returns nread */ diff --git a/io/ioutil_test.ts b/io/ioutil_test.ts index 72adfcec28..c6980ebb93 100644 --- a/io/ioutil_test.ts +++ b/io/ioutil_test.ts @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { Buffer } = Deno; -import { Reader, ReadResult } from "deno"; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { diff --git a/io/readers.ts b/io/readers.ts index df02993560..915d73e6cb 100644 --- a/io/readers.ts +++ b/io/readers.ts @@ -1,5 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { Reader, ReadResult } from "deno"; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; import { encode } from "../strings/strings.ts"; /** Reader utility for strings */ diff --git a/io/util.ts b/io/util.ts index d87776ee5a..30df2a0e1f 100644 --- a/io/util.ts +++ b/io/util.ts @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { Buffer, mkdir, open } = Deno; -import { File, Reader } from "deno"; +type File = Deno.File; +type Reader = Deno.Reader; import { encode } from "../strings/strings.ts"; import * as path from "../fs/path.ts"; // `off` is the offset into `dst` where it will at which to begin writing values diff --git a/io/writers.ts b/io/writers.ts index 15c2628aca..07c5743adc 100644 --- a/io/writers.ts +++ b/io/writers.ts @@ -1,5 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { Writer } from "deno"; +type Writer = Deno.Writer; import { decode, encode } from "../strings/strings.ts"; /** Writer utility for buffering string chunks */ diff --git a/log/handlers.ts b/log/handlers.ts index c1f664cc09..666a8aa48f 100644 --- a/log/handlers.ts +++ b/log/handlers.ts @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { open } = Deno; -import { File, Writer } from "deno"; +type File = Deno.File; +type Writer = Deno.Writer; import { getLevelByName, LogLevel } from "./levels.ts"; import { LogRecord } from "./logger.ts"; import { red, yellow, blue, bold } from "../colors/mod.ts"; diff --git a/multipart/multipart.ts b/multipart/multipart.ts index 68785c7c6c..9b3f1ceb01 100644 --- a/multipart/multipart.ts +++ b/multipart/multipart.ts @@ -1,7 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { Buffer, copy, remove } = Deno; -import { Closer, Reader, ReadResult, Writer } from "deno"; +type Closer = Deno.Closer; +type Reader = Deno.Reader; +type ReadResult = Deno.ReadResult; +type Writer = Deno.Writer; import { FormFile } from "./formfile.ts"; import { bytesFindIndex, diff --git a/ws/mod.ts b/ws/mod.ts index 6c827802bb..b68f3ad4a6 100644 --- a/ws/mod.ts +++ b/ws/mod.ts @@ -1,6 +1,7 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. const { Buffer } = Deno; -import { Writer, Conn } from "deno"; +type Conn = Deno.Conn; +type Writer = Deno.Writer; import { BufReader, BufWriter } from "../io/bufio.ts"; import { readLong, readShort, sliceLongToBytes } from "../io/ioutil.ts"; import { Sha1 } from "./sha1.ts";