1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00

refactor: ProcState::build -> ProcState::from_flags (#18672)

This commit is contained in:
David Sherret 2023-04-12 14:54:28 -04:00 committed by Levente Kurusa
parent e556a3a962
commit ae424ee976
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4
18 changed files with 31 additions and 32 deletions

View file

@ -182,7 +182,7 @@ impl LanguageServer {
.into_iter() .into_iter()
.map(|d| (d.specifier().clone(), d)) .map(|d| (d.specifier().clone(), d))
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
let mut inner_loader = ps.create_graph_loader(); let mut inner_loader = ps.create_graph_loader();
let mut loader = crate::lsp::documents::OpenDocumentsGraphLoader { let mut loader = crate::lsp::documents::OpenDocumentsGraphLoader {
inner_loader: &mut inner_loader, inner_loader: &mut inner_loader,

View file

@ -259,7 +259,7 @@ impl TestRun {
let args = self.get_args(); let args = self.get_args();
lsp_log!("Executing test run with arguments: {}", args.join(" ")); lsp_log!("Executing test run with arguments: {}", args.join(" "));
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::from_flags(flags).await?;
// Various test files should not share the same permissions in terms of // Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.

View file

@ -69,13 +69,13 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
tools::run::eval_command(flags, eval_flags).await tools::run::eval_command(flags, eval_flags).await
} }
DenoSubcommand::Cache(cache_flags) => { DenoSubcommand::Cache(cache_flags) => {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
ps.load_and_type_check_files(&cache_flags.files).await?; ps.load_and_type_check_files(&cache_flags.files).await?;
ps.cache_module_emits()?; ps.cache_module_emits()?;
Ok(0) Ok(0)
} }
DenoSubcommand::Check(check_flags) => { DenoSubcommand::Check(check_flags) => {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
ps.load_and_type_check_files(&check_flags.files).await?; ps.load_and_type_check_files(&check_flags.files).await?;
Ok(0) Ok(0)
} }

View file

@ -112,17 +112,17 @@ impl Deref for ProcState {
} }
impl ProcState { impl ProcState {
pub async fn build(flags: Flags) -> Result<Self, AnyError> { pub async fn from_cli_options(
Self::from_options(Arc::new(CliOptions::from_flags(flags)?)).await
}
pub async fn from_options(
options: Arc<CliOptions>, options: Arc<CliOptions>,
) -> Result<Self, AnyError> { ) -> Result<Self, AnyError> {
Self::build_with_sender(options, None).await Self::build_with_sender(options, None).await
} }
pub async fn build_for_file_watcher( pub async fn from_flags(flags: Flags) -> Result<Self, AnyError> {
Self::from_cli_options(Arc::new(CliOptions::from_flags(flags)?)).await
}
pub async fn from_flags_for_file_watcher(
flags: Flags, flags: Flags,
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> {

View file

@ -307,7 +307,7 @@ pub async fn run(
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let flags = metadata_to_flags(&metadata); let flags = metadata_to_flags(&metadata);
let main_module = &metadata.entrypoint; let main_module = &metadata.entrypoint;
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let permissions = PermissionsContainer::new(Permissions::from_options( let permissions = PermissionsContainer::new(Permissions::from_options(
&metadata.permissions, &metadata.permissions,
)?); )?);

View file

@ -574,7 +574,7 @@ pub async fn run_benchmarks(
cli_options: CliOptions, cli_options: CliOptions,
bench_options: BenchOptions, bench_options: BenchOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
// Various bench files should not share the same permissions in terms of // Various bench files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.
@ -609,7 +609,7 @@ pub async fn run_benchmarks_with_watch(
cli_options: CliOptions, cli_options: CliOptions,
bench_options: BenchOptions, bench_options: BenchOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
// Various bench files should not share the same permissions in terms of // Various bench files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.

View file

@ -41,7 +41,7 @@ pub async fn bundle(
let module_specifier = &module_specifier; let module_specifier = &module_specifier;
async move { async move {
log::debug!(">>>>> bundle START"); log::debug!(">>>>> bundle START");
let ps = ProcState::from_options(cli_options).await?; let ps = ProcState::from_cli_options(cli_options).await?;
let graph = let graph =
create_graph_and_maybe_check(vec![module_specifier.clone()], &ps) create_graph_and_maybe_check(vec![module_specifier.clone()], &ps)
.await?; .await?;

View file

@ -621,7 +621,7 @@ pub async fn cover_files(
return Err(generic_error("No matching coverage profiles found")); return Err(generic_error("No matching coverage profiles found"));
} }
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let root_dir_url = ps.npm_resolver.root_dir_url(); let root_dir_url = ps.npm_resolver.root_dir_url();
let script_coverages = collect_coverages(coverage_flags.files)?; let script_coverages = collect_coverages(coverage_flags.files)?;

View file

@ -23,7 +23,7 @@ pub async fn print_docs(
flags: Flags, flags: Flags,
doc_flags: DocFlags, doc_flags: DocFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let mut doc_nodes = match doc_flags.source_file { let mut doc_nodes = match doc_flags.source_file {
DocSourceFileFlag::Builtin => { DocSourceFileFlag::Builtin => {

View file

@ -33,7 +33,7 @@ use crate::proc_state::ProcState;
use crate::util::checksum; use crate::util::checksum;
pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
if let Some(specifier) = info_flags.file { if let Some(specifier) = info_flags.file {
let specifier = resolve_url_or_path(&specifier, ps.options.initial_cwd())?; let specifier = resolve_url_or_path(&specifier, ps.options.initial_cwd())?;
let mut loader = ps.create_graph_loader(); let mut loader = ps.create_graph_loader();

View file

@ -233,7 +233,7 @@ pub async fn install_command(
install_flags: InstallFlags, install_flags: InstallFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
// ensure the module is cached // ensure the module is cached
ProcState::build(flags.clone()) ProcState::from_flags(flags.clone())
.await? .await?
.load_and_type_check_files(&[install_flags.module_url.clone()]) .load_and_type_check_files(&[install_flags.module_url.clone()])
.await?; .await?;

View file

@ -80,7 +80,7 @@ async fn read_eval_file(
} }
pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> { pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let main_module = ps.options.resolve_main_module()?; let main_module = ps.options.resolve_main_module()?;
let mut worker = create_main_worker( let mut worker = create_main_worker(
&ps, &ps,

View file

@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::io::Read; use std::io::Read;
use std::sync::Arc;
use deno_ast::MediaType; use deno_ast::MediaType;
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
@ -35,7 +34,7 @@ To grant permissions, set them before the script argument. For example:
// TODO(bartlomieju): actually I think it will also fail if there's an import // TODO(bartlomieju): actually I think it will also fail if there's an import
// map specified and bare specifier is used on the command line - this should // map specified and bare specifier is used on the command line - this should
// probably call `ProcState::resolve` instead // probably call `ProcState::resolve` instead
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
// Run a background task that checks for available upgrades. If an earlier // Run a background task that checks for available upgrades. If an earlier
// run of this background task found a new version of Deno. // run of this background task found a new version of Deno.
@ -56,7 +55,7 @@ To grant permissions, set them before the script argument. For example:
} }
pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let main_module = ps.options.resolve_main_module()?; let main_module = ps.options.resolve_main_module()?;
let mut worker = create_main_worker( let mut worker = create_main_worker(
@ -90,10 +89,10 @@ pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
// TODO(bartlomieju): this function is not handling `exit_code` set by the runtime // TODO(bartlomieju): this function is not handling `exit_code` set by the runtime
// code properly. // code properly.
async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> { async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
let flags = Arc::new(flags);
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
let mut ps = let mut ps =
ProcState::build_for_file_watcher((*flags).clone(), sender.clone()).await?; ProcState::from_flags_for_file_watcher(flags, sender.clone()).await?;
let clear_screen = !ps.options.no_clear_screen();
let main_module = ps.options.resolve_main_module()?; let main_module = ps.options.resolve_main_module()?;
let operation = |main_module: ModuleSpecifier| { let operation = |main_module: ModuleSpecifier| {
@ -116,7 +115,7 @@ async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
main_module, main_module,
util::file_watcher::PrintConfig { util::file_watcher::PrintConfig {
job_name: "Process".to_string(), job_name: "Process".to_string(),
clear_screen: !flags.no_clear_screen, clear_screen,
}, },
) )
.await?; .await?;
@ -128,7 +127,7 @@ pub async fn eval_command(
flags: Flags, flags: Flags,
eval_flags: EvalFlags, eval_flags: EvalFlags,
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let main_module = ps.options.resolve_main_module()?; let main_module = ps.options.resolve_main_module()?;
let permissions = PermissionsContainer::new(Permissions::from_options( let permissions = PermissionsContainer::new(Permissions::from_options(
&ps.options.permissions_options(), &ps.options.permissions_options(),

View file

@ -38,7 +38,7 @@ pub async fn compile(
flags: Flags, flags: Flags,
compile_flags: CompileFlags, compile_flags: CompileFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let module_specifier = ps.options.resolve_main_module()?; let module_specifier = ps.options.resolve_main_module()?;
let module_roots = { let module_roots = {
let mut vec = Vec::with_capacity(compile_flags.include.len() + 1); let mut vec = Vec::with_capacity(compile_flags.include.len() + 1);

View file

@ -23,7 +23,7 @@ pub async fn execute_script(
flags: Flags, flags: Flags,
task_flags: TaskFlags, task_flags: TaskFlags,
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let tasks_config = ps.options.resolve_tasks_config()?; let tasks_config = ps.options.resolve_tasks_config()?;
let maybe_package_json = ps.options.maybe_package_json(); let maybe_package_json = ps.options.maybe_package_json();
let package_json_scripts = maybe_package_json let package_json_scripts = maybe_package_json

View file

@ -1531,7 +1531,7 @@ pub async fn run_tests(
cli_options: CliOptions, cli_options: CliOptions,
test_options: TestOptions, test_options: TestOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
// Various test files should not share the same permissions in terms of // Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.
@ -1575,7 +1575,7 @@ pub async fn run_tests_with_watch(
cli_options: CliOptions, cli_options: CliOptions,
test_options: TestOptions, test_options: TestOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
// Various test files should not share the same permissions in terms of // Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.

View file

@ -263,7 +263,7 @@ pub async fn upgrade(
flags: Flags, flags: Flags,
upgrade_flags: UpgradeFlags, upgrade_flags: UpgradeFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let ps = ProcState::build(flags).await?; let ps = ProcState::from_flags(flags).await?;
let current_exe_path = std::env::current_exe()?; let current_exe_path = std::env::current_exe()?;
let metadata = fs::metadata(&current_exe_path)?; let metadata = fs::metadata(&current_exe_path)?;
let permissions = metadata.permissions(); let permissions = metadata.permissions();

View file

@ -42,7 +42,7 @@ pub async fn vendor(
let output_dir = resolve_from_cwd(&raw_output_dir)?; let output_dir = resolve_from_cwd(&raw_output_dir)?;
validate_output_dir(&output_dir, &vendor_flags)?; validate_output_dir(&output_dir, &vendor_flags)?;
validate_options(&mut cli_options, &output_dir)?; validate_options(&mut cli_options, &output_dir)?;
let ps = ProcState::from_options(Arc::new(cli_options)).await?; let ps = ProcState::from_cli_options(Arc::new(cli_options)).await?;
let graph = create_graph(&ps, &vendor_flags).await?; let graph = create_graph(&ps, &vendor_flags).await?;
let vendored_count = build::build( let vendored_count = build::build(
graph, graph,