Skip to content

Commit c370f74

Browse files
authored
Remove ts_library_builder, maintain lib.deno_runtime.d.ts by hand (#2827)
1 parent 5401cb7 commit c370f74

29 files changed

+2869
-1753
lines changed

cli/BUILD.gn

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ if (is_posix) {
6161
}
6262

6363
ts_sources = [
64-
"../js/assets.ts",
6564
"../js/base64.ts",
6665
"../js/blob.ts",
6766
"../js/body.ts",
@@ -98,6 +97,7 @@ ts_sources = [
9897
"../js/globals.ts",
9998
"../js/headers.ts",
10099
"../js/io.ts",
100+
"../js/lib.deno_runtime.d.ts",
101101
"../js/lib.web_assembly.d.ts",
102102
"../js/link.ts",
103103
"../js/location.ts",
@@ -200,55 +200,16 @@ rust_test("cli_test") {
200200
env = [ "CARGO_PKG_VERSION=${deno_cargo_info.version}" ]
201201
}
202202

203-
# Generates the core TypeScript type library for deno that will be
204-
# included in the runtime bundle
205-
run_node("deno_runtime_declaration") {
206-
out_dir = target_gen_dir
207-
sources = ts_sources
208-
outputs = [
209-
"$out_dir/lib/lib.deno_runtime.d.ts",
210-
]
211-
inputs = ts_sources + [
212-
"//tools/ts_library_builder/tsconfig.json",
213-
"//tools/ts_library_builder/main.ts",
214-
"//tools/ts_library_builder/build_library.ts",
215-
"//tools/ts_library_builder/ast_util.ts",
216-
]
217-
args = [
218-
rebase_path("//node_modules/ts-node/dist/bin.js", root_build_dir),
219-
"--project",
220-
rebase_path("//tools/ts_library_builder/tsconfig.json"),
221-
"--skip-ignore",
222-
rebase_path("//tools/ts_library_builder/main.ts", root_build_dir),
223-
"--basePath",
224-
rebase_path("//", root_build_dir),
225-
"--inline",
226-
rebase_path("//js/lib.web_assembly.d.ts", root_build_dir),
227-
"--buildPath",
228-
rebase_path(root_build_dir, root_build_dir),
229-
"--outFile",
230-
rebase_path(outputs[0], root_build_dir),
231-
"--silent",
232-
]
233-
if (is_debug) {
234-
args += [ "--debug" ]
235-
}
236-
}
237-
238203
bundle("main_bundle") {
204+
sources = ts_sources
239205
out_dir = "$target_gen_dir/bundle/"
240206
out_name = "main"
241-
deps = [
242-
":deno_runtime_declaration",
243-
]
244207
}
245208

246209
bundle("compiler_bundle") {
210+
sources = ts_sources
247211
out_dir = "$target_gen_dir/bundle/"
248212
out_name = "compiler"
249-
deps = [
250-
":deno_runtime_declaration",
251-
]
252213
}
253214

254215
# Generates $target_gen_dir/snapshot_deno.bin

cli/assets.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
static DENO_RUNTIME: &str = include_str!("../js/lib.deno_runtime.d.ts");
2+
3+
macro_rules! inc {
4+
($e:expr) => {
5+
Some(include_str!(concat!(
6+
"../third_party/node_modules/typescript/lib/",
7+
$e
8+
)))
9+
};
10+
}
11+
12+
pub fn get_source_code(name: &str) -> Option<&'static str> {
13+
match name {
14+
"lib.deno_runtime.d.ts" => Some(DENO_RUNTIME),
15+
"lib.es2015.collection.d.ts" => inc!("lib.es2015.collection.d.ts"),
16+
"lib.es2015.core.d.ts" => inc!("lib.es2015.core.d.ts"),
17+
"lib.es2015.d.ts" => inc!("lib.es2015.d.ts"),
18+
"lib.es2015.generator.d.ts" => inc!("lib.es2015.generator.d.ts"),
19+
"lib.es2015.iterable.d.ts" => inc!("lib.es2015.iterable.d.ts"),
20+
"lib.es2015.promise.d.ts" => inc!("lib.es2015.promise.d.ts"),
21+
"lib.es2015.proxy.d.ts" => inc!("lib.es2015.proxy.d.ts"),
22+
"lib.es2015.reflect.d.ts" => inc!("lib.es2015.reflect.d.ts"),
23+
"lib.es2015.symbol.d.ts" => inc!("lib.es2015.symbol.d.ts"),
24+
"lib.es2015.symbol.wellknown.d.ts" => {
25+
inc!("lib.es2015.symbol.wellknown.d.ts")
26+
}
27+
"lib.es2016.array.include.d.ts" => inc!("lib.es2016.array.include.d.ts"),
28+
"lib.es2016.d.ts" => inc!("lib.es2016.d.ts"),
29+
"lib.es2017.d.ts" => inc!("lib.es2017.d.ts"),
30+
"lib.es2017.intl.d.ts" => inc!("lib.es2017.intl.d.ts"),
31+
"lib.es2017.object.d.ts" => inc!("lib.es2017.object.d.ts"),
32+
"lib.es2017.sharedmemory.d.ts" => inc!("lib.es2017.sharedmemory.d.ts"),
33+
"lib.es2017.string.d.ts" => inc!("lib.es2017.string.d.ts"),
34+
"lib.es2017.typedarrays.d.ts" => inc!("lib.es2017.typedarrays.d.ts"),
35+
"lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
36+
"lib.es2018.asynciterable.d.ts" => inc!("lib.es2018.asynciterable.d.ts"),
37+
"lib.es2018.intl.d.ts" => inc!("lib.es2018.intl.d.ts"),
38+
"lib.es2018.promise.d.ts" => inc!("lib.es2018.promise.d.ts"),
39+
"lib.es2018.regexp.d.ts" => inc!("lib.es2018.regexp.d.ts"),
40+
"lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
41+
"lib.es2019.array.d.ts" => inc!("lib.es2019.array.d.ts"),
42+
"lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
43+
"lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
44+
"lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
45+
"lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
46+
"lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"),
47+
"lib.es2020.symbol.wellknown.d.ts" => {
48+
inc!("lib.es2020.symbol.wellknown.d.ts")
49+
}
50+
"lib.es5.d.ts" => inc!("lib.es5.d.ts"),
51+
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
52+
"lib.esnext.array.d.ts" => inc!("lib.esnext.array.d.ts"),
53+
"lib.esnext.asynciterable.d.ts" => inc!("lib.esnext.asynciterable.d.ts"),
54+
"lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"),
55+
"lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"),
56+
"lib.esnext.symbol.d.ts" => inc!("lib.esnext.symbol.d.ts"),
57+
_ => None,
58+
}
59+
}

