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

This commit is contained in:
David Sherret 2023-04-12 14:54:28 -04:00 committed by GitHub
parent 66a22d231a
commit 9c255b2843
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 31 additions and 32 deletions

View file

@ -182,7 +182,7 @@ impl LanguageServer {
.into_iter()
.map(|d| (d.specifier().clone(), d))
.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 loader = crate::lsp::documents::OpenDocumentsGraphLoader {
inner_loader: &mut inner_loader,

View file

@ -259,7 +259,7 @@ impl TestRun {
let args = self.get_args();
lsp_log!("Executing test run with arguments: {}", args.join(" "));
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
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// 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
}
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.cache_module_emits()?;
Ok(0)
}
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?;
Ok(0)
}

View file

@ -112,17 +112,17 @@ impl Deref for ProcState {
}
impl ProcState {
pub async fn build(flags: Flags) -> Result<Self, AnyError> {
Self::from_options(Arc::new(CliOptions::from_flags(flags)?)).await
}
pub async fn from_options(
pub async fn from_cli_options(
options: Arc<CliOptions>,
) -> Result<Self, AnyError> {
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,
files_to_watch_sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>,
) -> Result<Self, AnyError> {

View file

@ -307,7 +307,7 @@ pub async fn run(
) -> Result<(), AnyError> {
let flags = metadata_to_flags(&metadata);
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(
&metadata.permissions,
)?);

View file

@ -574,7 +574,7 @@ pub async fn run_benchmarks(
cli_options: CliOptions,
bench_options: BenchOptions,
) -> 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
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.
@ -613,7 +613,7 @@ pub async fn run_benchmarks_with_watch(
cli_options: CliOptions,
bench_options: BenchOptions,
) -> 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
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// 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;
async move {
log::debug!(">>>>> bundle START");
let ps = ProcState::from_options(cli_options).await?;
let ps = ProcState::from_cli_options(cli_options).await?;
let graph =
create_graph_and_maybe_check(vec![module_specifier.clone()], &ps)
.await?;

View file

@ -621,7 +621,7 @@ pub async fn cover_files(
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 script_coverages = collect_coverages(coverage_flags.files)?;

View file

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

View file

@ -33,7 +33,7 @@ use crate::proc_state::ProcState;
use crate::util::checksum;
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 {
let specifier = resolve_url_or_path(&specifier, ps.options.initial_cwd())?;
let mut loader = ps.create_graph_loader();

View file

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

View file

@ -80,7 +80,7 @@ async fn read_eval_file(
}
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 mut worker = create_main_worker(
&ps,

View file

@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::io::Read;
use std::sync::Arc;
use deno_ast::MediaType;
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
// map specified and bare specifier is used on the command line - this should
// 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 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> {
let ps = ProcState::build(flags).await?;
let ps = ProcState::from_flags(flags).await?;
let main_module = ps.options.resolve_main_module()?;
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
// code properly.
async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
let flags = Arc::new(flags);
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
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 operation = |main_module: ModuleSpecifier| {
@ -116,7 +115,7 @@ async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> {
main_module,
util::file_watcher::PrintConfig {
job_name: "Process".to_string(),
clear_screen: !flags.no_clear_screen,
clear_screen,
},
)
.await?;
@ -128,7 +127,7 @@ pub async fn eval_command(
flags: Flags,
eval_flags: EvalFlags,
) -> 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 permissions = PermissionsContainer::new(Permissions::from_options(
&ps.options.permissions_options(),

View file

@ -38,7 +38,7 @@ pub async fn compile(
flags: Flags,
compile_flags: CompileFlags,
) -> 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_roots = {
let mut vec = Vec::with_capacity(compile_flags.include.len() + 1);

View file

@ -23,7 +23,7 @@ pub async fn execute_script(
flags: Flags,
task_flags: TaskFlags,
) -> 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 maybe_package_json = ps.options.maybe_package_json();
let package_json_scripts = maybe_package_json

View file

@ -1531,7 +1531,7 @@ pub async fn run_tests(
cli_options: CliOptions,
test_options: TestOptions,
) -> 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
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.
@ -1575,7 +1575,7 @@ pub async fn run_tests_with_watch(
cli_options: CliOptions,
test_options: TestOptions,
) -> 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
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.

View file

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

View file

@ -42,7 +42,7 @@ pub async fn vendor(
let output_dir = resolve_from_cwd(&raw_output_dir)?;
validate_output_dir(&output_dir, &vendor_flags)?;
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 vendored_count = build::build(
graph,