summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.rs4
-rw-r--r--src/deno_dir.rs34
-rw-r--r--src/flags.rs5
-rw-r--r--src/main.rs10
-rw-r--r--tests/021_info_flag_setup.out1
-rw-r--r--tests/021_info_flag_setup.test4
-rw-r--r--tests/022_info_flag.out4
-rw-r--r--tests/022_info_flag.test4
-rwxr-xr-xtools/integration_tests.py3
9 files changed, 69 insertions, 0 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index db8d3ecd5..3b5d57ad0 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -24,7 +24,9 @@ pub struct CodeFetchOutput {
pub filename: String,
pub media_type: msg::MediaType,
pub source_code: String,
+ pub maybe_output_code_filename: Option<String>,
pub maybe_output_code: Option<String>,
+ pub maybe_source_map_filename: Option<String>,
pub maybe_source_map: Option<String>,
}
@@ -70,7 +72,9 @@ impl CodeFetchOutput {
filename,
media_type: msg::MediaType::JavaScript, // TODO
source_code,
+ maybe_output_code_filename: None,
maybe_output_code,
+ maybe_source_map_filename: None,
maybe_source_map,
})
}
diff --git a/src/deno_dir.rs b/src/deno_dir.rs
index 6fbe90f68..1a87a7d69 100644
--- a/src/deno_dir.rs
+++ b/src/deno_dir.rs
@@ -180,7 +180,9 @@ impl DenoDir {
filename: filename.to_string(),
media_type: map_content_type(&p, Some(&content_type)),
source_code: source,
+ maybe_output_code_filename: None,
maybe_output_code: None,
+ maybe_source_map_filename: None,
maybe_source_map: None,
}));
} else {
@@ -219,7 +221,9 @@ impl DenoDir {
filename: filename.to_string(),
media_type: map_content_type(&p, maybe_content_type_str),
source_code,
+ maybe_output_code_filename: None,
maybe_output_code: None,
+ maybe_source_map_filename: None,
maybe_source_map: None,
}))
}
@@ -307,6 +311,8 @@ impl DenoDir {
return Ok(out);
}
+ let (output_code_filename, output_source_map_filename) =
+ self.cache_path(&out.filename, &out.source_code);
let result =
self.load_cache(out.filename.as_str(), out.source_code.as_str());
match result {
@@ -322,7 +328,13 @@ impl DenoDir {
filename: out.filename,
media_type: out.media_type,
source_code: out.source_code,
+ maybe_output_code_filename: output_code_filename
+ .to_str()
+ .map(|s| s.to_string()),
maybe_output_code: Some(output_code),
+ maybe_source_map_filename: output_source_map_filename
+ .to_str()
+ .map(|s| s.to_string()),
maybe_source_map: Some(source_map),
}),
}
@@ -419,6 +431,28 @@ impl DenoDir {
debug!("module_name: {}, filename: {}", module_name, filename);
Ok((module_name, filename))
}
+
+ pub fn print_file_info(self: &Self, filename: String) {
+ let maybe_out = self.code_fetch(&filename, ".");
+ if maybe_out.is_err() {
+ println!("{}", maybe_out.unwrap_err());
+ return;
+ }
+ let out = maybe_out.unwrap();
+
+ println!("local: {}", &(out.filename));
+ println!("type: {}", msg::enum_name_media_type(out.media_type));
+ if out.maybe_output_code_filename.is_some() {
+ println!(
+ "compiled: {}",
+ out.maybe_output_code_filename.as_ref().unwrap(),
+ );
+ }
+ if out.maybe_source_map_filename.is_some() {
+ println!("map: {}", out.maybe_source_map_filename.as_ref().unwrap());
+ }
+ // TODO print deps.
+ }
}
impl SourceMapGetter for DenoDir {
diff --git a/src/flags.rs b/src/flags.rs
index 7a400319c..ecc60922e 100644
--- a/src/flags.rs
+++ b/src/flags.rs
@@ -29,6 +29,7 @@ pub struct DenoFlags {
pub allow_run: bool,
pub types: bool,
pub prefetch: bool,
+ pub info: bool,
}
pub fn get_usage(opts: &Options) -> String {
@@ -111,6 +112,9 @@ fn set_recognized_flags(
if matches.opt_present("prefetch") {
flags.prefetch = true;
}
+ if matches.opt_present("info") {
+ flags.info = true;
+ }
if !matches.free.is_empty() {
rest.extend(matches.free);
@@ -147,6 +151,7 @@ pub fn set_flags(
opts.optflag("", "v8-options", "Print V8 command line options.");
opts.optflag("", "types", "Print runtime TypeScript declarations.");
opts.optflag("", "prefetch", "Prefetch the dependencies.");
+ opts.optflag("", "info", "Show source file related info");
let mut flags = DenoFlags::default();
diff --git a/src/main.rs b/src/main.rs
index 1b93ea86d..d50a68ad5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -81,12 +81,22 @@ fn main() {
});
let should_prefetch = flags.prefetch;
+ let should_display_info = flags.info;
let state = Arc::new(isolate::IsolateState::new(flags, rest_argv, None));
let snapshot = snapshot::deno_snapshot();
let mut isolate = isolate::Isolate::new(snapshot, state, ops::dispatch);
tokio_util::init(|| {
+ // Requires tokio
+ if should_display_info {
+ isolate
+ .state
+ .dir
+ .print_file_info(isolate.state.argv[1].clone());
+ std::process::exit(0);
+ }
+
// Setup runtime.
isolate
.execute("denoMain();")
diff --git a/tests/021_info_flag_setup.out b/tests/021_info_flag_setup.out
new file mode 100644
index 000000000..e965047ad
--- /dev/null
+++ b/tests/021_info_flag_setup.out
@@ -0,0 +1 @@
+Hello
diff --git a/tests/021_info_flag_setup.test b/tests/021_info_flag_setup.test
new file mode 100644
index 000000000..eaded0840
--- /dev/null
+++ b/tests/021_info_flag_setup.test
@@ -0,0 +1,4 @@
+# This is used to make sure code for remote source is compiled
+# such that 022_info_flag.test would function correctly
+args: --reload http://127.0.0.1:4545/tests/003_relative_import.ts
+output: tests/021_info_flag_setup.out
diff --git a/tests/022_info_flag.out b/tests/022_info_flag.out
new file mode 100644
index 000000000..9421387a6
--- /dev/null
+++ b/tests/022_info_flag.out
@@ -0,0 +1,4 @@
+local: [WILDCARD]deps/http/127.0.0.1_PORT4545/tests/003_relative_import.ts
+type: TypeScript
+compiled: [WILDCARD].js
+map: [WILDCARD].js.map
diff --git a/tests/022_info_flag.test b/tests/022_info_flag.test
new file mode 100644
index 000000000..e2132a85f
--- /dev/null
+++ b/tests/022_info_flag.test
@@ -0,0 +1,4 @@
+# The output assumes 003_relative_import.ts has already been run earlier
+# and its output is cached to $DENO_DIR.
+args: --info http://127.0.0.1:4545/tests/003_relative_import.ts
+output: tests/022_info_flag.out
diff --git a/tools/integration_tests.py b/tools/integration_tests.py
index cca4a75ca..a6392bae6 100755
--- a/tools/integration_tests.py
+++ b/tools/integration_tests.py
@@ -20,6 +20,9 @@ def read_test(file_name):
lines = test_file.splitlines()
test_dict = {}
for line in lines:
+ if line.strip().startswith("#"):
+ # skip comments
+ continue
key, value = re.split(r":\s+", line)
test_dict[key] = value
return test_dict