1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-18 11:53:59 -05:00

Add support for --types

This commit is contained in:
Kitson Kelly 2018-10-12 08:23:22 +11:00 committed by Ryan Dahl
parent ec402c6932
commit 298d755152
6 changed files with 58 additions and 13 deletions

View file

@ -48,6 +48,14 @@ export default function denoMain() {
setLogDebug(startResMsg.debugFlag()); setLogDebug(startResMsg.debugFlag());
// handle `--types`
if (startResMsg.typesFlag()) {
const defaultLibFileName = compiler.getDefaultLibFileName();
const defaultLibModule = compiler.resolveModule(defaultLibFileName, "");
console.log(defaultLibModule.sourceCode);
os.exit(0);
}
const cwd = startResMsg.cwd(); const cwd = startResMsg.cwd();
log("cwd", cwd); log("cwd", cwd);
@ -64,8 +72,8 @@ export default function denoMain() {
os.exit(1); os.exit(1);
} }
const printDeps = startResMsg.depsFlag(); // handle `--deps`
if (printDeps) { if (startResMsg.depsFlag()) {
for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) {
console.log(dep); console.log(dep);
} }

View file

@ -26,6 +26,7 @@ pub struct DenoFlags {
pub allow_net: bool, pub allow_net: bool,
pub allow_env: bool, pub allow_env: bool,
pub deps_flag: bool, pub deps_flag: bool,
pub types_flag: bool,
} }
pub fn process(flags: &DenoFlags) { pub fn process(flags: &DenoFlags) {
@ -58,7 +59,8 @@ pub fn print_usage() {
-D or --log-debug Log debug output. -D or --log-debug Log debug output.
-h or --help Print this message. -h or --help Print this message.
--v8-options Print V8 command line options. --v8-options Print V8 command line options.
--deps Print module dependencies." --deps Print module dependencies.
--types Print runtime TypeScript declarations."
); );
} }
@ -82,6 +84,7 @@ pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) {
"--allow-net" => flags.allow_net = true, "--allow-net" => flags.allow_net = true,
"--allow-env" => flags.allow_env = true, "--allow-env" => flags.allow_env = true,
"--deps" => flags.deps_flag = true, "--deps" => flags.deps_flag = true,
"--types" => flags.types_flag = true,
"--" => break, "--" => break,
_ => unimplemented!(), _ => unimplemented!(),
} }
@ -165,6 +168,19 @@ fn test_set_flags_4() {
); );
} }
#[test]
fn test_set_flags_5() {
let (flags, rest) = set_flags(svec!["deno", "--types"]);
assert_eq!(rest, svec!["deno"]);
assert_eq!(
flags,
DenoFlags {
types_flag: true,
..DenoFlags::default()
}
)
}
// Returns args passed to V8, followed by args passed to JS // Returns args passed to V8, followed by args passed to JS
fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) { fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) {
let mut rest = vec![]; let mut rest = vec![];
@ -179,7 +195,8 @@ fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) {
} }
true true
}).collect(); })
.collect();
// Replace args being sent to V8 // Replace args being sent to V8
for idx in 0..args.len() { for idx in 0..args.len() {
@ -248,6 +265,7 @@ pub fn v8_set_flags(args: Vec<String>) -> Vec<String> {
let cstr = CStr::from_ptr(*ptr as *const i8); let cstr = CStr::from_ptr(*ptr as *const i8);
let slice = cstr.to_str().unwrap(); let slice = cstr.to_str().unwrap();
slice.to_string() slice.to_string()
}).chain(rest.into_iter()) })
.chain(rest.into_iter())
.collect() .collect()
} }

View file

@ -348,7 +348,8 @@ mod tests {
throw Error("assert error"); throw Error("assert error");
} }
"#, "#,
).expect("execute error"); )
.expect("execute error");
isolate.event_loop(); isolate.event_loop();
}); });
} }
@ -392,7 +393,8 @@ mod tests {
const data = new Uint8Array([42, 43, 44, 45, 46]); const data = new Uint8Array([42, 43, 44, 45, 46]);
libdeno.send(control, data); libdeno.send(control, data);
"#, "#,
).expect("execute error"); )
.expect("execute error");
isolate.event_loop(); isolate.event_loop();
let metrics = isolate.state.metrics.lock().unwrap(); let metrics = isolate.state.metrics.lock().unwrap();
assert_eq!(metrics.ops_dispatched, 1); assert_eq!(metrics.ops_dispatched, 1);
@ -427,7 +429,8 @@ mod tests {
let r = libdeno.send(control, data); let r = libdeno.send(control, data);
if (r != null) throw Error("expected null"); if (r != null) throw Error("expected null");
"#, "#,
).expect("execute error"); )
.expect("execute error");
// Make sure relevant metrics are updated before task is executed. // Make sure relevant metrics are updated before task is executed.
{ {

View file

@ -111,6 +111,7 @@ table StartRes {
debug_flag: bool; debug_flag: bool;
deps_flag: bool; deps_flag: bool;
recompile_flag: bool; recompile_flag: bool;
types_flag: bool;
} }
table CodeFetch { table CodeFetch {

View file

@ -185,6 +185,7 @@ fn op_start(
argv: Some(argv_off), argv: Some(argv_off),
debug_flag: state.flags.log_debug, debug_flag: state.flags.log_debug,
recompile_flag: state.flags.recompile, recompile_flag: state.flags.recompile,
types_flag: state.flags.types_flag,
..Default::default() ..Default::default()
}, },
); );
@ -342,7 +343,8 @@ fn op_env(
..Default::default() ..Default::default()
}, },
) )
}).collect(); })
.collect();
let tables = builder.create_vector(&vars); let tables = builder.create_vector(&vars);
let inner = msg::EnvironRes::create( let inner = msg::EnvironRes::create(
builder, builder,
@ -891,7 +893,8 @@ fn op_read_dir(
..Default::default() ..Default::default()
}, },
) )
}).collect(); })
.collect();
let entries = builder.create_vector(&entries); let entries = builder.create_vector(&entries);
let inner = msg::ReadDirRes::create( let inner = msg::ReadDirRes::create(

View file

@ -4,9 +4,7 @@ import sys
import subprocess import subprocess
import re import re
def run_unit_test2(cmd):
def run_unit_test(deno_exe, permStr, flags=[]):
cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags
process = subprocess.Popen( process = subprocess.Popen(
cmd, cmd,
bufsize=1, bufsize=1,
@ -28,6 +26,10 @@ def run_unit_test(deno_exe, permStr, flags=[]):
if errcode != 0: if errcode != 0:
sys.exit(errcode) sys.exit(errcode)
def run_unit_test(deno_exe, permStr, flags=[]):
cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags
run_unit_test2(cmd)
# We want to test many ops in deno which have different behavior depending on # We want to test many ops in deno which have different behavior depending on
# the permissions set. These tests can specify which permissions they expect, # the permissions set. These tests can specify which permissions they expect,
@ -43,6 +45,16 @@ def unit_tests(deno_exe):
# TODO We might accidentally miss some. We should be smarter about which we # TODO We might accidentally miss some. We should be smarter about which we
# run. Maybe we can use the "filtered out" number to check this. # run. Maybe we can use the "filtered out" number to check this.
# These are not strictly unit tests for Deno, but for ts_library_builder.
# They run under Node, but use the same //js/testing/ library.
run_unit_test2([
"node",
"./node_modules/.bin/ts-node",
"--project",
"tools/ts_library_builder/tsconfig.json",
"tools/ts_library_builder/test.ts"
])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2: if len(sys.argv) < 2: