1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -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());
// 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();
log("cwd", cwd);
@ -64,8 +72,8 @@ export default function denoMain() {
os.exit(1);
}
const printDeps = startResMsg.depsFlag();
if (printDeps) {
// handle `--deps`
if (startResMsg.depsFlag()) {
for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) {
console.log(dep);
}

View file

@ -26,6 +26,7 @@ pub struct DenoFlags {
pub allow_net: bool,
pub allow_env: bool,
pub deps_flag: bool,
pub types_flag: bool,
}
pub fn process(flags: &DenoFlags) {
@ -58,7 +59,8 @@ pub fn print_usage() {
-D or --log-debug Log debug output.
-h or --help Print this message.
--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-env" => flags.allow_env = true,
"--deps" => flags.deps_flag = true,
"--types" => flags.types_flag = true,
"--" => break,
_ => 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
fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) {
let mut rest = vec![];
@ -179,7 +195,8 @@ fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) {
}
true
}).collect();
})
.collect();
// Replace args being sent to V8
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 slice = cstr.to_str().unwrap();
slice.to_string()
}).chain(rest.into_iter())
})
.chain(rest.into_iter())
.collect()
}

View file

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

View file

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

View file

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

View file

@ -4,9 +4,7 @@ import sys
import subprocess
import re
def run_unit_test(deno_exe, permStr, flags=[]):
cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags
def run_unit_test2(cmd):
process = subprocess.Popen(
cmd,
bufsize=1,
@ -28,6 +26,10 @@ def run_unit_test(deno_exe, permStr, flags=[]):
if errcode != 0:
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
# 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
# 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 len(sys.argv) < 2: