diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-07-22 03:14:52 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2018-07-22 03:16:17 +0200 |
commit | 845f7215dbde5c4fa448d201c9f7ebbe986eedba (patch) | |
tree | 80ec819df0a5241fd5db1b28642d73a028c55fb0 /js | |
parent | dff5c16e85b9ee7e610d17792f8c301af1a9c458 (diff) |
Replace packer with rollup
Diffstat (limited to 'js')
-rw-r--r-- | js/assets.ts | 82 | ||||
-rw-r--r-- | js/main.ts | 8 | ||||
-rw-r--r-- | js/mock_builtin.js | 1 | ||||
-rw-r--r-- | js/plugins.d.ts | 7 |
4 files changed, 65 insertions, 33 deletions
diff --git a/js/assets.ts b/js/assets.ts index 850fc6c72..e247049c0 100644 --- a/js/assets.ts +++ b/js/assets.ts @@ -1,51 +1,77 @@ // Copyright 2018 Ryan Dahl <ry@tinyclouds.org> // All rights reserved. MIT License. -// This file is formatted as it is because we are using the fact that Parcel -// statically evaluates fs.readFileSync. -import { readFileSync } from "fs"; +// tslint:disable-next-line:no-reference +/// <reference path="plugins.d.ts" /> +// There is a rollup plugin that will inline any module ending with `!string` // tslint:disable:max-line-length +import denoDts from "/js/deno.d.ts!string"; +import libDts from "/third_party/node_modules/typescript/lib/lib.d.ts!string"; +import libDomIterableDts from "/third_party/node_modules/typescript/lib/lib.dom.iterable.d.ts!string"; +import libEs2015CollectionDts from "/third_party/node_modules/typescript/lib/lib.es2015.collection.d.ts!string"; +import libEs2015CoreDts from "/third_party/node_modules/typescript/lib/lib.es2015.core.d.ts!string"; +import libEs2015GeneratorDts from "/third_party/node_modules/typescript/lib/lib.es2015.generator.d.ts!string"; +import libEs2015IterableDts from "/third_party/node_modules/typescript/lib/lib.es2015.iterable.d.ts!string"; +import libEs2015PromiseDts from "/third_party/node_modules/typescript/lib/lib.es2015.promise.d.ts!string"; +import libEs2015ProxyDts from "/third_party/node_modules/typescript/lib/lib.es2015.proxy.d.ts!string"; +import libEs2015ReflectDts from "/third_party/node_modules/typescript/lib/lib.es2015.reflect.d.ts!string"; +import libEs2015SymbolDts from "/third_party/node_modules/typescript/lib/lib.es2015.symbol.d.ts!string"; +import libEs2015SymbolWellknownDts from "/third_party/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts!string"; +import libEs2016ArrayIncludeDts from "/third_party/node_modules/typescript/lib/lib.es2016.array.include.d.ts!string"; +import libEs2017IntlDts from "/third_party/node_modules/typescript/lib/lib.es2017.intl.d.ts!string"; +import libEs2017ObjectDts from "/third_party/node_modules/typescript/lib/lib.es2017.object.d.ts!string"; +import libEs2017SharedmemoryDts from "/third_party/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts!string"; +import libEs2017StringDts from "/third_party/node_modules/typescript/lib/lib.es2017.string.d.ts!string"; +import libEs2017TypedarraysDts from "/third_party/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts!string"; +import libEs2018Dts from "/third_party/node_modules/typescript/lib/lib.es2018.d.ts!string"; +import libEs2018PromiseDts from "/third_party/node_modules/typescript/lib/lib.es2018.promise.d.ts!string"; +import libEs2018RegexpDts from "/third_party/node_modules/typescript/lib/lib.es2018.regexp.d.ts!string"; +import libEsnextArrayDts from "/third_party/node_modules/typescript/lib/lib.esnext.array.d.ts!string"; +import libEsnextAsynciterablesDts from "/third_party/node_modules/typescript/lib/lib.esnext.asynciterable.d.ts!string"; +import libEsnextDts from "/third_party/node_modules/typescript/lib/lib.esnext.d.ts!string"; +import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string"; + // prettier-ignore export const assetSourceCode: { [key: string]: string } = { - "deno.d.ts": readFileSync(__dirname + "/deno.d.ts", "utf8"), - "lib.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.d.ts", "utf8"), + "deno.d.ts": denoDts, + "lib.d.ts": libDts, //"lib.dom.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.dom.d.ts", "utf8"), - "lib.dom.iterable.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.dom.iterable.d.ts", "utf8"), - "lib.es2015.collection.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.collection.d.ts", "utf8"), - "lib.es2015.core.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.core.d.ts", "utf8"), + "lib.dom.iterable.d.ts": libDomIterableDts, + "lib.es2015.collection.d.ts": libEs2015CollectionDts, + "lib.es2015.core.d.ts": libEs2015CoreDts, //"lib.es2015.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.d.ts", "utf8"), - "lib.es2015.generator.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.generator.d.ts", "utf8"), - "lib.es2015.iterable.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.iterable.d.ts", "utf8"), - "lib.es2015.promise.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.promise.d.ts", "utf8"), - "lib.es2015.proxy.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.proxy.d.ts", "utf8"), - "lib.es2015.reflect.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.reflect.d.ts", "utf8"), - "lib.es2015.symbol.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.symbol.d.ts", "utf8"), - "lib.es2015.symbol.wellknown.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts", "utf8"), - "lib.es2016.array.include.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2016.array.include.d.ts", "utf8"), + "lib.es2015.generator.d.ts": libEs2015GeneratorDts, + "lib.es2015.iterable.d.ts": libEs2015IterableDts, + "lib.es2015.promise.d.ts": libEs2015PromiseDts, + "lib.es2015.proxy.d.ts": libEs2015ProxyDts, + "lib.es2015.reflect.d.ts": libEs2015ReflectDts, + "lib.es2015.symbol.d.ts": libEs2015SymbolDts, + "lib.es2015.symbol.wellknown.d.ts": libEs2015SymbolWellknownDts, + "lib.es2016.array.include.d.ts": libEs2016ArrayIncludeDts, //"lib.es2016.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2016.d.ts", "utf8"), //"lib.es2016.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2016.full.d.ts", "utf8"), //"lib.es2017.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.d.ts", "utf8"), //"lib.es2017.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.full.d.ts", "utf8"), - "lib.es2017.intl.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.intl.d.ts", "utf8"), - "lib.es2017.object.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.object.d.ts", "utf8"), - "lib.es2017.sharedmemory.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts", "utf8"), - "lib.es2017.string.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.string.d.ts", "utf8"), - "lib.es2017.typedarrays.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts", "utf8"), - "lib.es2018.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2018.d.ts", "utf8"), + "lib.es2017.intl.d.ts": libEs2017IntlDts, + "lib.es2017.object.d.ts": libEs2017ObjectDts, + "lib.es2017.sharedmemory.d.ts": libEs2017SharedmemoryDts, + "lib.es2017.string.d.ts": libEs2017StringDts, + "lib.es2017.typedarrays.d.ts": libEs2017TypedarraysDts, + "lib.es2018.d.ts": libEs2018Dts, //"lib.es2018.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2018.full.d.ts", "utf8"), - "lib.es2018.promise.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2018.promise.d.ts", "utf8"), - "lib.es2018.regexp.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es2018.regexp.d.ts", "utf8"), + "lib.es2018.promise.d.ts": libEs2018PromiseDts, + "lib.es2018.regexp.d.ts": libEs2018RegexpDts, //"lib.es5.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es5.d.ts", "utf8"), //"lib.es6.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.es6.d.ts", "utf8"), - "lib.esnext.array.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.esnext.array.d.ts", "utf8"), - "lib.esnext.asynciterable.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.esnext.asynciterable.d.ts", "utf8"), - "lib.esnext.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.esnext.d.ts", "utf8"), + "lib.esnext.array.d.ts": libEsnextArrayDts, + "lib.esnext.asynciterable.d.ts": libEsnextAsynciterablesDts, + "lib.esnext.d.ts": libEsnextDts, //"lib.esnext.full.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.esnext.full.d.ts", "utf8"), //"lib.scripthost.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.scripthost.d.ts", "utf8"), //"lib.webworker.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/lib.webworker.d.ts", "utf8"), //"protocol.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/protocol.d.ts", "utf8"), //"tsserverlibrary.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/tsserverlibrary.d.ts", "utf8"), - "typescript.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/typescript.d.ts", "utf8"), + "typescript.d.ts": typescriptDts, //"typescriptServices.d.ts": readFileSync(__dirname + "/../third_party/node_modules/typescript/lib/typescriptServices.d.ts", "utf8"), }; diff --git a/js/main.ts b/js/main.ts index c140304ef..728c46e80 100644 --- a/js/main.ts +++ b/js/main.ts @@ -5,9 +5,6 @@ import { deno as fbs } from "./msg_generated"; import { assert, log } from "./util"; import * as runtime from "./runtime"; -const globalEval = eval; -const window = globalEval("this"); - let cmdIdCounter = 0; function assignCmdId(): number { // TODO(piscisaureus) Safely re-use so they don't overflow. @@ -27,7 +24,8 @@ function startMsg(cmdId: number): Uint8Array { return builder.asUint8Array(); } -window["denoMain"] = () => { +/* tslint:disable-next-line:no-default-export */ +export default function denoMain() { // First we send an empty "Start" message to let the privlaged side know we // are ready. The response should be a "StartRes" message containing the CLI // argv and other info. @@ -61,4 +59,4 @@ window["denoMain"] = () => { const inputFn = argv[1]; const mod = runtime.resolveModule(inputFn, `${cwd}/`); mod.compileAndRun(); -}; +} diff --git a/js/mock_builtin.js b/js/mock_builtin.js new file mode 100644 index 000000000..f237ddf58 --- /dev/null +++ b/js/mock_builtin.js @@ -0,0 +1 @@ +export default undefined; diff --git a/js/plugins.d.ts b/js/plugins.d.ts new file mode 100644 index 000000000..d1dae3885 --- /dev/null +++ b/js/plugins.d.ts @@ -0,0 +1,7 @@ +// This allows TypeScript to resolve any modules that end with `!string` +// as there is a rollup plugin that will take any mids ending with `!string` +// and return them as a string to rollup for inlining +declare module "*!string" { + const value: string; + export default value; +} |