summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs75
1 files changed, 26 insertions, 49 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 191355a0c..97f3161df 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -286,22 +286,18 @@ async fn print_file_info(
}
fn get_types(unstable: bool) -> String {
+ let mut types = format!(
+ "{}\n{}\n{}",
+ crate::js::DENO_NS_LIB,
+ crate::js::SHARED_GLOBALS_LIB,
+ crate::js::WINDOW_LIB,
+ );
+
if unstable {
- format!(
- "{}\n{}\n{}\n{}",
- crate::js::DENO_NS_LIB,
- crate::js::SHARED_GLOBALS_LIB,
- crate::js::WINDOW_LIB,
- crate::js::UNSTABLE_NS_LIB,
- )
- } else {
- format!(
- "{}\n{}\n{}",
- crate::js::DENO_NS_LIB,
- crate::js::SHARED_GLOBALS_LIB,
- crate::js::WINDOW_LIB,
- )
+ types.push_str(&format!("\n{}", crate::js::UNSTABLE_NS_LIB,));
}
+
+ types
}
async fn info_command(
@@ -348,20 +344,9 @@ async fn lint_command(
files: Vec<String>,
list_rules: bool,
) -> Result<(), ErrBox> {
- let global_state = GlobalState::new(flags)?;
-
- // TODO(bartlomieju): refactor, it's non-sense to create
- // state just to perform unstable check...
- use crate::state::State;
- let state = State::new(
- global_state,
- None,
- ModuleSpecifier::resolve_url("file:///dummy.ts").unwrap(),
- None,
- true,
- )?;
-
- state.check_unstable("lint");
+ if !flags.unstable {
+ exit_unstable("lint");
+ }
if list_rules {
lint::print_rules_list();
@@ -396,13 +381,14 @@ async fn eval_command(
let main_module =
ModuleSpecifier::resolve_url_or_path("./__$deno$eval.ts").unwrap();
let global_state = GlobalState::new(flags)?;
- let mut worker = MainWorker::create(global_state, main_module.clone())?;
+ let mut worker =
+ MainWorker::create(global_state.clone(), main_module.clone())?;
let main_module_url = main_module.as_url().to_owned();
// Create a dummy source file.
let source_code = if print {
- "console.log(".to_string() + &code + ")"
+ format!("console.log({})", code)
} else {
- code.clone()
+ code
}
.into_bytes();
@@ -418,11 +404,8 @@ async fn eval_command(
source_code: TextDocument::new(source_code, Some("utf-8")),
};
// Save our fake file into file fetcher cache
- // to allow module access by TS compiler (e.g. op_fetch_source_files)
- worker
- .state
- .borrow()
- .global_state
+ // to allow module access by TS compiler.
+ global_state
.file_fetcher
.save_source_file_in_cache(&main_module, source_file);
debug!("main_module {}", &main_module);
@@ -520,11 +503,11 @@ async fn doc_command(
&self,
specifier: &str,
) -> Pin<Box<dyn Future<Output = Result<String, OpError>>>> {
- let specifier =
- ModuleSpecifier::resolve_url_or_path(specifier).expect("Bad specifier");
let fetcher = self.clone();
-
+ let specifier = specifier.to_string();
async move {
+ let specifier = ModuleSpecifier::resolve_url_or_path(&specifier)
+ .map_err(OpError::from)?;
let source_file = fetcher
.fetch_source_file(&specifier, None, Permissions::allow_all())
.await?;
@@ -606,11 +589,8 @@ async fn run_command(flags: Flags, script: String) -> Result<(), ErrBox> {
source_code: source.into(),
};
// Save our fake file into file fetcher cache
- // to allow module access by TS compiler (e.g. op_fetch_source_files)
- worker
- .state
- .borrow()
- .global_state
+ // to allow module access by TS compiler
+ global_state
.file_fetcher
.save_source_file_in_cache(&main_module, source_file);
};
@@ -665,11 +645,8 @@ async fn test_command(
),
};
// Save our fake file into file fetcher cache
- // to allow module access by TS compiler (e.g. op_fetch_source_files)
- worker
- .state
- .borrow()
- .global_state
+ // to allow module access by TS compiler
+ global_state
.file_fetcher
.save_source_file_in_cache(&main_module, source_file);
let execute_result = worker.execute_module(&main_module).await;