cli/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern crate serde_derive;
1818
extern crate url;
1919

2020
mod ansi;
21+
mod assets;
2122
pub mod compilers;
2223
pub mod deno_dir;
2324
pub mod deno_error;
@@ -127,10 +128,7 @@ fn create_worker_and_state(
127128
}
128129

129130
fn types_command() {
130-
let content = include_str!(concat!(
131-
env!("GN_OUT_DIR"),
132-
"/gen/cli/lib/lib.deno_runtime.d.ts"
133-
));
131+
let content = assets::get_source_code("lib.deno_runtime.d.ts").unwrap();
134132
println!("{}", content);
135133
}
136134

cli/ops/compiler.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
22
use super::dispatch_json::{Deserialize, JsonOp, Value};
3+
use crate::assets;
34
use crate::state::ThreadSafeState;
45
use crate::tokio_util;
56
use deno::*;
@@ -66,3 +67,21 @@ pub fn op_fetch_source_file(
6667
"sourceCode": String::from_utf8(out.source_code).unwrap(),
6768
})))
6869
}
70+
71+
#[derive(Deserialize)]
72+
struct FetchAssetArgs {
73+
name: String,
74+
}
75+
76+
pub fn op_fetch_asset(
77+
_state: &ThreadSafeState,
78+
args: Value,
79+
_zero_copy: Option<PinnedBuf>,
80+
) -> Result<JsonOp, ErrBox> {
81+
let args: FetchAssetArgs = serde_json::from_value(args)?;
82+
if let Some(source_code) = assets::get_source_code(&args.name) {
83+
Ok(JsonOp::Sync(json!(source_code)))
84+
} else {
85+
panic!("op_fetch_asset bad asset {}", args.name)
86+
}
87+
}

cli/ops/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub const OP_READ_LINK: OpId = 53;
8080
pub const OP_TRUNCATE: OpId = 54;
8181
pub const OP_MAKE_TEMP_DIR: OpId = 55;
8282
pub const OP_CWD: OpId = 56;
83+
pub const OP_FETCH_ASSET: OpId = 57;
8384

8485
pub fn dispatch(
8586
state: &ThreadSafeState,
@@ -293,6 +294,12 @@ pub fn dispatch(
293294
dispatch_json::dispatch(fs::op_make_temp_dir, state, control, zero_copy)
294295
}
295296
OP_CWD => dispatch_json::dispatch(fs::op_cwd, state, control, zero_copy),
297+
OP_FETCH_ASSET => dispatch_json::dispatch(
298+
compiler::op_fetch_asset,
299+
state,
300+
control,
301+
zero_copy,
302+
),
296303
_ => panic!("bad op_id"),
297304
};
298305

js/assets.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

js/compiler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
22
import * as ts from "typescript";
3-
import { assetSourceCode } from "./assets";
43
import { bold, cyan, yellow } from "./colors";
54
import { Console } from "./console";
65
import { core } from "./core";
@@ -128,6 +127,10 @@ interface EmitResult {
128127
diagnostics?: Diagnostic;
129128
}
130129

130+
function fetchAsset(name: string): string {
131+
return sendSync(dispatch.OP_FETCH_ASSET, { name });
132+
}
133+
131134
/** Ops to Rust to resolve and fetch a modules meta data. */
132135
function fetchSourceFile(specifier: string, referrer: string): SourceFile {
133136
util.log("compiler.fetchSourceFile", { specifier, referrer });
@@ -222,8 +225,7 @@ class Host implements ts.CompilerHost {
222225
const assetName = moduleName.includes(".")
223226
? moduleName
224227
: `${moduleName}.d.ts`;
225-
assert(assetName in assetSourceCode, `No such asset "${assetName}"`);
226-
const sourceCode = assetSourceCode[assetName];
228+
const sourceCode = fetchAsset(assetName);
227229
const sourceFile = {
228230
moduleName,
229231
filename: specifier,

js/dispatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const OP_READ_LINK = 53;
5959
export const OP_TRUNCATE = 54;
6060
export const OP_MAKE_TEMP_DIR = 55;
6161
export const OP_CWD = 56;
62+
export const OP_FETCH_ASSET = 57;
6263

6364
export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
6465
switch (opId) {

js/globals.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ import { core } from "./core";
3737
// file are tracked and created as part of default library that is built into
3838
// Deno, we only need to declare the enough to compile Deno.
3939
declare global {
40-
const console: consoleTypes.Console;
41-
const setTimeout: typeof timers.setTimeout;
42-
4340
interface CallSite {
4441
getThis(): unknown;
4542
getTypeName(): string;

0 commit comments

Comments
 (0)