mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 15:48:16 -05:00
refactor: rename RootConfig
to CliOptions
(#15007)
This commit is contained in:
parent
1328a56230
commit
8c4420c005
12 changed files with 138 additions and 132 deletions
|
@ -44,16 +44,16 @@ use crate::file_fetcher::CacheSetting;
|
||||||
use crate::lockfile::Lockfile;
|
use crate::lockfile::Lockfile;
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
/// Holds the common configuration used by many sub commands
|
/// Holds the common options used by many sub commands
|
||||||
/// and provides some helper function for creating common objects.
|
/// and provides some helper function for creating common objects.
|
||||||
pub struct RootConfig {
|
pub struct CliOptions {
|
||||||
// the source of the configuration is a detail the rest of the
|
// the source of the options is a detail the rest of the
|
||||||
// application need not concern itself with, so keep these private
|
// application need not concern itself with, so keep these private
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
maybe_config_file: Option<ConfigFile>,
|
maybe_config_file: Option<ConfigFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootConfig {
|
impl CliOptions {
|
||||||
pub fn from_flags(flags: Flags) -> Result<Self, AnyError> {
|
pub fn from_flags(flags: Flags) -> Result<Self, AnyError> {
|
||||||
if let Some(insecure_allowlist) =
|
if let Some(insecure_allowlist) =
|
||||||
flags.unsafely_ignore_certificate_errors.as_ref()
|
flags.unsafely_ignore_certificate_errors.as_ref()
|
||||||
|
|
|
@ -315,7 +315,7 @@ impl TestRun {
|
||||||
let flags = flags_from_vec(args.into_iter().map(String::from).collect())?;
|
let flags = flags_from_vec(args.into_iter().map(String::from).collect())?;
|
||||||
let ps = proc_state::ProcState::build(flags).await?;
|
let ps = proc_state::ProcState::build(flags).await?;
|
||||||
let permissions =
|
let permissions =
|
||||||
Permissions::from_options(&ps.config.permissions_options());
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
test::check_specifiers(
|
test::check_specifiers(
|
||||||
&ps,
|
&ps,
|
||||||
permissions.clone(),
|
permissions.clone(),
|
||||||
|
@ -331,7 +331,7 @@ impl TestRun {
|
||||||
let sender = TestEventSender::new(sender);
|
let sender = TestEventSender::new(sender);
|
||||||
|
|
||||||
let (concurrent_jobs, fail_fast) =
|
let (concurrent_jobs, fail_fast) =
|
||||||
if let DenoSubcommand::Test(test_flags) = ps.config.sub_command() {
|
if let DenoSubcommand::Test(test_flags) = ps.options.sub_command() {
|
||||||
(
|
(
|
||||||
test_flags.concurrent_jobs.into(),
|
test_flags.concurrent_jobs.into(),
|
||||||
test_flags.fail_fast.map(|count| count.into()),
|
test_flags.fail_fast.map(|count| count.into()),
|
||||||
|
|
96
cli/main.rs
96
cli/main.rs
|
@ -70,7 +70,7 @@ use crate::proc_state::ProcState;
|
||||||
use crate::resolver::ImportMapResolver;
|
use crate::resolver::ImportMapResolver;
|
||||||
use crate::resolver::JsxResolver;
|
use crate::resolver::JsxResolver;
|
||||||
|
|
||||||
use args::RootConfig;
|
use args::CliOptions;
|
||||||
use deno_ast::MediaType;
|
use deno_ast::MediaType;
|
||||||
use deno_core::error::generic_error;
|
use deno_core::error::generic_error;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
|
@ -109,7 +109,7 @@ use std::sync::Arc;
|
||||||
fn create_web_worker_preload_module_callback(
|
fn create_web_worker_preload_module_callback(
|
||||||
ps: ProcState,
|
ps: ProcState,
|
||||||
) -> Arc<PreloadModuleCb> {
|
) -> Arc<PreloadModuleCb> {
|
||||||
let compat = ps.config.compat();
|
let compat = ps.options.compat();
|
||||||
|
|
||||||
Arc::new(move |mut worker| {
|
Arc::new(move |mut worker| {
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
|
@ -144,30 +144,30 @@ fn create_web_worker_callback(
|
||||||
|
|
||||||
let options = WebWorkerOptions {
|
let options = WebWorkerOptions {
|
||||||
bootstrap: BootstrapOptions {
|
bootstrap: BootstrapOptions {
|
||||||
args: ps.config.argv().clone(),
|
args: ps.options.argv().clone(),
|
||||||
cpu_count: std::thread::available_parallelism()
|
cpu_count: std::thread::available_parallelism()
|
||||||
.map(|p| p.get())
|
.map(|p| p.get())
|
||||||
.unwrap_or(1),
|
.unwrap_or(1),
|
||||||
debug_flag: ps
|
debug_flag: ps
|
||||||
.config
|
.options
|
||||||
.log_level()
|
.log_level()
|
||||||
.map_or(false, |l| l == log::Level::Debug),
|
.map_or(false, |l| l == log::Level::Debug),
|
||||||
enable_testing_features: ps.config.enable_testing_features(),
|
enable_testing_features: ps.options.enable_testing_features(),
|
||||||
location: Some(args.main_module.clone()),
|
location: Some(args.main_module.clone()),
|
||||||
no_color: !colors::use_color(),
|
no_color: !colors::use_color(),
|
||||||
is_tty: colors::is_tty(),
|
is_tty: colors::is_tty(),
|
||||||
runtime_version: version::deno(),
|
runtime_version: version::deno(),
|
||||||
ts_version: version::TYPESCRIPT.to_string(),
|
ts_version: version::TYPESCRIPT.to_string(),
|
||||||
unstable: ps.config.unstable(),
|
unstable: ps.options.unstable(),
|
||||||
user_agent: version::get_user_agent(),
|
user_agent: version::get_user_agent(),
|
||||||
},
|
},
|
||||||
extensions,
|
extensions,
|
||||||
unsafely_ignore_certificate_errors: ps
|
unsafely_ignore_certificate_errors: ps
|
||||||
.config
|
.options
|
||||||
.unsafely_ignore_certificate_errors()
|
.unsafely_ignore_certificate_errors()
|
||||||
.map(ToOwned::to_owned),
|
.map(ToOwned::to_owned),
|
||||||
root_cert_store: Some(ps.root_cert_store.clone()),
|
root_cert_store: Some(ps.root_cert_store.clone()),
|
||||||
seed: ps.config.seed(),
|
seed: ps.options.seed(),
|
||||||
module_loader,
|
module_loader,
|
||||||
create_web_worker_cb,
|
create_web_worker_cb,
|
||||||
preload_module_cb,
|
preload_module_cb,
|
||||||
|
@ -204,14 +204,14 @@ pub fn create_main_worker(
|
||||||
let module_loader = CliModuleLoader::new(ps.clone());
|
let module_loader = CliModuleLoader::new(ps.clone());
|
||||||
|
|
||||||
let maybe_inspector_server = ps.maybe_inspector_server.clone();
|
let maybe_inspector_server = ps.maybe_inspector_server.clone();
|
||||||
let should_break_on_first_statement = ps.config.inspect_brk().is_some();
|
let should_break_on_first_statement = ps.options.inspect_brk().is_some();
|
||||||
|
|
||||||
let create_web_worker_cb =
|
let create_web_worker_cb =
|
||||||
create_web_worker_callback(ps.clone(), stdio.clone());
|
create_web_worker_callback(ps.clone(), stdio.clone());
|
||||||
let web_worker_preload_module_cb =
|
let web_worker_preload_module_cb =
|
||||||
create_web_worker_preload_module_callback(ps.clone());
|
create_web_worker_preload_module_callback(ps.clone());
|
||||||
|
|
||||||
let maybe_storage_key = ps.config.resolve_storage_key(&main_module);
|
let maybe_storage_key = ps.options.resolve_storage_key(&main_module);
|
||||||
let origin_storage_dir = maybe_storage_key.map(|key| {
|
let origin_storage_dir = maybe_storage_key.map(|key| {
|
||||||
ps.dir
|
ps.dir
|
||||||
.root
|
.root
|
||||||
|
@ -225,30 +225,30 @@ pub fn create_main_worker(
|
||||||
|
|
||||||
let options = WorkerOptions {
|
let options = WorkerOptions {
|
||||||
bootstrap: BootstrapOptions {
|
bootstrap: BootstrapOptions {
|
||||||
args: ps.config.argv().clone(),
|
args: ps.options.argv().clone(),
|
||||||
cpu_count: std::thread::available_parallelism()
|
cpu_count: std::thread::available_parallelism()
|
||||||
.map(|p| p.get())
|
.map(|p| p.get())
|
||||||
.unwrap_or(1),
|
.unwrap_or(1),
|
||||||
debug_flag: ps
|
debug_flag: ps
|
||||||
.config
|
.options
|
||||||
.log_level()
|
.log_level()
|
||||||
.map_or(false, |l| l == log::Level::Debug),
|
.map_or(false, |l| l == log::Level::Debug),
|
||||||
enable_testing_features: ps.config.enable_testing_features(),
|
enable_testing_features: ps.options.enable_testing_features(),
|
||||||
location: ps.config.location_flag().map(ToOwned::to_owned),
|
location: ps.options.location_flag().map(ToOwned::to_owned),
|
||||||
no_color: !colors::use_color(),
|
no_color: !colors::use_color(),
|
||||||
is_tty: colors::is_tty(),
|
is_tty: colors::is_tty(),
|
||||||
runtime_version: version::deno(),
|
runtime_version: version::deno(),
|
||||||
ts_version: version::TYPESCRIPT.to_string(),
|
ts_version: version::TYPESCRIPT.to_string(),
|
||||||
unstable: ps.config.unstable(),
|
unstable: ps.options.unstable(),
|
||||||
user_agent: version::get_user_agent(),
|
user_agent: version::get_user_agent(),
|
||||||
},
|
},
|
||||||
extensions,
|
extensions,
|
||||||
unsafely_ignore_certificate_errors: ps
|
unsafely_ignore_certificate_errors: ps
|
||||||
.config
|
.options
|
||||||
.unsafely_ignore_certificate_errors()
|
.unsafely_ignore_certificate_errors()
|
||||||
.map(ToOwned::to_owned),
|
.map(ToOwned::to_owned),
|
||||||
root_cert_store: Some(ps.root_cert_store.clone()),
|
root_cert_store: Some(ps.root_cert_store.clone()),
|
||||||
seed: ps.config.seed(),
|
seed: ps.options.seed(),
|
||||||
source_map_getter: Some(Box::new(ps.clone())),
|
source_map_getter: Some(Box::new(ps.clone())),
|
||||||
format_js_error_fn: Some(Arc::new(format_js_error)),
|
format_js_error_fn: Some(Arc::new(format_js_error)),
|
||||||
create_web_worker_cb,
|
create_web_worker_cb,
|
||||||
|
@ -460,7 +460,7 @@ async fn info_command(
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = ps
|
let maybe_jsx_resolver = ps
|
||||||
.config
|
.options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
||||||
|
@ -489,7 +489,7 @@ async fn info_command(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If it was just "deno info" print location of caches and exit
|
// If it was just "deno info" print location of caches and exit
|
||||||
print_cache_info(&ps, info_flags.json, ps.config.location_flag())?;
|
print_cache_info(&ps, info_flags.json, ps.options.location_flag())?;
|
||||||
}
|
}
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,7 @@ async fn cache_command(
|
||||||
cache_flags: CacheFlags,
|
cache_flags: CacheFlags,
|
||||||
) -> Result<i32, AnyError> {
|
) -> Result<i32, AnyError> {
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let lib = ps.config.ts_type_lib_window();
|
let lib = ps.options.ts_type_lib_window();
|
||||||
|
|
||||||
for file in cache_flags.files {
|
for file in cache_flags.files {
|
||||||
let specifier = resolve_url_or_path(&file)?;
|
let specifier = resolve_url_or_path(&file)?;
|
||||||
|
@ -617,7 +617,7 @@ async fn eval_command(
|
||||||
// to allow module access by TS compiler.
|
// to allow module access by TS compiler.
|
||||||
ps.file_fetcher.insert_cached(file);
|
ps.file_fetcher.insert_cached(file);
|
||||||
debug!("main_module {}", &main_module);
|
debug!("main_module {}", &main_module);
|
||||||
if ps.config.compat() {
|
if ps.options.compat() {
|
||||||
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
||||||
}
|
}
|
||||||
worker.execute_main_module(&main_module).await?;
|
worker.execute_main_module(&main_module).await?;
|
||||||
|
@ -645,11 +645,11 @@ async fn create_graph_and_maybe_check(
|
||||||
Permissions::allow_all(),
|
Permissions::allow_all(),
|
||||||
);
|
);
|
||||||
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
||||||
let maybe_imports = ps.config.to_maybe_imports()?;
|
let maybe_imports = ps.options.to_maybe_imports()?;
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = ps
|
let maybe_jsx_resolver = ps
|
||||||
.config
|
.options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
||||||
|
@ -673,36 +673,36 @@ async fn create_graph_and_maybe_check(
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
|
|
||||||
let check_js = ps.config.check_js();
|
let check_js = ps.options.check_js();
|
||||||
graph_valid(
|
graph_valid(
|
||||||
&graph,
|
&graph,
|
||||||
ps.config.type_check_mode() != TypeCheckMode::None,
|
ps.options.type_check_mode() != TypeCheckMode::None,
|
||||||
check_js,
|
check_js,
|
||||||
)?;
|
)?;
|
||||||
graph_lock_or_exit(&graph);
|
graph_lock_or_exit(&graph);
|
||||||
|
|
||||||
if ps.config.type_check_mode() != TypeCheckMode::None {
|
if ps.options.type_check_mode() != TypeCheckMode::None {
|
||||||
let ts_config_result =
|
let ts_config_result =
|
||||||
ps.config.resolve_ts_config_for_emit(TsConfigType::Check {
|
ps.options.resolve_ts_config_for_emit(TsConfigType::Check {
|
||||||
tsc_emit: false,
|
tsc_emit: false,
|
||||||
lib: ps.config.ts_type_lib_window(),
|
lib: ps.options.ts_type_lib_window(),
|
||||||
})?;
|
})?;
|
||||||
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
||||||
eprintln!("{}", ignored_options);
|
eprintln!("{}", ignored_options);
|
||||||
}
|
}
|
||||||
let maybe_config_specifier = ps.config.maybe_config_file_specifier();
|
let maybe_config_specifier = ps.options.maybe_config_file_specifier();
|
||||||
let check_result = emit::check_and_maybe_emit(
|
let check_result = emit::check_and_maybe_emit(
|
||||||
&graph.roots,
|
&graph.roots,
|
||||||
Arc::new(RwLock::new(graph.as_ref().into())),
|
Arc::new(RwLock::new(graph.as_ref().into())),
|
||||||
&ps.dir.gen_cache,
|
&ps.dir.gen_cache,
|
||||||
emit::CheckOptions {
|
emit::CheckOptions {
|
||||||
type_check_mode: ps.config.type_check_mode(),
|
type_check_mode: ps.options.type_check_mode(),
|
||||||
debug,
|
debug,
|
||||||
emit_with_diagnostics: false,
|
emit_with_diagnostics: false,
|
||||||
maybe_config_specifier,
|
maybe_config_specifier,
|
||||||
ts_config: ts_config_result.ts_config,
|
ts_config: ts_config_result.ts_config,
|
||||||
log_checks: true,
|
log_checks: true,
|
||||||
reload: ps.config.reload_flag(),
|
reload: ps.options.reload_flag(),
|
||||||
reload_exclusions: Default::default(),
|
reload_exclusions: Default::default(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
@ -721,9 +721,10 @@ fn bundle_module_graph(
|
||||||
) -> Result<deno_emit::BundleEmit, AnyError> {
|
) -> Result<deno_emit::BundleEmit, AnyError> {
|
||||||
info!("{} {}", colors::green("Bundle"), graph.roots[0].0);
|
info!("{} {}", colors::green("Bundle"), graph.roots[0].0);
|
||||||
|
|
||||||
let ts_config_result =
|
let ts_config_result = ps
|
||||||
ps.config.resolve_ts_config_for_emit(TsConfigType::Bundle)?;
|
.options
|
||||||
if ps.config.type_check_mode() == TypeCheckMode::None {
|
.resolve_ts_config_for_emit(TsConfigType::Bundle)?;
|
||||||
|
if ps.options.type_check_mode() == TypeCheckMode::None {
|
||||||
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
||||||
eprintln!("{}", ignored_options);
|
eprintln!("{}", ignored_options);
|
||||||
}
|
}
|
||||||
|
@ -744,16 +745,16 @@ async fn bundle_command(
|
||||||
bundle_flags: BundleFlags,
|
bundle_flags: BundleFlags,
|
||||||
) -> Result<i32, AnyError> {
|
) -> Result<i32, AnyError> {
|
||||||
let debug = flags.log_level == Some(log::Level::Debug);
|
let debug = flags.log_level == Some(log::Level::Debug);
|
||||||
let root_config = Arc::new(RootConfig::from_flags(flags)?);
|
let cli_options = Arc::new(CliOptions::from_flags(flags)?);
|
||||||
let resolver = |_| {
|
let resolver = |_| {
|
||||||
let root_config = root_config.clone();
|
let cli_options = cli_options.clone();
|
||||||
let source_file1 = bundle_flags.source_file.clone();
|
let source_file1 = bundle_flags.source_file.clone();
|
||||||
let source_file2 = bundle_flags.source_file.clone();
|
let source_file2 = bundle_flags.source_file.clone();
|
||||||
async move {
|
async move {
|
||||||
let module_specifier = resolve_url_or_path(&source_file1)?;
|
let module_specifier = resolve_url_or_path(&source_file1)?;
|
||||||
|
|
||||||
debug!(">>>>> bundle START");
|
debug!(">>>>> bundle START");
|
||||||
let ps = ProcState::from_root_config(root_config).await?;
|
let ps = ProcState::from_options(cli_options).await?;
|
||||||
|
|
||||||
let graph =
|
let graph =
|
||||||
create_graph_and_maybe_check(module_specifier, &ps, debug).await?;
|
create_graph_and_maybe_check(module_specifier, &ps, debug).await?;
|
||||||
|
@ -767,7 +768,7 @@ async fn bundle_command(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let Ok(Some(import_map_path)) = ps
|
if let Ok(Some(import_map_path)) = ps
|
||||||
.config
|
.options
|
||||||
.resolve_import_map_path()
|
.resolve_import_map_path()
|
||||||
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
|
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
|
||||||
{
|
{
|
||||||
|
@ -829,13 +830,13 @@ async fn bundle_command(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if root_config.watch_paths().is_some() {
|
if cli_options.watch_paths().is_some() {
|
||||||
file_watcher::watch_func(
|
file_watcher::watch_func(
|
||||||
resolver,
|
resolver,
|
||||||
operation,
|
operation,
|
||||||
file_watcher::PrintConfig {
|
file_watcher::PrintConfig {
|
||||||
job_name: "Bundle".to_string(),
|
job_name: "Bundle".to_string(),
|
||||||
clear_screen: !root_config.no_clear_screen(),
|
clear_screen: !cli_options.no_clear_screen(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -864,7 +865,7 @@ async fn format_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
fmt_flags: FmtFlags,
|
fmt_flags: FmtFlags,
|
||||||
) -> Result<i32, AnyError> {
|
) -> Result<i32, AnyError> {
|
||||||
let config = RootConfig::from_flags(flags)?;
|
let config = CliOptions::from_flags(flags)?;
|
||||||
|
|
||||||
if fmt_flags.files.len() == 1 && fmt_flags.files[0].to_string_lossy() == "-" {
|
if fmt_flags.files.len() == 1 && fmt_flags.files[0].to_string_lossy() == "-" {
|
||||||
let maybe_fmt_config = config.to_fmt_config()?;
|
let maybe_fmt_config = config.to_fmt_config()?;
|
||||||
|
@ -888,11 +889,11 @@ async fn repl_command(
|
||||||
let mut worker = create_main_worker(
|
let mut worker = create_main_worker(
|
||||||
&ps,
|
&ps,
|
||||||
main_module.clone(),
|
main_module.clone(),
|
||||||
Permissions::from_options(&ps.config.permissions_options()),
|
Permissions::from_options(&ps.options.permissions_options()),
|
||||||
vec![],
|
vec![],
|
||||||
Default::default(),
|
Default::default(),
|
||||||
);
|
);
|
||||||
if ps.config.compat() {
|
if ps.options.compat() {
|
||||||
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
||||||
compat::add_global_require(&mut worker.js_runtime, main_module.as_str())?;
|
compat::add_global_require(&mut worker.js_runtime, main_module.as_str())?;
|
||||||
worker.run_event_loop(false).await?;
|
worker.run_event_loop(false).await?;
|
||||||
|
@ -909,7 +910,7 @@ async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
|
||||||
let mut worker = create_main_worker(
|
let mut worker = create_main_worker(
|
||||||
&ps.clone(),
|
&ps.clone(),
|
||||||
main_module.clone(),
|
main_module.clone(),
|
||||||
Permissions::from_options(&ps.config.permissions_options()),
|
Permissions::from_options(&ps.options.permissions_options()),
|
||||||
vec![],
|
vec![],
|
||||||
Default::default(),
|
Default::default(),
|
||||||
);
|
);
|
||||||
|
@ -930,7 +931,7 @@ async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
|
||||||
ps.file_fetcher.insert_cached(source_file);
|
ps.file_fetcher.insert_cached(source_file);
|
||||||
|
|
||||||
debug!("main_module {}", main_module);
|
debug!("main_module {}", main_module);
|
||||||
if ps.config.compat() {
|
if ps.options.compat() {
|
||||||
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
worker.execute_side_module(&compat::GLOBAL_URL).await?;
|
||||||
}
|
}
|
||||||
worker.execute_main_module(&main_module).await?;
|
worker.execute_main_module(&main_module).await?;
|
||||||
|
@ -1078,7 +1079,8 @@ async fn run_command(
|
||||||
// probably call `ProcState::resolve` instead
|
// probably call `ProcState::resolve` instead
|
||||||
let main_module = resolve_url_or_path(&run_flags.script)?;
|
let main_module = resolve_url_or_path(&run_flags.script)?;
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions = Permissions::from_options(&ps.config.permissions_options());
|
let permissions =
|
||||||
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
let mut worker = create_main_worker(
|
let mut worker = create_main_worker(
|
||||||
&ps,
|
&ps,
|
||||||
main_module.clone(),
|
main_module.clone(),
|
||||||
|
@ -1104,7 +1106,7 @@ async fn run_command(
|
||||||
|
|
||||||
debug!("main_module {}", main_module);
|
debug!("main_module {}", main_module);
|
||||||
|
|
||||||
if ps.config.compat() {
|
if ps.options.compat() {
|
||||||
// TODO(bartlomieju): fix me
|
// TODO(bartlomieju): fix me
|
||||||
assert_eq!(main_module.scheme(), "file");
|
assert_eq!(main_module.scheme(), "file");
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct CliModuleLoader {
|
||||||
impl CliModuleLoader {
|
impl CliModuleLoader {
|
||||||
pub fn new(ps: ProcState) -> Rc<Self> {
|
pub fn new(ps: ProcState) -> Rc<Self> {
|
||||||
Rc::new(CliModuleLoader {
|
Rc::new(CliModuleLoader {
|
||||||
lib: ps.config.ts_type_lib_window(),
|
lib: ps.options.ts_type_lib_window(),
|
||||||
root_permissions: Permissions::allow_all(),
|
root_permissions: Permissions::allow_all(),
|
||||||
ps,
|
ps,
|
||||||
})
|
})
|
||||||
|
@ -35,7 +35,7 @@ impl CliModuleLoader {
|
||||||
|
|
||||||
pub fn new_for_worker(ps: ProcState, permissions: Permissions) -> Rc<Self> {
|
pub fn new_for_worker(ps: ProcState, permissions: Permissions) -> Rc<Self> {
|
||||||
Rc::new(CliModuleLoader {
|
Rc::new(CliModuleLoader {
|
||||||
lib: ps.config.ts_type_lib_worker(),
|
lib: ps.options.ts_type_lib_worker(),
|
||||||
root_permissions: permissions,
|
root_permissions: permissions,
|
||||||
ps,
|
ps,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use crate::args::CliOptions;
|
||||||
use crate::args::DenoSubcommand;
|
use crate::args::DenoSubcommand;
|
||||||
use crate::args::Flags;
|
use crate::args::Flags;
|
||||||
use crate::args::RootConfig;
|
|
||||||
use crate::args::TypeCheckMode;
|
use crate::args::TypeCheckMode;
|
||||||
use crate::cache;
|
use crate::cache;
|
||||||
use crate::compat;
|
use crate::compat;
|
||||||
|
@ -68,7 +68,7 @@ pub struct Inner {
|
||||||
pub dir: deno_dir::DenoDir,
|
pub dir: deno_dir::DenoDir,
|
||||||
pub coverage_dir: Option<String>,
|
pub coverage_dir: Option<String>,
|
||||||
pub file_fetcher: FileFetcher,
|
pub file_fetcher: FileFetcher,
|
||||||
pub config: Arc<RootConfig>,
|
pub options: Arc<CliOptions>,
|
||||||
graph_data: Arc<RwLock<GraphData>>,
|
graph_data: Arc<RwLock<GraphData>>,
|
||||||
pub lockfile: Option<Arc<Mutex<Lockfile>>>,
|
pub lockfile: Option<Arc<Mutex<Lockfile>>>,
|
||||||
pub maybe_import_map: Option<Arc<ImportMap>>,
|
pub maybe_import_map: Option<Arc<ImportMap>>,
|
||||||
|
@ -91,13 +91,13 @@ impl Deref for ProcState {
|
||||||
|
|
||||||
impl ProcState {
|
impl ProcState {
|
||||||
pub async fn build(flags: Flags) -> Result<Self, AnyError> {
|
pub async fn build(flags: Flags) -> Result<Self, AnyError> {
|
||||||
Self::from_root_config(Arc::new(RootConfig::from_flags(flags)?)).await
|
Self::from_options(Arc::new(CliOptions::from_flags(flags)?)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn from_root_config(
|
pub async fn from_options(
|
||||||
root_config: Arc<RootConfig>,
|
options: Arc<CliOptions>,
|
||||||
) -> Result<Self, AnyError> {
|
) -> Result<Self, AnyError> {
|
||||||
Self::build_with_sender(root_config, None).await
|
Self::build_with_sender(options, None).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_for_file_watcher(
|
pub async fn build_for_file_watcher(
|
||||||
|
@ -105,18 +105,18 @@ impl ProcState {
|
||||||
files_to_watch_sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>,
|
files_to_watch_sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>,
|
||||||
) -> Result<Self, AnyError> {
|
) -> Result<Self, AnyError> {
|
||||||
// resolve the config each time
|
// resolve the config each time
|
||||||
let root_config = Arc::new(RootConfig::from_flags(flags)?);
|
let cli_options = Arc::new(CliOptions::from_flags(flags)?);
|
||||||
let ps =
|
let ps =
|
||||||
Self::build_with_sender(root_config, Some(files_to_watch_sender.clone()))
|
Self::build_with_sender(cli_options, Some(files_to_watch_sender.clone()))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Add the extra files listed in the watch flag
|
// Add the extra files listed in the watch flag
|
||||||
if let Some(watch_paths) = ps.config.watch_paths() {
|
if let Some(watch_paths) = ps.options.watch_paths() {
|
||||||
files_to_watch_sender.send(watch_paths.clone()).unwrap();
|
files_to_watch_sender.send(watch_paths.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(Some(import_map_path)) = ps
|
if let Ok(Some(import_map_path)) = ps
|
||||||
.config
|
.options
|
||||||
.resolve_import_map_path()
|
.resolve_import_map_path()
|
||||||
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
|
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
|
||||||
{
|
{
|
||||||
|
@ -127,33 +127,33 @@ impl ProcState {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn build_with_sender(
|
async fn build_with_sender(
|
||||||
root_config: Arc<RootConfig>,
|
cli_options: Arc<CliOptions>,
|
||||||
maybe_sender: Option<tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>>,
|
maybe_sender: Option<tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>>,
|
||||||
) -> Result<Self, AnyError> {
|
) -> Result<Self, AnyError> {
|
||||||
let blob_store = BlobStore::default();
|
let blob_store = BlobStore::default();
|
||||||
let broadcast_channel = InMemoryBroadcastChannel::default();
|
let broadcast_channel = InMemoryBroadcastChannel::default();
|
||||||
let shared_array_buffer_store = SharedArrayBufferStore::default();
|
let shared_array_buffer_store = SharedArrayBufferStore::default();
|
||||||
let compiled_wasm_module_store = CompiledWasmModuleStore::default();
|
let compiled_wasm_module_store = CompiledWasmModuleStore::default();
|
||||||
let dir = root_config.resolve_deno_dir()?;
|
let dir = cli_options.resolve_deno_dir()?;
|
||||||
let deps_cache_location = dir.root.join("deps");
|
let deps_cache_location = dir.root.join("deps");
|
||||||
let http_cache = http_cache::HttpCache::new(&deps_cache_location);
|
let http_cache = http_cache::HttpCache::new(&deps_cache_location);
|
||||||
let root_cert_store = root_config.resolve_root_cert_store()?;
|
let root_cert_store = cli_options.resolve_root_cert_store()?;
|
||||||
let cache_usage = root_config.cache_setting();
|
let cache_usage = cli_options.cache_setting();
|
||||||
let file_fetcher = FileFetcher::new(
|
let file_fetcher = FileFetcher::new(
|
||||||
http_cache,
|
http_cache,
|
||||||
cache_usage,
|
cache_usage,
|
||||||
!root_config.no_remote(),
|
!cli_options.no_remote(),
|
||||||
Some(root_cert_store.clone()),
|
Some(root_cert_store.clone()),
|
||||||
blob_store.clone(),
|
blob_store.clone(),
|
||||||
root_config
|
cli_options
|
||||||
.unsafely_ignore_certificate_errors()
|
.unsafely_ignore_certificate_errors()
|
||||||
.map(ToOwned::to_owned),
|
.map(ToOwned::to_owned),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let lockfile = root_config
|
let lockfile = cli_options
|
||||||
.resolve_lock_file()?
|
.resolve_lock_file()?
|
||||||
.map(|f| Arc::new(Mutex::new(f)));
|
.map(|f| Arc::new(Mutex::new(f)));
|
||||||
let maybe_import_map_specifier = root_config.resolve_import_map_path()?;
|
let maybe_import_map_specifier = cli_options.resolve_import_map_path()?;
|
||||||
|
|
||||||
let maybe_import_map =
|
let maybe_import_map =
|
||||||
if let Some(import_map_specifier) = maybe_import_map_specifier {
|
if let Some(import_map_specifier) = maybe_import_map_specifier {
|
||||||
|
@ -172,9 +172,9 @@ impl ProcState {
|
||||||
};
|
};
|
||||||
|
|
||||||
let maybe_inspector_server =
|
let maybe_inspector_server =
|
||||||
root_config.resolve_inspector_server().map(Arc::new);
|
cli_options.resolve_inspector_server().map(Arc::new);
|
||||||
|
|
||||||
let coverage_dir = root_config
|
let coverage_dir = cli_options
|
||||||
.coverage_dir()
|
.coverage_dir()
|
||||||
.map(ToOwned::to_owned)
|
.map(ToOwned::to_owned)
|
||||||
.or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok());
|
.or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok());
|
||||||
|
@ -186,12 +186,12 @@ impl ProcState {
|
||||||
);
|
);
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
maybe_import_map.clone().map(ImportMapResolver::new);
|
maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = root_config
|
let maybe_jsx_resolver = cli_options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_resolver: Option<
|
let maybe_resolver: Option<
|
||||||
Arc<dyn deno_graph::source::Resolver + Send + Sync>,
|
Arc<dyn deno_graph::source::Resolver + Send + Sync>,
|
||||||
> = if root_config.compat() {
|
> = if cli_options.compat() {
|
||||||
Some(Arc::new(node_resolver))
|
Some(Arc::new(node_resolver))
|
||||||
} else if let Some(jsx_resolver) = maybe_jsx_resolver {
|
} else if let Some(jsx_resolver) = maybe_jsx_resolver {
|
||||||
// the JSX resolver offloads to the import map if present, otherwise uses
|
// the JSX resolver offloads to the import map if present, otherwise uses
|
||||||
|
@ -212,7 +212,7 @@ impl ProcState {
|
||||||
Ok(ProcState(Arc::new(Inner {
|
Ok(ProcState(Arc::new(Inner {
|
||||||
dir,
|
dir,
|
||||||
coverage_dir,
|
coverage_dir,
|
||||||
config: root_config,
|
options: cli_options,
|
||||||
file_fetcher,
|
file_fetcher,
|
||||||
graph_data: Default::default(),
|
graph_data: Default::default(),
|
||||||
lockfile,
|
lockfile,
|
||||||
|
@ -276,7 +276,7 @@ impl ProcState {
|
||||||
|
|
||||||
// TODO(bartlomieju): this is very make-shift, is there an existing API
|
// TODO(bartlomieju): this is very make-shift, is there an existing API
|
||||||
// that we could include it like with "maybe_imports"?
|
// that we could include it like with "maybe_imports"?
|
||||||
let roots = if self.config.compat() {
|
let roots = if self.options.compat() {
|
||||||
let mut r = vec![(compat::GLOBAL_URL.clone(), ModuleKind::Esm)];
|
let mut r = vec![(compat::GLOBAL_URL.clone(), ModuleKind::Esm)];
|
||||||
r.extend(roots);
|
r.extend(roots);
|
||||||
r
|
r
|
||||||
|
@ -285,12 +285,12 @@ impl ProcState {
|
||||||
};
|
};
|
||||||
if !reload_on_watch {
|
if !reload_on_watch {
|
||||||
let graph_data = self.graph_data.read();
|
let graph_data = self.graph_data.read();
|
||||||
if self.config.type_check_mode() == TypeCheckMode::None
|
if self.options.type_check_mode() == TypeCheckMode::None
|
||||||
|| graph_data.is_type_checked(&roots, &lib)
|
|| graph_data.is_type_checked(&roots, &lib)
|
||||||
{
|
{
|
||||||
if let Some(result) = graph_data.check(
|
if let Some(result) = graph_data.check(
|
||||||
&roots,
|
&roots,
|
||||||
self.config.type_check_mode() != TypeCheckMode::None,
|
self.options.type_check_mode() != TypeCheckMode::None,
|
||||||
false,
|
false,
|
||||||
) {
|
) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -304,7 +304,7 @@ impl ProcState {
|
||||||
dynamic_permissions.clone(),
|
dynamic_permissions.clone(),
|
||||||
);
|
);
|
||||||
let maybe_locker = as_maybe_locker(self.lockfile.clone());
|
let maybe_locker = as_maybe_locker(self.lockfile.clone());
|
||||||
let maybe_imports = self.config.to_maybe_imports()?;
|
let maybe_imports = self.options.to_maybe_imports()?;
|
||||||
|
|
||||||
struct ProcStateLoader<'a> {
|
struct ProcStateLoader<'a> {
|
||||||
inner: &'a mut cache::FetchCacher,
|
inner: &'a mut cache::FetchCacher,
|
||||||
|
@ -399,17 +399,17 @@ impl ProcState {
|
||||||
{
|
{
|
||||||
let mut graph_data = self.graph_data.write();
|
let mut graph_data = self.graph_data.write();
|
||||||
graph_data.add_graph(&graph, reload_on_watch);
|
graph_data.add_graph(&graph, reload_on_watch);
|
||||||
let check_js = self.config.check_js();
|
let check_js = self.options.check_js();
|
||||||
graph_data
|
graph_data
|
||||||
.check(
|
.check(
|
||||||
&roots,
|
&roots,
|
||||||
self.config.type_check_mode() != TypeCheckMode::None,
|
self.options.type_check_mode() != TypeCheckMode::None,
|
||||||
check_js,
|
check_js,
|
||||||
)
|
)
|
||||||
.unwrap()?;
|
.unwrap()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_type = if self.config.type_check_mode() == TypeCheckMode::None {
|
let config_type = if self.options.type_check_mode() == TypeCheckMode::None {
|
||||||
TsConfigType::Emit
|
TsConfigType::Emit
|
||||||
} else {
|
} else {
|
||||||
TsConfigType::Check {
|
TsConfigType::Check {
|
||||||
|
@ -419,30 +419,30 @@ impl ProcState {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ts_config_result =
|
let ts_config_result =
|
||||||
self.config.resolve_ts_config_for_emit(config_type)?;
|
self.options.resolve_ts_config_for_emit(config_type)?;
|
||||||
|
|
||||||
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
||||||
log::warn!("{}", ignored_options);
|
log::warn!("{}", ignored_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config.type_check_mode() == TypeCheckMode::None {
|
if self.options.type_check_mode() == TypeCheckMode::None {
|
||||||
let options = emit::EmitOptions {
|
let options = emit::EmitOptions {
|
||||||
ts_config: ts_config_result.ts_config,
|
ts_config: ts_config_result.ts_config,
|
||||||
reload: self.config.reload_flag(),
|
reload: self.options.reload_flag(),
|
||||||
reload_exclusions,
|
reload_exclusions,
|
||||||
};
|
};
|
||||||
let emit_result = emit::emit(&graph, &self.dir.gen_cache, options)?;
|
let emit_result = emit::emit(&graph, &self.dir.gen_cache, options)?;
|
||||||
log::debug!("{}", emit_result.stats);
|
log::debug!("{}", emit_result.stats);
|
||||||
} else {
|
} else {
|
||||||
let maybe_config_specifier = self.config.maybe_config_file_specifier();
|
let maybe_config_specifier = self.options.maybe_config_file_specifier();
|
||||||
let options = emit::CheckOptions {
|
let options = emit::CheckOptions {
|
||||||
type_check_mode: self.config.type_check_mode(),
|
type_check_mode: self.options.type_check_mode(),
|
||||||
debug: self.config.log_level() == Some(log::Level::Debug),
|
debug: self.options.log_level() == Some(log::Level::Debug),
|
||||||
emit_with_diagnostics: false,
|
emit_with_diagnostics: false,
|
||||||
maybe_config_specifier,
|
maybe_config_specifier,
|
||||||
ts_config: ts_config_result.ts_config,
|
ts_config: ts_config_result.ts_config,
|
||||||
log_checks: true,
|
log_checks: true,
|
||||||
reload: self.config.reload_flag(),
|
reload: self.options.reload_flag(),
|
||||||
reload_exclusions,
|
reload_exclusions,
|
||||||
};
|
};
|
||||||
let emit_result = emit::check_and_maybe_emit(
|
let emit_result = emit::check_and_maybe_emit(
|
||||||
|
@ -457,7 +457,7 @@ impl ProcState {
|
||||||
log::debug!("{}", emit_result.stats);
|
log::debug!("{}", emit_result.stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config.type_check_mode() != TypeCheckMode::None {
|
if self.options.type_check_mode() != TypeCheckMode::None {
|
||||||
let mut graph_data = self.graph_data.write();
|
let mut graph_data = self.graph_data.write();
|
||||||
graph_data.set_type_checked(&roots, lib);
|
graph_data.set_type_checked(&roots, lib);
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,7 @@ impl ProcState {
|
||||||
// and `Deno.core.evalContext` API. Ideally we should always have a referrer filled
|
// and `Deno.core.evalContext` API. Ideally we should always have a referrer filled
|
||||||
// but sadly that's not the case due to missing APIs in V8.
|
// but sadly that's not the case due to missing APIs in V8.
|
||||||
let referrer = if referrer.is_empty()
|
let referrer = if referrer.is_empty()
|
||||||
&& matches!(self.config.sub_command(), DenoSubcommand::Repl(_))
|
&& matches!(self.options.sub_command(), DenoSubcommand::Repl(_))
|
||||||
{
|
{
|
||||||
deno_core::resolve_url_or_path("./$deno$repl.ts").unwrap()
|
deno_core::resolve_url_or_path("./$deno$repl.ts").unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -336,7 +336,7 @@ async fn check_specifiers(
|
||||||
permissions: Permissions,
|
permissions: Permissions,
|
||||||
specifiers: Vec<ModuleSpecifier>,
|
specifiers: Vec<ModuleSpecifier>,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let lib = ps.config.ts_type_lib_window();
|
let lib = ps.options.ts_type_lib_window();
|
||||||
ps.prepare_module_load(
|
ps.prepare_module_load(
|
||||||
specifiers,
|
specifiers,
|
||||||
false,
|
false,
|
||||||
|
@ -366,7 +366,7 @@ async fn bench_specifier(
|
||||||
vec![ops::bench::init(
|
vec![ops::bench::init(
|
||||||
channel.clone(),
|
channel.clone(),
|
||||||
filter,
|
filter,
|
||||||
ps.config.unstable(),
|
ps.options.unstable(),
|
||||||
)],
|
)],
|
||||||
Default::default(),
|
Default::default(),
|
||||||
);
|
);
|
||||||
|
@ -424,7 +424,7 @@ async fn bench_specifiers(
|
||||||
specifiers: Vec<ModuleSpecifier>,
|
specifiers: Vec<ModuleSpecifier>,
|
||||||
options: BenchSpecifierOptions,
|
options: BenchSpecifierOptions,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let log_level = ps.config.log_level();
|
let log_level = ps.options.log_level();
|
||||||
|
|
||||||
let (sender, mut receiver) = unbounded_channel::<BenchEvent>();
|
let (sender, mut receiver) = unbounded_channel::<BenchEvent>();
|
||||||
|
|
||||||
|
@ -527,7 +527,8 @@ pub async fn run_benchmarks(
|
||||||
bench_flags: BenchFlags,
|
bench_flags: BenchFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions = Permissions::from_options(&ps.config.permissions_options());
|
let permissions =
|
||||||
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
let specifiers = collect_specifiers(
|
let specifiers = collect_specifiers(
|
||||||
bench_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
bench_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
||||||
&bench_flags.ignore.clone(),
|
&bench_flags.ignore.clone(),
|
||||||
|
@ -540,7 +541,7 @@ pub async fn run_benchmarks(
|
||||||
|
|
||||||
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
|
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
|
||||||
|
|
||||||
let compat = ps.config.compat();
|
let compat = ps.options.compat();
|
||||||
bench_specifiers(
|
bench_specifiers(
|
||||||
ps,
|
ps,
|
||||||
permissions,
|
permissions,
|
||||||
|
@ -561,12 +562,13 @@ pub async fn run_benchmarks_with_watch(
|
||||||
bench_flags: BenchFlags,
|
bench_flags: BenchFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions = Permissions::from_options(&ps.config.permissions_options());
|
let permissions =
|
||||||
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
|
|
||||||
let include = bench_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
let include = bench_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
||||||
let ignore = bench_flags.ignore.clone();
|
let ignore = bench_flags.ignore.clone();
|
||||||
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
||||||
let no_check = ps.config.type_check_mode() == TypeCheckMode::None;
|
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
|
||||||
|
|
||||||
let resolver = |changed: Option<Vec<PathBuf>>| {
|
let resolver = |changed: Option<Vec<PathBuf>>| {
|
||||||
let mut cache = cache::FetchCacher::new(
|
let mut cache = cache::FetchCacher::new(
|
||||||
|
@ -582,15 +584,15 @@ pub async fn run_benchmarks_with_watch(
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = ps
|
let maybe_jsx_resolver = ps
|
||||||
.config
|
.options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
||||||
let maybe_imports_result = ps.config.to_maybe_imports();
|
let maybe_imports_result = ps.options.to_maybe_imports();
|
||||||
let files_changed = changed.is_some();
|
let files_changed = changed.is_some();
|
||||||
let include = include.clone();
|
let include = include.clone();
|
||||||
let ignore = ignore.clone();
|
let ignore = ignore.clone();
|
||||||
let check_js = ps.config.check_js();
|
let check_js = ps.options.check_js();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let bench_modules =
|
let bench_modules =
|
||||||
|
@ -734,7 +736,7 @@ pub async fn run_benchmarks_with_watch(
|
||||||
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
|
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
|
||||||
|
|
||||||
let specifier_options = BenchSpecifierOptions {
|
let specifier_options = BenchSpecifierOptions {
|
||||||
compat_mode: ps.config.compat(),
|
compat_mode: ps.options.compat(),
|
||||||
filter: filter.clone(),
|
filter: filter.clone(),
|
||||||
};
|
};
|
||||||
bench_specifiers(ps, permissions.clone(), specifiers, specifier_options)
|
bench_specifiers(ps, permissions.clone(), specifiers, specifier_options)
|
||||||
|
@ -749,7 +751,7 @@ pub async fn run_benchmarks_with_watch(
|
||||||
operation,
|
operation,
|
||||||
file_watcher::PrintConfig {
|
file_watcher::PrintConfig {
|
||||||
job_name: "Bench".to_string(),
|
job_name: "Bench".to_string(),
|
||||||
clear_screen: !ps.config.no_clear_screen(),
|
clear_screen: !ps.options.no_clear_screen(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub async fn print_docs(
|
||||||
doc_parser.parse_source(
|
doc_parser.parse_source(
|
||||||
&source_file_specifier,
|
&source_file_specifier,
|
||||||
MediaType::Dts,
|
MediaType::Dts,
|
||||||
get_types(ps.config.unstable()).into(),
|
get_types(ps.options.unstable()).into(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let module_specifier = resolve_url_or_path(&source_file)?;
|
let module_specifier = resolve_url_or_path(&source_file)?;
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
//! the future it can be easily extended to provide
|
//! the future it can be easily extended to provide
|
||||||
//! the same functions as ops available in JS runtime.
|
//! the same functions as ops available in JS runtime.
|
||||||
|
|
||||||
|
use crate::args::CliOptions;
|
||||||
use crate::args::FmtFlags;
|
use crate::args::FmtFlags;
|
||||||
use crate::args::FmtOptionsConfig;
|
use crate::args::FmtOptionsConfig;
|
||||||
use crate::args::ProseWrap;
|
use crate::args::ProseWrap;
|
||||||
use crate::args::RootConfig;
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::diff::diff;
|
use crate::diff::diff;
|
||||||
use crate::file_watcher;
|
use crate::file_watcher;
|
||||||
|
@ -43,7 +43,7 @@ use super::incremental_cache::IncrementalCache;
|
||||||
|
|
||||||
/// Format JavaScript/TypeScript files.
|
/// Format JavaScript/TypeScript files.
|
||||||
pub async fn format(
|
pub async fn format(
|
||||||
config: &RootConfig,
|
config: &CliOptions,
|
||||||
fmt_flags: FmtFlags,
|
fmt_flags: FmtFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let maybe_fmt_config = config.to_fmt_config()?;
|
let maybe_fmt_config = config.to_fmt_config()?;
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
|
||||||
let mut exclude_files = ignore.clone();
|
let mut exclude_files = ignore.clone();
|
||||||
|
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let maybe_lint_config = ps.config.to_lint_config()?;
|
let maybe_lint_config = ps.options.to_lint_config()?;
|
||||||
|
|
||||||
if let Some(lint_config) = maybe_lint_config.as_ref() {
|
if let Some(lint_config) = maybe_lint_config.as_ref() {
|
||||||
if include_files.is_empty() {
|
if include_files.is_empty() {
|
||||||
|
@ -202,7 +202,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
if ps.config.watch_paths().is_some() {
|
if ps.options.watch_paths().is_some() {
|
||||||
if args.len() == 1 && args[0].to_string_lossy() == "-" {
|
if args.len() == 1 && args[0].to_string_lossy() == "-" {
|
||||||
return Err(generic_error(
|
return Err(generic_error(
|
||||||
"Lint watch on standard input is not supported.",
|
"Lint watch on standard input is not supported.",
|
||||||
|
@ -213,7 +213,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
|
||||||
operation,
|
operation,
|
||||||
file_watcher::PrintConfig {
|
file_watcher::PrintConfig {
|
||||||
job_name: "Lint".to_string(),
|
job_name: "Lint".to_string(),
|
||||||
clear_screen: !ps.config.no_clear_screen(),
|
clear_screen: !ps.options.no_clear_screen(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -30,8 +30,8 @@ pub async fn execute_script(
|
||||||
crate::colors::yellow("Warning"),
|
crate::colors::yellow("Warning"),
|
||||||
);
|
);
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let tasks_config = ps.config.resolve_tasks_config()?;
|
let tasks_config = ps.options.resolve_tasks_config()?;
|
||||||
let config_file_url = ps.config.maybe_config_file_specifier().unwrap();
|
let config_file_url = ps.options.maybe_config_file_specifier().unwrap();
|
||||||
let config_file_path = if config_file_url.scheme() == "file" {
|
let config_file_path = if config_file_url.scheme() == "file" {
|
||||||
config_file_url.to_file_path().unwrap()
|
config_file_url.to_file_path().unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,7 +52,7 @@ pub async fn execute_script(
|
||||||
|
|
||||||
if let Some(script) = maybe_script {
|
if let Some(script) = maybe_script {
|
||||||
let additional_args = ps
|
let additional_args = ps
|
||||||
.config
|
.options
|
||||||
.argv()
|
.argv()
|
||||||
.iter()
|
.iter()
|
||||||
// surround all the additional arguments in double quotes
|
// surround all the additional arguments in double quotes
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ pub async fn check_specifiers(
|
||||||
permissions: Permissions,
|
permissions: Permissions,
|
||||||
specifiers: Vec<(ModuleSpecifier, TestMode)>,
|
specifiers: Vec<(ModuleSpecifier, TestMode)>,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let lib = ps.config.ts_type_lib_window();
|
let lib = ps.options.ts_type_lib_window();
|
||||||
let inline_files = fetch_inline_files(
|
let inline_files = fetch_inline_files(
|
||||||
ps.clone(),
|
ps.clone(),
|
||||||
specifiers
|
specifiers
|
||||||
|
@ -1088,7 +1088,7 @@ async fn test_specifiers(
|
||||||
specifiers_with_mode: Vec<(ModuleSpecifier, TestMode)>,
|
specifiers_with_mode: Vec<(ModuleSpecifier, TestMode)>,
|
||||||
options: TestSpecifierOptions,
|
options: TestSpecifierOptions,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let log_level = ps.config.log_level();
|
let log_level = ps.options.log_level();
|
||||||
let specifiers_with_mode = if let Some(seed) = options.shuffle {
|
let specifiers_with_mode = if let Some(seed) = options.shuffle {
|
||||||
let mut rng = SmallRng::seed_from_u64(seed);
|
let mut rng = SmallRng::seed_from_u64(seed);
|
||||||
let mut specifiers_with_mode = specifiers_with_mode.clone();
|
let mut specifiers_with_mode = specifiers_with_mode.clone();
|
||||||
|
@ -1333,7 +1333,8 @@ pub async fn run_tests(
|
||||||
test_flags: TestFlags,
|
test_flags: TestFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions = Permissions::from_options(&ps.config.permissions_options());
|
let permissions =
|
||||||
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
let specifiers_with_mode = fetch_specifiers_with_test_mode(
|
let specifiers_with_mode = fetch_specifiers_with_test_mode(
|
||||||
&ps,
|
&ps,
|
||||||
test_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
test_flags.include.unwrap_or_else(|| vec![".".to_string()]),
|
||||||
|
@ -1353,7 +1354,7 @@ pub async fn run_tests(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let compat = ps.config.compat();
|
let compat = ps.options.compat();
|
||||||
test_specifiers(
|
test_specifiers(
|
||||||
ps,
|
ps,
|
||||||
permissions,
|
permissions,
|
||||||
|
@ -1377,12 +1378,13 @@ pub async fn run_tests_with_watch(
|
||||||
test_flags: TestFlags,
|
test_flags: TestFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags).await?;
|
||||||
let permissions = Permissions::from_options(&ps.config.permissions_options());
|
let permissions =
|
||||||
|
Permissions::from_options(&ps.options.permissions_options());
|
||||||
|
|
||||||
let include = test_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
let include = test_flags.include.unwrap_or_else(|| vec![".".to_string()]);
|
||||||
let ignore = test_flags.ignore.clone();
|
let ignore = test_flags.ignore.clone();
|
||||||
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
let paths_to_watch: Vec<_> = include.iter().map(PathBuf::from).collect();
|
||||||
let no_check = ps.config.type_check_mode() == TypeCheckMode::None;
|
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
|
||||||
|
|
||||||
let resolver = |changed: Option<Vec<PathBuf>>| {
|
let resolver = |changed: Option<Vec<PathBuf>>| {
|
||||||
let mut cache = cache::FetchCacher::new(
|
let mut cache = cache::FetchCacher::new(
|
||||||
|
@ -1398,15 +1400,15 @@ pub async fn run_tests_with_watch(
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = ps
|
let maybe_jsx_resolver = ps
|
||||||
.config
|
.options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
||||||
let maybe_imports_result = ps.config.to_maybe_imports();
|
let maybe_imports_result = ps.options.to_maybe_imports();
|
||||||
let files_changed = changed.is_some();
|
let files_changed = changed.is_some();
|
||||||
let include = include.clone();
|
let include = include.clone();
|
||||||
let ignore = ignore.clone();
|
let ignore = ignore.clone();
|
||||||
let check_js = ps.config.check_js();
|
let check_js = ps.options.check_js();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let test_modules = if test_flags.doc {
|
let test_modules = if test_flags.doc {
|
||||||
|
@ -1535,9 +1537,9 @@ pub async fn run_tests_with_watch(
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let root_config = ps.config.clone();
|
let cli_options = ps.options.clone();
|
||||||
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
||||||
let root_config = root_config.clone();
|
let cli_options = cli_options.clone();
|
||||||
let filter = test_flags.filter.clone();
|
let filter = test_flags.filter.clone();
|
||||||
let include = include.clone();
|
let include = include.clone();
|
||||||
let ignore = ignore.clone();
|
let ignore = ignore.clone();
|
||||||
|
@ -1571,7 +1573,7 @@ pub async fn run_tests_with_watch(
|
||||||
permissions.clone(),
|
permissions.clone(),
|
||||||
specifiers_with_mode,
|
specifiers_with_mode,
|
||||||
TestSpecifierOptions {
|
TestSpecifierOptions {
|
||||||
compat_mode: root_config.compat(),
|
compat_mode: cli_options.compat(),
|
||||||
concurrent_jobs: test_flags.concurrent_jobs,
|
concurrent_jobs: test_flags.concurrent_jobs,
|
||||||
fail_fast: test_flags.fail_fast,
|
fail_fast: test_flags.fail_fast,
|
||||||
filter: filter.clone(),
|
filter: filter.clone(),
|
||||||
|
@ -1590,7 +1592,7 @@ pub async fn run_tests_with_watch(
|
||||||
operation,
|
operation,
|
||||||
file_watcher::PrintConfig {
|
file_watcher::PrintConfig {
|
||||||
job_name: "Test".to_string(),
|
job_name: "Test".to_string(),
|
||||||
clear_screen: !root_config.no_clear_screen(),
|
clear_screen: !cli_options.no_clear_screen(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
8
cli/tools/vendor/mod.rs
vendored
8
cli/tools/vendor/mod.rs
vendored
|
@ -134,12 +134,12 @@ fn validate_output_dir(
|
||||||
|
|
||||||
fn maybe_update_config_file(output_dir: &Path, ps: &ProcState) -> bool {
|
fn maybe_update_config_file(output_dir: &Path, ps: &ProcState) -> bool {
|
||||||
assert!(output_dir.is_absolute());
|
assert!(output_dir.is_absolute());
|
||||||
let config_file_specifier = match ps.config.maybe_config_file_specifier() {
|
let config_file_specifier = match ps.options.maybe_config_file_specifier() {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
let fmt_config = ps
|
let fmt_config = ps
|
||||||
.config
|
.options
|
||||||
.to_fmt_config()
|
.to_fmt_config()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
@ -263,11 +263,11 @@ async fn create_graph(
|
||||||
Permissions::allow_all(),
|
Permissions::allow_all(),
|
||||||
);
|
);
|
||||||
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
||||||
let maybe_imports = ps.config.to_maybe_imports()?;
|
let maybe_imports = ps.options.to_maybe_imports()?;
|
||||||
let maybe_import_map_resolver =
|
let maybe_import_map_resolver =
|
||||||
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
||||||
let maybe_jsx_resolver = ps
|
let maybe_jsx_resolver = ps
|
||||||
.config
|
.options
|
||||||
.to_maybe_jsx_import_source_module()
|
.to_maybe_jsx_import_source_module()
|
||||||
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()));
|
||||||
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
||||||
|
|
Loading…
Reference in a new issue