diff options
-rw-r--r-- | BUILD.gn | 20 | ||||
-rw-r--r-- | js/assets.ts | 33 | ||||
-rw-r--r-- | js/compiler.ts | 8 | ||||
-rw-r--r-- | js/compiler_test.ts | 4 | ||||
-rw-r--r-- | js/deno.ts | 1 | ||||
-rw-r--r-- | js/globals.ts | 10 | ||||
-rw-r--r-- | js/lib.globals.d.ts | 2 | ||||
-rw-r--r-- | js/os.ts | 6 | ||||
-rw-r--r-- | js/tsconfig.generated.json | 1 | ||||
-rw-r--r-- | js/types.ts (renamed from js/types.d.ts) | 8 | ||||
-rw-r--r-- | rollup.config.js | 31 | ||||
-rw-r--r-- | tests/error_003_typescript.ts.out | 4 |
12 files changed, 50 insertions, 78 deletions
@@ -186,23 +186,23 @@ executable("snapshot_creator") { run_node("gen_declarations") { out_dir = target_gen_dir sources = [ + "js/assets.ts", "js/compiler.ts", "js/console.ts", "js/deno.ts", + "js/fetch.ts", + "js/global-eval.ts", "js/globals.ts", "js/os.ts", + "js/text_encoding.ts", "js/timers.ts", "js/tsconfig.generated.json", + "js/types.ts", "js/util.ts", + "js/v8_source_maps.ts" ] outputs = [ - out_dir + "/js/compiler.d.ts", - out_dir + "/js/console.d.ts", - out_dir + "/js/deno.d.ts", - out_dir + "/js/globals.d.ts", - out_dir + "/js/os.d.ts", - out_dir + "/js/timers.d.ts", - out_dir + "/js/util.d.ts", + "$out_dir/types/globals.d.ts", ] deps = [ ":msg_ts", @@ -213,8 +213,8 @@ run_node("gen_declarations") { rebase_path("js/tsconfig.generated.json", root_build_dir), "--baseUrl", rebase_path(root_build_dir, root_build_dir), - "--outDir", - rebase_path(out_dir, root_build_dir), + "--outFile", + rebase_path("$out_dir/types/globals.js", root_build_dir), ] } @@ -233,7 +233,7 @@ run_node("bundle") { "js/plugins.d.ts", "js/text_encoding.ts", "js/timers.ts", - "js/types.d.ts", + "js/types.ts", "js/util.ts", "js/v8_source_maps.ts", "rollup.config.js", diff --git a/js/assets.ts b/js/assets.ts index 89b3e2645..e5ec507f7 100644 --- a/js/assets.ts +++ b/js/assets.ts @@ -1,21 +1,13 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. // tslint:disable-next-line:no-reference -/// <reference path="plugins.d.ts" /> +/// <reference path="./plugins.d.ts" /> // There is a rollup plugin that will inline any module ending with `!string` // tslint:disable:max-line-length // Generated definitions -import compilerDts from "gen/js/compiler.d.ts!string"; -import consoleDts from "gen/js/console.d.ts!string"; -import denoDts from "gen/js/deno.d.ts!string"; -import libdenoDts from "gen/js/libdeno.d.ts!string"; -import globalsDts from "gen/js/globals.d.ts!string"; -import osDts from "gen/js/os.d.ts!string"; -import fetchDts from "gen/js/fetch.d.ts!string"; -import timersDts from "gen/js/timers.d.ts!string"; -import utilDts from "gen/js/util.d.ts!string"; +import globalsDts from "gen/types/globals.d.ts!string"; // Static libraries import libEs2015Dts from "/third_party/node_modules/typescript/lib/lib.es2015.d.ts!string"; @@ -49,24 +41,16 @@ import libEsnextSymbolDts from "/third_party/node_modules/typescript/lib/lib.esn import libGlobalsDts from "/js/lib.globals.d.ts!string"; // Static definitions -import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string"; -import typesDts from "/js/types.d.ts!string"; import fetchTypesDts from "/js/fetch_types.d.ts!string"; +import flatbuffersDts from "/third_party/node_modules/@types/flatbuffers/index.d.ts!string"; +import textEncodingDts from "/third_party/node_modules/@types/text-encoding/index.d.ts!string"; +import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string"; // tslint:enable:max-line-length // prettier-ignore export const assetSourceCode: { [key: string]: string } = { // Generated definitions - "compiler.d.ts": compilerDts, - "console.d.ts": consoleDts, - "deno.d.ts": denoDts, - "libdeno.d.ts": libdenoDts, "globals.d.ts": globalsDts, - "os.d.ts": osDts, - "fetch.d.ts": fetchDts, - "fetch_types.d.ts": fetchTypesDts, - "timers.d.ts": timersDts, - "util.d.ts": utilDts, // Static libraries "lib.es2015.collection.d.ts": libEs2015CollectionDts, @@ -100,9 +84,8 @@ export const assetSourceCode: { [key: string]: string } = { "lib.globals.d.ts": libGlobalsDts, // Static definitions + "fetch-types.d.ts": fetchTypesDts, + "flatbuffers.d.ts": flatbuffersDts, + "text-encoding.d.ts": textEncodingDts, "typescript.d.ts": typescriptDts, - "types.d.ts": typesDts, - - // TODO Remove. - "msg_generated.d.ts": "", }; diff --git a/js/compiler.ts b/js/compiler.ts index 2e8c525b8..28fe8be8f 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -1,4 +1,5 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. +/// <amd-module name="compiler"/> import * as ts from "typescript"; import { assetSourceCode } from "./assets"; import * as deno from "./deno"; @@ -669,10 +670,9 @@ export class DenoCompiler implements ts.LanguageServiceHost { this._log("resolveModuleNames()", { moduleNames, containingFile }); return moduleNames.map(name => { let resolvedFileName; - if (name === "deno") { - resolvedFileName = this.resolveModuleName("deno.d.ts", ASSETS); - } else if (name === "compiler") { - resolvedFileName = this.resolveModuleName("compiler.d.ts", ASSETS); + if (name === "deno" || name === "compiler") { + // builtin modules are part of `globals.d.ts` + resolvedFileName = this.resolveModuleName("globals.d.ts", ASSETS); } else if (name === "typescript") { resolvedFileName = this.resolveModuleName("typescript.d.ts", ASSETS); } else { diff --git a/js/compiler_test.ts b/js/compiler_test.ts index 2fb67ab3b..18c2d16cc 100644 --- a/js/compiler_test.ts +++ b/js/compiler_test.ts @@ -474,7 +474,7 @@ test(function compilerFileExists() { "/root/project" ); assert(compilerInstance.fileExists(moduleMetaData.fileName)); - assert(compilerInstance.fileExists("$asset$/compiler.d.ts")); + assert(compilerInstance.fileExists("$asset$/globals.d.ts")); assertEqual( compilerInstance.fileExists("/root/project/unknown-module.ts"), false @@ -493,7 +493,7 @@ test(function compilerResolveModuleNames() { ["/root/project/foo/bar.ts", false], ["/root/project/foo/baz.ts", false], ["$asset$/lib.globals.d.ts", true], - ["$asset$/deno.d.ts", true] + ["$asset$/globals.d.ts", true] ]; for (let i = 0; i < results.length; i++) { const result = results[i]; diff --git a/js/deno.ts b/js/deno.ts index c9611d116..21766401b 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -1,5 +1,6 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. // Public deno module. +/// <amd-module name="deno"/> export { env, exit, diff --git a/js/globals.ts b/js/globals.ts index 0364aaf98..b90aa46eb 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -2,7 +2,7 @@ import { Console } from "./console"; import * as timers from "./timers"; -import { TextDecoder, TextEncoder } from "./text_encoding"; +import * as textEncoding from "./text_encoding"; import * as fetch_ from "./fetch"; import { libdeno } from "./libdeno"; import { globalEval } from "./global-eval"; @@ -24,8 +24,8 @@ declare global { const fetch: typeof fetch_.fetch; // tslint:disable:variable-name - let TextEncoder: TextEncoder; - let TextDecoder: TextDecoder; + let TextEncoder: typeof textEncoding.TextEncoder; + let TextDecoder: typeof textEncoding.TextDecoder; // tslint:enable:variable-name } @@ -41,7 +41,7 @@ window.clearTimeout = timers.clearTimer; window.clearInterval = timers.clearTimer; window.console = new Console(libdeno.print); -window.TextEncoder = TextEncoder; -window.TextDecoder = TextDecoder; +window.TextEncoder = textEncoding.TextEncoder; +window.TextDecoder = textEncoding.TextDecoder; window.fetch = fetch_.fetch; diff --git a/js/lib.globals.d.ts b/js/lib.globals.d.ts index a1526c573..5243e4b5d 100644 --- a/js/lib.globals.d.ts +++ b/js/lib.globals.d.ts @@ -2,4 +2,4 @@ // This file contains the default TypeScript libraries for the deno runtime. /// <reference no-default-lib="true"/> /// <reference lib="esnext" /> -import "gen/js/globals"; +/// <reference path="globals.d.ts"/> @@ -128,8 +128,8 @@ export function readFileSync(filename: string): Uint8Array { return new Uint8Array(dataArray!); } -function createEnv(_msg: fbs.EnvironRes): { [index:string]: string } { - const env: { [index:string]: string } = {}; +function createEnv(_msg: fbs.EnvironRes): { [index: string]: string } { + const env: { [index: string]: string } = {}; for (let i = 0; i < _msg.mapLength(); i++) { const item = _msg.map(i)!; @@ -169,7 +169,7 @@ function setEnv(key: string, value: string): void { * const newEnv = deno.env(); * console.log(env.TEST_VAR == newEnv.TEST_VAR); */ -export function env(): { [index:string]: string } { +export function env(): { [index: string]: string } { /* Ideally we could write const res = send({ command: fbs.Command.ENV, diff --git a/js/tsconfig.generated.json b/js/tsconfig.generated.json index d3cacd73e..8a8269d5b 100644 --- a/js/tsconfig.generated.json +++ b/js/tsconfig.generated.json @@ -7,6 +7,7 @@ "compilerOptions": { "declaration": true, "emitDeclarationOnly": true, + "module": "amd", "stripInternal": true }, "files": [ diff --git a/js/types.d.ts b/js/types.ts index 110873c6b..7af0a5201 100644 --- a/js/types.d.ts +++ b/js/types.ts @@ -8,6 +8,7 @@ export interface ModuleInfo { outputCode: string | null; } +// tslint:disable:max-line-length // Following definitions adapted from: // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts // Type definitions for Node.js 10.3.x @@ -36,11 +37,13 @@ export interface ModuleInfo { // Alexander T. <https://github.com/a-tarasyuk> // Lishude <https://github.com/islishude> // Andrew Makarov <https://github.com/r3nya> +// tslint:enable:max-line-length export interface CallSite { /** * Value of "this" */ + // tslint:disable-next-line:no-any getThis(): any; /** @@ -133,13 +136,16 @@ declare global { // Declare "static" methods in Error interface ErrorConstructor { /** Create .stack property on a target object */ - captureStackTrace(targetObject: Object, constructorOpt?: Function): void; + captureStackTrace(targetObject: object, constructorOpt?: Function): void; + // tslint:disable:max-line-length /** * Optional override for formatting stack traces * * @see https://github.com/v8/v8/wiki/Stack%20Trace%20API#customizing-stack-traces */ + // tslint:enable:max-line-length + // tslint:disable-next-line:no-any prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any; stackTraceLimit: number; diff --git a/rollup.config.js b/rollup.config.js index 0f0e5a3e1..299bdad92 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -24,15 +24,6 @@ const tsconfigOverride = { } }; -// when the build path is not a child of the root of the project path -// TypeScript will output resources following the same path structure, -// `BASEPATH` will be a relative path to the root of the source project which -// we can use to determine what TypeScript would have output -const basePathParts = process.env.BASEPATH.split("/"); -while (basePathParts[0] === "..") { - basePathParts.shift(); -} - // this is a rollup plugin which will look for imports ending with `!string` and resolve // them with a module that will inline the contents of the file as a string. Needed to // support `js/assets.ts`. @@ -54,23 +45,13 @@ function strings({ include, exclude } = {}) { // strip the `!string` from `importee` importee = importee.slice(0, importee.lastIndexOf("!string")); if (!importee.startsWith("gen/")) { - // this is a static asset which is located relative to the root of the source project + // this is a static asset which is located relative to the root of + // the source project return path.resolve(path.join(process.env.BASEPATH, importee)); } - // ignoring the first part, which is "gen" - const [, ...importeeParts] = importee.split("/"); - // generated assets will be output by TypeScript relative between the build path and the - // root of the project. For example on Travis, the project path is: - // /home/travis/build/denoland/deno/ - // and the build path is: - // /home/travis/out/Default/ - // TypeScript will then output `globals.d.ts` from `js/globals.ts` to: - // /home/travis/out/Default/gen/build/denoland/deno/js/globals.d.ts - // therefore we need to insert any non relative BASEPATH parts into - // the final module ID - return path.resolve( - path.join(process.cwd(), "gen", ...basePathParts, ...importeeParts) - ); + // this is an asset which has been generated, therefore it will be + // located within the build path + return path.resolve(path.join(process.cwd(), importee)); } }, @@ -96,7 +77,7 @@ function resolveGenerated() { return { name: "resolve-msg-generated", resolveId(importee) { - if (importee.startsWith("gen/")) { + if (importee.startsWith("gen/msg_generated")) { const resolved = path.resolve( path.join(process.cwd(), `${importee}.ts`) ); diff --git a/tests/error_003_typescript.ts.out b/tests/error_003_typescript.ts.out index f04be363b..277d4e929 100644 --- a/tests/error_003_typescript.ts.out +++ b/tests/error_003_typescript.ts.out @@ -4,7 +4,7 @@ [30;47m [0m [91m~~~~~~[0m [96m$asset$/globals.d.ts[WILDCARD] - [30;47m[WILDCARD][0m const console: Console; - [30;47m [0m [96m ~~~~~~~[0m + [30;47m[WILDCARD][0m const console: Console; + [30;47m [0m [96m ~~~~~~~[0m 'console' is declared here. |