Skip to content

Commit

Permalink
change deno --prefetch to deno prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Apr 20, 2019
1 parent b2e877e commit 9d8c7d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
14 changes: 6 additions & 8 deletions cli/flags.rs
Expand Up @@ -21,7 +21,6 @@ pub struct DenoFlags {
pub allow_run: bool,
pub allow_high_precision: bool,
pub no_prompts: bool,
pub prefetch: bool,
}

impl<'a> From<ArgMatches<'a>> for DenoFlags {
Expand Down Expand Up @@ -67,9 +66,6 @@ impl<'a> From<ArgMatches<'a>> for DenoFlags {
if matches.is_present("no-prompt") {
flags.no_prompts = true;
}
if matches.is_present("prefetch") {
flags.prefetch = true;
}

flags
}
Expand Down Expand Up @@ -145,12 +141,14 @@ pub fn create_cli_app<'a, 'b>() -> App<'a, 'b> {
.takes_value(true)
.require_equals(true)
.help("Set V8 command line options"),
).arg(
Arg::with_name("prefetch")
.long("prefetch")
.help("Prefetch the dependencies"),
).subcommand(
SubCommand::with_name("prefetch")
.setting(AppSettings::DisableVersion)
.about("Prefetch the dependencies")
.arg(Arg::with_name("file").takes_value(true).required(true)),
).subcommand(
SubCommand::with_name("types")
.setting(AppSettings::DisableVersion)
.about("Print runtime TypeScript declarations"),
).subcommand(
SubCommand::with_name("info")
Expand Down
21 changes: 15 additions & 6 deletions cli/main.rs
Expand Up @@ -152,7 +152,11 @@ fn types_command() {
std::process::exit(0);
}

fn info_command(flags: DenoFlags, argv: Vec<String>) {
fn prefetch_or_info_command(
flags: DenoFlags,
argv: Vec<String>,
print_info: bool,
) {
let (mut worker, state) = get_worker_and_state(flags, argv);

let main_module = state.main_module().unwrap();
Expand All @@ -166,7 +170,9 @@ fn info_command(flags: DenoFlags, argv: Vec<String>) {
worker
.execute_mod_async(&main_url, true)
.and_then(move |worker| {
print_file_info(&worker, &main_module);
if print_info {
print_file_info(&worker, &main_module);
}
worker.then(|result| {
js_check(result);
Ok(())
Expand Down Expand Up @@ -221,8 +227,6 @@ fn run_repl(flags: DenoFlags, argv: Vec<String>) {
}

fn run_script(flags: DenoFlags, argv: Vec<String>) {
let should_prefetch = flags.prefetch;

let (mut worker, state) = get_worker_and_state(flags, argv);

let main_module = state.main_module().unwrap();
Expand All @@ -235,7 +239,7 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
let main_url = root_specifier_to_url(&main_module).unwrap();

worker
.execute_mod_async(&main_url, should_prefetch)
.execute_mod_async(&main_url, false)
.and_then(move |worker| {
worker.then(|result| {
js_check(result);
Expand Down Expand Up @@ -285,7 +289,12 @@ fn main() {
("info", Some(info_match)) => {
let file: &str = info_match.value_of("file").unwrap();
rest_argv.extend(vec![file.to_string()]);
info_command(flags, rest_argv);
prefetch_or_info_command(flags, rest_argv, true);
}
("prefetch", Some(info_match)) => {
let file: &str = info_match.value_of("file").unwrap();
rest_argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, rest_argv, false);
}
("fmt", Some(fmt_match)) => {
let files: Vec<String> = fmt_match
Expand Down
2 changes: 1 addition & 1 deletion tools/prefetch_test.py
Expand Up @@ -13,7 +13,7 @@ def prefetch_test(deno_exe):
deno_dir = mkdtemp()
try:
t = os.path.join(tests_path, "006_url_imports.ts")
output = run_output([deno_exe, "--prefetch", t],
output = run_output([deno_exe, "prefetch", t],
merge_env={"DENO_DIR": deno_dir})
assert output == ""
# Check that we actually did the prefetch.
Expand Down

0 comments on commit 9d8c7d3

Please sign in to comment.