Skip to content

Commit

Permalink
Remove ts_library_builder, maintain lib.deno_runtime.d.ts by hand (#2827
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ry committed Aug 30, 2019
1 parent 5401cb7 commit c370f74
Show file tree
Hide file tree
Showing 29 changed files with 2,869 additions and 1,753 deletions.
45 changes: 3 additions & 42 deletions cli/BUILD.gn
Expand Up @@ -61,7 +61,6 @@ if (is_posix) {
}

ts_sources = [
"../js/assets.ts",
"../js/base64.ts",
"../js/blob.ts",
"../js/body.ts",
Expand Down Expand Up @@ -98,6 +97,7 @@ ts_sources = [
"../js/globals.ts",
"../js/headers.ts",
"../js/io.ts",
"../js/lib.deno_runtime.d.ts",
"../js/lib.web_assembly.d.ts",
"../js/link.ts",
"../js/location.ts",
Expand Down Expand Up @@ -200,55 +200,16 @@ rust_test("cli_test") {
env = [ "CARGO_PKG_VERSION=${deno_cargo_info.version}" ]
}

# Generates the core TypeScript type library for deno that will be
# included in the runtime bundle
run_node("deno_runtime_declaration") {
out_dir = target_gen_dir
sources = ts_sources
outputs = [
"$out_dir/lib/lib.deno_runtime.d.ts",
]
inputs = ts_sources + [
"//tools/ts_library_builder/tsconfig.json",
"//tools/ts_library_builder/main.ts",
"//tools/ts_library_builder/build_library.ts",
"//tools/ts_library_builder/ast_util.ts",
]
args = [
rebase_path("//node_modules/ts-node/dist/bin.js", root_build_dir),
"--project",
rebase_path("//tools/ts_library_builder/tsconfig.json"),
"--skip-ignore",
rebase_path("//tools/ts_library_builder/main.ts", root_build_dir),
"--basePath",
rebase_path("//", root_build_dir),
"--inline",
rebase_path("//js/lib.web_assembly.d.ts", root_build_dir),
"--buildPath",
rebase_path(root_build_dir, root_build_dir),
"--outFile",
rebase_path(outputs[0], root_build_dir),
"--silent",
]
if (is_debug) {
args += [ "--debug" ]
}
}

bundle("main_bundle") {
sources = ts_sources
out_dir = "$target_gen_dir/bundle/"
out_name = "main"
deps = [
":deno_runtime_declaration",
]
}

bundle("compiler_bundle") {
sources = ts_sources
out_dir = "$target_gen_dir/bundle/"
out_name = "compiler"
deps = [
":deno_runtime_declaration",
]
}

# Generates $target_gen_dir/snapshot_deno.bin
Expand Down
59 changes: 59 additions & 0 deletions cli/assets.rs
@@ -0,0 +1,59 @@
static DENO_RUNTIME: &str = include_str!("../js/lib.deno_runtime.d.ts");

macro_rules! inc {
($e:expr) => {
Some(include_str!(concat!(
"../third_party/node_modules/typescript/lib/",
$e
)))
};
}

pub fn get_source_code(name: &str) -> Option<&'static str> {
match name {
"lib.deno_runtime.d.ts" => Some(DENO_RUNTIME),
"lib.es2015.collection.d.ts" => inc!("lib.es2015.collection.d.ts"),
"lib.es2015.core.d.ts" => inc!("lib.es2015.core.d.ts"),
"lib.es2015.d.ts" => inc!("lib.es2015.d.ts"),
"lib.es2015.generator.d.ts" => inc!("lib.es2015.generator.d.ts"),
"lib.es2015.iterable.d.ts" => inc!("lib.es2015.iterable.d.ts"),
"lib.es2015.promise.d.ts" => inc!("lib.es2015.promise.d.ts"),
"lib.es2015.proxy.d.ts" => inc!("lib.es2015.proxy.d.ts"),
"lib.es2015.reflect.d.ts" => inc!("lib.es2015.reflect.d.ts"),
"lib.es2015.symbol.d.ts" => inc!("lib.es2015.symbol.d.ts"),
"lib.es2015.symbol.wellknown.d.ts" => {
inc!("lib.es2015.symbol.wellknown.d.ts")
}
"lib.es2016.array.include.d.ts" => inc!("lib.es2016.array.include.d.ts"),
"lib.es2016.d.ts" => inc!("lib.es2016.d.ts"),
"lib.es2017.d.ts" => inc!("lib.es2017.d.ts"),
"lib.es2017.intl.d.ts" => inc!("lib.es2017.intl.d.ts"),
"lib.es2017.object.d.ts" => inc!("lib.es2017.object.d.ts"),
"lib.es2017.sharedmemory.d.ts" => inc!("lib.es2017.sharedmemory.d.ts"),
"lib.es2017.string.d.ts" => inc!("lib.es2017.string.d.ts"),
"lib.es2017.typedarrays.d.ts" => inc!("lib.es2017.typedarrays.d.ts"),
"lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
"lib.es2018.asynciterable.d.ts" => inc!("lib.es2018.asynciterable.d.ts"),
"lib.es2018.intl.d.ts" => inc!("lib.es2018.intl.d.ts"),
"lib.es2018.promise.d.ts" => inc!("lib.es2018.promise.d.ts"),
"lib.es2018.regexp.d.ts" => inc!("lib.es2018.regexp.d.ts"),
"lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
"lib.es2019.array.d.ts" => inc!("lib.es2019.array.d.ts"),
"lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
"lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
"lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
"lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
"lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"),
"lib.es2020.symbol.wellknown.d.ts" => {
inc!("lib.es2020.symbol.wellknown.d.ts")
}
"lib.es5.d.ts" => inc!("lib.es5.d.ts"),
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
"lib.esnext.array.d.ts" => inc!("lib.esnext.array.d.ts"),
"lib.esnext.asynciterable.d.ts" => inc!("lib.esnext.asynciterable.d.ts"),
"lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"),
"lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"),
"lib.esnext.symbol.d.ts" => inc!("lib.esnext.symbol.d.ts"),
_ => None,
}
}
6 changes: 2 additions & 4 deletions cli/main.rs
Expand Up @@ -18,6 +18,7 @@ extern crate serde_derive;
extern crate url;

mod ansi;
mod assets;
pub mod compilers;
pub mod deno_dir;
pub mod deno_error;
Expand Down Expand Up @@ -127,10 +128,7 @@ fn create_worker_and_state(
}

fn types_command() {
let content = include_str!(concat!(
env!("GN_OUT_DIR"),
"/gen/cli/lib/lib.deno_runtime.d.ts"
));
let content = assets::get_source_code("lib.deno_runtime.d.ts").unwrap();
println!("{}", content);
}

Expand Down
19 changes: 19 additions & 0 deletions cli/ops/compiler.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::assets;
use crate::state::ThreadSafeState;
use crate::tokio_util;
use deno::*;
Expand Down Expand Up @@ -66,3 +67,21 @@ pub fn op_fetch_source_file(
"sourceCode": String::from_utf8(out.source_code).unwrap(),
})))
}

#[derive(Deserialize)]
struct FetchAssetArgs {
name: String,
}

pub fn op_fetch_asset(
_state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: FetchAssetArgs = serde_json::from_value(args)?;
if let Some(source_code) = assets::get_source_code(&args.name) {
Ok(JsonOp::Sync(json!(source_code)))
} else {
panic!("op_fetch_asset bad asset {}", args.name)
}
}
7 changes: 7 additions & 0 deletions cli/ops/mod.rs
Expand Up @@ -80,6 +80,7 @@ pub const OP_READ_LINK: OpId = 53;
pub const OP_TRUNCATE: OpId = 54;
pub const OP_MAKE_TEMP_DIR: OpId = 55;
pub const OP_CWD: OpId = 56;
pub const OP_FETCH_ASSET: OpId = 57;

pub fn dispatch(
state: &ThreadSafeState,
Expand Down Expand Up @@ -293,6 +294,12 @@ pub fn dispatch(
dispatch_json::dispatch(fs::op_make_temp_dir, state, control, zero_copy)
}
OP_CWD => dispatch_json::dispatch(fs::op_cwd, state, control, zero_copy),
OP_FETCH_ASSET => dispatch_json::dispatch(
compiler::op_fetch_asset,
state,
control,
zero_copy,
),
_ => panic!("bad op_id"),
};

Expand Down
99 changes: 0 additions & 99 deletions js/assets.ts

This file was deleted.

8 changes: 5 additions & 3 deletions js/compiler.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as ts from "typescript";
import { assetSourceCode } from "./assets";
import { bold, cyan, yellow } from "./colors";
import { Console } from "./console";
import { core } from "./core";
Expand Down Expand Up @@ -128,6 +127,10 @@ interface EmitResult {
diagnostics?: Diagnostic;
}

function fetchAsset(name: string): string {
return sendSync(dispatch.OP_FETCH_ASSET, { name });
}

/** Ops to Rust to resolve and fetch a modules meta data. */
function fetchSourceFile(specifier: string, referrer: string): SourceFile {
util.log("compiler.fetchSourceFile", { specifier, referrer });
Expand Down Expand Up @@ -222,8 +225,7 @@ class Host implements ts.CompilerHost {
const assetName = moduleName.includes(".")
? moduleName
: `${moduleName}.d.ts`;
assert(assetName in assetSourceCode, `No such asset "${assetName}"`);
const sourceCode = assetSourceCode[assetName];
const sourceCode = fetchAsset(assetName);
const sourceFile = {
moduleName,
filename: specifier,
Expand Down
1 change: 1 addition & 0 deletions js/dispatch.ts
Expand Up @@ -59,6 +59,7 @@ export const OP_READ_LINK = 53;
export const OP_TRUNCATE = 54;
export const OP_MAKE_TEMP_DIR = 55;
export const OP_CWD = 56;
export const OP_FETCH_ASSET = 57;

export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
switch (opId) {
Expand Down
3 changes: 0 additions & 3 deletions js/globals.ts
Expand Up @@ -37,9 +37,6 @@ import { core } from "./core";
// file are tracked and created as part of default library that is built into
// Deno, we only need to declare the enough to compile Deno.
declare global {
const console: consoleTypes.Console;
const setTimeout: typeof timers.setTimeout;

interface CallSite {
getThis(): unknown;
getTypeName(): string;
Expand Down

0 comments on commit c370f74

Please sign in to comment.