2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-05-01 14:35:23 -04:00
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
use crate::args::get_root_cert_store;
|
|
|
|
use crate::args::CaData;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::args::CliOptions;
|
|
|
|
use crate::args::DenoSubcommand;
|
|
|
|
use crate::args::Flags;
|
2024-07-03 20:54:33 -04:00
|
|
|
use crate::args::PackageJsonInstallDepsProvider;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::args::StorageKeyResolver;
|
|
|
|
use crate::args::TsConfigType;
|
|
|
|
use crate::cache::Caches;
|
2024-04-17 10:19:55 -04:00
|
|
|
use crate::cache::CodeCache;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::cache::DenoDir;
|
2023-05-25 14:27:45 -04:00
|
|
|
use crate::cache::DenoDirProvider;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::cache::EmitCache;
|
2023-08-01 20:49:09 -04:00
|
|
|
use crate::cache::GlobalHttpCache;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::cache::HttpCache;
|
2023-08-01 20:49:09 -04:00
|
|
|
use crate::cache::LocalHttpCache;
|
2023-10-25 18:13:22 -04:00
|
|
|
use crate::cache::ModuleInfoCache;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::cache::NodeAnalysisCache;
|
|
|
|
use crate::cache::ParsedSourceCache;
|
|
|
|
use crate::emit::Emitter;
|
|
|
|
use crate::file_fetcher::FileFetcher;
|
2024-05-16 03:09:35 -04:00
|
|
|
use crate::graph_container::MainModuleGraphContainer;
|
2023-06-14 18:29:19 -04:00
|
|
|
use crate::graph_util::FileWatcherReporter;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::graph_util::ModuleGraphBuilder;
|
2024-02-20 16:29:57 -05:00
|
|
|
use crate::graph_util::ModuleGraphCreator;
|
2024-06-03 17:17:08 -04:00
|
|
|
use crate::http_util::HttpClientProvider;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::module_loader::CliModuleLoaderFactory;
|
|
|
|
use crate::module_loader::ModuleLoadPreparer;
|
2023-07-19 04:30:04 -04:00
|
|
|
use crate::node::CliCjsCodeAnalyzer;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::node::CliNodeCodeTranslator;
|
2023-10-02 17:53:55 -04:00
|
|
|
use crate::npm::create_cli_npm_resolver;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::npm::CliNpmResolver;
|
2023-10-25 14:39:00 -04:00
|
|
|
use crate::npm::CliNpmResolverByonmCreateOptions;
|
2023-10-02 17:53:55 -04:00
|
|
|
use crate::npm::CliNpmResolverCreateOptions;
|
|
|
|
use crate::npm::CliNpmResolverManagedCreateOptions;
|
|
|
|
use crate::npm::CliNpmResolverManagedSnapshotOption;
|
2024-01-27 12:10:36 -05:00
|
|
|
use crate::resolver::CjsResolutionStore;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::resolver::CliGraphResolver;
|
2023-08-17 12:14:22 -04:00
|
|
|
use crate::resolver::CliGraphResolverOptions;
|
2024-01-27 12:10:36 -05:00
|
|
|
use crate::resolver::CliNodeResolver;
|
|
|
|
use crate::resolver::NpmModuleLoader;
|
2023-12-07 15:59:13 -05:00
|
|
|
use crate::resolver::SloppyImportsResolver;
|
2023-05-10 20:06:59 -04:00
|
|
|
use crate::standalone::DenoCompileBinaryWriter;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::tools::check::TypeChecker;
|
2024-02-13 11:22:30 -05:00
|
|
|
use crate::tools::coverage::CoverageCollector;
|
2024-07-25 09:07:59 -04:00
|
|
|
use crate::tools::lint::LintRuleProvider;
|
2024-02-13 11:22:30 -05:00
|
|
|
use crate::tools::run::hmr::HmrRunner;
|
2023-10-19 01:05:00 -04:00
|
|
|
use crate::util::file_watcher::WatcherCommunicator;
|
2023-11-29 09:32:23 -05:00
|
|
|
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::util::progress_bar::ProgressBar;
|
|
|
|
use crate::util::progress_bar::ProgressBarStyle;
|
|
|
|
use crate::worker::CliMainWorkerFactory;
|
|
|
|
use crate::worker::CliMainWorkerOptions;
|
2024-02-13 11:22:30 -05:00
|
|
|
use std::path::PathBuf;
|
2023-05-01 14:35:23 -04:00
|
|
|
|
2024-07-04 20:41:01 -04:00
|
|
|
use deno_config::workspace::PackageJsonDepResolution;
|
2024-07-03 20:54:33 -04:00
|
|
|
use deno_config::workspace::WorkspaceResolver;
|
2023-05-01 14:35:23 -04:00
|
|
|
use deno_core::error::AnyError;
|
2024-02-20 16:29:57 -05:00
|
|
|
use deno_core::futures::FutureExt;
|
2023-10-12 11:55:50 -04:00
|
|
|
use deno_core::FeatureChecker;
|
2023-05-01 14:35:23 -04:00
|
|
|
|
2023-05-04 14:28:42 -04:00
|
|
|
use deno_runtime::deno_fs;
|
2024-07-25 19:08:14 -04:00
|
|
|
use deno_runtime::deno_node::DenoFsNodeResolverEnv;
|
2023-05-01 14:35:23 -04:00
|
|
|
use deno_runtime::deno_node::NodeResolver;
|
2024-07-23 19:00:48 -04:00
|
|
|
use deno_runtime::deno_tls::rustls::RootCertStore;
|
2023-05-01 16:42:05 -04:00
|
|
|
use deno_runtime::deno_tls::RootCertStoreProvider;
|
2023-05-01 14:35:23 -04:00
|
|
|
use deno_runtime::deno_web::BlobStore;
|
|
|
|
use deno_runtime::inspector_server::InspectorServer;
|
|
|
|
use log::warn;
|
2024-07-25 19:08:14 -04:00
|
|
|
use node_resolver::analyze::NodeCodeTranslator;
|
2024-07-23 19:00:48 -04:00
|
|
|
use once_cell::sync::OnceCell;
|
2023-05-01 14:35:23 -04:00
|
|
|
use std::future::Future;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
struct CliRootCertStoreProvider {
|
|
|
|
cell: OnceCell<RootCertStore>,
|
|
|
|
maybe_root_path: Option<PathBuf>,
|
|
|
|
maybe_ca_stores: Option<Vec<String>>,
|
|
|
|
maybe_ca_data: Option<CaData>,
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
impl CliRootCertStoreProvider {
|
|
|
|
pub fn new(
|
|
|
|
maybe_root_path: Option<PathBuf>,
|
|
|
|
maybe_ca_stores: Option<Vec<String>>,
|
|
|
|
maybe_ca_data: Option<CaData>,
|
|
|
|
) -> Self {
|
2023-10-19 01:05:00 -04:00
|
|
|
Self {
|
2024-07-23 19:00:48 -04:00
|
|
|
cell: Default::default(),
|
|
|
|
maybe_root_path,
|
|
|
|
maybe_ca_stores,
|
|
|
|
maybe_ca_data,
|
2023-10-19 01:05:00 -04:00
|
|
|
}
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
2024-07-23 19:00:48 -04:00
|
|
|
}
|
2023-05-01 14:35:23 -04:00
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
impl RootCertStoreProvider for CliRootCertStoreProvider {
|
|
|
|
fn get_or_try_init(&self) -> Result<&RootCertStore, AnyError> {
|
|
|
|
self
|
|
|
|
.cell
|
|
|
|
.get_or_try_init(|| {
|
|
|
|
get_root_cert_store(
|
|
|
|
self.maybe_root_path.clone(),
|
|
|
|
self.maybe_ca_stores.clone(),
|
|
|
|
self.maybe_ca_data.clone(),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.map_err(|e| e.into())
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Deferred<T>(once_cell::unsync::OnceCell<T>);
|
|
|
|
|
|
|
|
impl<T> Default for Deferred<T> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self(once_cell::unsync::OnceCell::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Deferred<T> {
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn from_value(value: T) -> Self {
|
|
|
|
Self(once_cell::unsync::OnceCell::from(value))
|
|
|
|
}
|
|
|
|
|
2024-02-20 16:29:57 -05:00
|
|
|
#[inline(always)]
|
2023-05-01 14:35:23 -04:00
|
|
|
pub fn get_or_try_init(
|
|
|
|
&self,
|
|
|
|
create: impl FnOnce() -> Result<T, AnyError>,
|
|
|
|
) -> Result<&T, AnyError> {
|
|
|
|
self.0.get_or_try_init(create)
|
|
|
|
}
|
|
|
|
|
2024-02-20 16:29:57 -05:00
|
|
|
#[inline(always)]
|
2023-05-01 14:35:23 -04:00
|
|
|
pub fn get_or_init(&self, create: impl FnOnce() -> T) -> &T {
|
|
|
|
self.0.get_or_init(create)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_or_try_init_async(
|
|
|
|
&self,
|
2024-02-20 16:29:57 -05:00
|
|
|
// some futures passed here are boxed because it was discovered
|
|
|
|
// that they were called a lot, causing other futures to get
|
|
|
|
// really big causing stack overflows on Windows
|
2023-05-01 14:35:23 -04:00
|
|
|
create: impl Future<Output = Result<T, AnyError>>,
|
|
|
|
) -> Result<&T, AnyError> {
|
|
|
|
if self.0.get().is_none() {
|
|
|
|
// todo(dsherret): it would be more ideal if this enforced a
|
|
|
|
// single executor and then we could make some initialization
|
|
|
|
// concurrent
|
|
|
|
let val = create.await?;
|
|
|
|
_ = self.0.set(val);
|
|
|
|
}
|
|
|
|
Ok(self.0.get().unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct CliFactoryServices {
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options: Deferred<Arc<CliOptions>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
caches: Deferred<Arc<Caches>>,
|
|
|
|
file_fetcher: Deferred<Arc<FileFetcher>>,
|
2023-08-01 20:49:09 -04:00
|
|
|
global_http_cache: Deferred<Arc<GlobalHttpCache>>,
|
|
|
|
http_cache: Deferred<Arc<dyn HttpCache>>,
|
2024-06-03 17:17:08 -04:00
|
|
|
http_client_provider: Deferred<Arc<HttpClientProvider>>,
|
2024-08-08 05:41:30 -04:00
|
|
|
emit_cache: Deferred<Arc<EmitCache>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
emitter: Deferred<Arc<Emitter>>,
|
2023-05-05 12:44:24 -04:00
|
|
|
fs: Deferred<Arc<dyn deno_fs::FileSystem>>,
|
2024-05-16 03:09:35 -04:00
|
|
|
main_graph_container: Deferred<Arc<MainModuleGraphContainer>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
maybe_inspector_server: Deferred<Option<Arc<InspectorServer>>>,
|
2023-05-01 16:42:05 -04:00
|
|
|
root_cert_store_provider: Deferred<Arc<dyn RootCertStoreProvider>>,
|
2023-07-01 18:52:30 -04:00
|
|
|
blob_store: Deferred<Arc<BlobStore>>,
|
2023-10-25 18:13:22 -04:00
|
|
|
module_info_cache: Deferred<Arc<ModuleInfoCache>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
parsed_source_cache: Deferred<Arc<ParsedSourceCache>>,
|
|
|
|
resolver: Deferred<Arc<CliGraphResolver>>,
|
|
|
|
maybe_file_watcher_reporter: Deferred<Option<FileWatcherReporter>>,
|
|
|
|
module_graph_builder: Deferred<Arc<ModuleGraphBuilder>>,
|
2024-02-20 16:29:57 -05:00
|
|
|
module_graph_creator: Deferred<Arc<ModuleGraphCreator>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
module_load_preparer: Deferred<Arc<ModuleLoadPreparer>>,
|
|
|
|
node_code_translator: Deferred<Arc<CliNodeCodeTranslator>>,
|
|
|
|
node_resolver: Deferred<Arc<NodeResolver>>,
|
2023-09-29 09:26:25 -04:00
|
|
|
npm_resolver: Deferred<Arc<dyn CliNpmResolver>>,
|
2024-07-25 09:07:59 -04:00
|
|
|
sloppy_imports_resolver: Deferred<Option<Arc<SloppyImportsResolver>>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
text_only_progress_bar: Deferred<ProgressBar>,
|
|
|
|
type_checker: Deferred<Arc<TypeChecker>>,
|
|
|
|
cjs_resolutions: Deferred<Arc<CjsResolutionStore>>,
|
2023-10-03 19:05:06 -04:00
|
|
|
cli_node_resolver: Deferred<Arc<CliNodeResolver>>,
|
2023-10-12 11:55:50 -04:00
|
|
|
feature_checker: Deferred<Arc<FeatureChecker>>,
|
2024-04-17 10:19:55 -04:00
|
|
|
code_cache: Deferred<Arc<CodeCache>>,
|
2024-07-03 20:54:33 -04:00
|
|
|
workspace_resolver: Deferred<Arc<WorkspaceResolver>>,
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CliFactory {
|
2023-10-30 20:25:58 -04:00
|
|
|
watcher_communicator: Option<Arc<WatcherCommunicator>>,
|
2024-07-23 19:00:48 -04:00
|
|
|
flags: Arc<Flags>,
|
2023-05-01 14:35:23 -04:00
|
|
|
services: CliFactoryServices,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CliFactory {
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn from_flags(flags: Arc<Flags>) -> Self {
|
|
|
|
Self {
|
|
|
|
flags,
|
|
|
|
watcher_communicator: None,
|
|
|
|
services: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_cli_options(cli_options: Arc<CliOptions>) -> Self {
|
|
|
|
let (cli_options, flags) = cli_options.into_self_and_flags();
|
|
|
|
CliFactory {
|
|
|
|
watcher_communicator: None,
|
|
|
|
flags,
|
|
|
|
services: CliFactoryServices {
|
|
|
|
cli_options: Deferred::from_value(cli_options),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
}
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn from_flags_for_watcher(
|
|
|
|
flags: Arc<Flags>,
|
|
|
|
watcher_communicator: Arc<WatcherCommunicator>,
|
|
|
|
) -> Self {
|
|
|
|
CliFactory {
|
|
|
|
watcher_communicator: Some(watcher_communicator),
|
|
|
|
flags,
|
|
|
|
services: Default::default(),
|
|
|
|
}
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn cli_options(&self) -> Result<&Arc<CliOptions>, AnyError> {
|
|
|
|
self.services.cli_options.get_or_try_init(|| {
|
|
|
|
CliOptions::from_flags(self.flags.clone()).map(Arc::new)
|
|
|
|
})
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn deno_dir_provider(&self) -> Result<&Arc<DenoDirProvider>, AnyError> {
|
2024-08-15 23:48:48 -04:00
|
|
|
Ok(&self.cli_options()?.deno_dir_provider)
|
2023-05-25 14:27:45 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
pub fn deno_dir(&self) -> Result<&DenoDir, AnyError> {
|
2024-07-23 19:00:48 -04:00
|
|
|
Ok(self.deno_dir_provider()?.get_or_create()?)
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn caches(&self) -> Result<&Arc<Caches>, AnyError> {
|
|
|
|
self.services.caches.get_or_try_init(|| {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
|
|
|
let caches = Arc::new(Caches::new(self.deno_dir_provider()?.clone()));
|
2023-05-01 14:35:23 -04:00
|
|
|
// Warm up the caches we know we'll likely need based on the CLI mode
|
2024-07-23 19:00:48 -04:00
|
|
|
match cli_options.sub_command() {
|
2024-02-20 16:29:57 -05:00
|
|
|
DenoSubcommand::Run(_)
|
2024-04-24 15:45:49 -04:00
|
|
|
| DenoSubcommand::Serve(_)
|
2024-02-20 16:29:57 -05:00
|
|
|
| DenoSubcommand::Bench(_)
|
|
|
|
| DenoSubcommand::Test(_)
|
|
|
|
| DenoSubcommand::Check(_) => {
|
2023-05-01 14:35:23 -04:00
|
|
|
_ = caches.dep_analysis_db();
|
|
|
|
_ = caches.node_analysis_db();
|
2024-07-23 19:00:48 -04:00
|
|
|
if cli_options.type_check_mode().is_true() {
|
2024-02-20 16:29:57 -05:00
|
|
|
_ = caches.fast_check_db();
|
|
|
|
_ = caches.type_checking_cache_db();
|
|
|
|
}
|
2024-07-23 19:00:48 -04:00
|
|
|
if cli_options.code_cache_enabled() {
|
2024-04-17 10:19:55 -04:00
|
|
|
_ = caches.code_cache_db();
|
|
|
|
}
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
Ok(caches)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-01 18:52:30 -04:00
|
|
|
pub fn blob_store(&self) -> &Arc<BlobStore> {
|
|
|
|
self.services.blob_store.get_or_init(Default::default)
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 16:42:05 -04:00
|
|
|
pub fn root_cert_store_provider(&self) -> &Arc<dyn RootCertStoreProvider> {
|
2024-07-23 19:00:48 -04:00
|
|
|
self.services.root_cert_store_provider.get_or_init(|| {
|
|
|
|
Arc::new(CliRootCertStoreProvider::new(
|
|
|
|
None,
|
|
|
|
self.flags.ca_stores.clone(),
|
|
|
|
self.flags.ca_data.clone(),
|
|
|
|
))
|
|
|
|
})
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn text_only_progress_bar(&self) -> &ProgressBar {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.text_only_progress_bar
|
|
|
|
.get_or_init(|| ProgressBar::new(ProgressBarStyle::TextOnly))
|
|
|
|
}
|
|
|
|
|
2023-08-01 20:49:09 -04:00
|
|
|
pub fn global_http_cache(&self) -> Result<&Arc<GlobalHttpCache>, AnyError> {
|
|
|
|
self.services.global_http_cache.get_or_try_init(|| {
|
|
|
|
Ok(Arc::new(GlobalHttpCache::new(
|
|
|
|
self.deno_dir()?.deps_folder_path(),
|
2023-08-08 10:23:02 -04:00
|
|
|
crate::cache::RealDenoCacheEnv,
|
2023-08-01 20:49:09 -04:00
|
|
|
)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn http_cache(&self) -> Result<&Arc<dyn HttpCache>, AnyError> {
|
|
|
|
self.services.http_cache.get_or_try_init(|| {
|
|
|
|
let global_cache = self.global_http_cache()?.clone();
|
2024-07-23 19:00:48 -04:00
|
|
|
match self.cli_options()?.vendor_dir_path() {
|
2023-08-01 20:49:09 -04:00
|
|
|
Some(local_path) => {
|
|
|
|
let local_cache =
|
|
|
|
LocalHttpCache::new(local_path.clone(), global_cache);
|
|
|
|
Ok(Arc::new(local_cache))
|
|
|
|
}
|
|
|
|
None => Ok(global_cache),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 17:17:08 -04:00
|
|
|
pub fn http_client_provider(&self) -> &Arc<HttpClientProvider> {
|
|
|
|
self.services.http_client_provider.get_or_init(|| {
|
|
|
|
Arc::new(HttpClientProvider::new(
|
2023-05-01 16:42:05 -04:00
|
|
|
Some(self.root_cert_store_provider().clone()),
|
2024-07-23 19:00:48 -04:00
|
|
|
self.flags.unsafely_ignore_certificate_errors.clone(),
|
2023-05-01 16:42:05 -04:00
|
|
|
))
|
2023-05-01 14:35:23 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn file_fetcher(&self) -> Result<&Arc<FileFetcher>, AnyError> {
|
|
|
|
self.services.file_fetcher.get_or_try_init(|| {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(Arc::new(FileFetcher::new(
|
2023-08-01 20:49:09 -04:00
|
|
|
self.http_cache()?.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.cache_setting(),
|
|
|
|
!cli_options.no_remote(),
|
2024-06-03 17:17:08 -04:00
|
|
|
self.http_client_provider().clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.blob_store().clone(),
|
|
|
|
Some(self.text_only_progress_bar().clone()),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-05 12:44:24 -04:00
|
|
|
pub fn fs(&self) -> &Arc<dyn deno_fs::FileSystem> {
|
|
|
|
self.services.fs.get_or_init(|| Arc::new(deno_fs::RealFs))
|
|
|
|
}
|
|
|
|
|
2023-09-29 09:26:25 -04:00
|
|
|
pub async fn npm_resolver(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<dyn CliNpmResolver>, AnyError> {
|
2023-05-01 14:35:23 -04:00
|
|
|
self
|
|
|
|
.services
|
|
|
|
.npm_resolver
|
|
|
|
.get_or_try_init_async(async {
|
2023-10-03 19:05:06 -04:00
|
|
|
let fs = self.fs();
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2024-05-08 15:34:46 -04:00
|
|
|
// For `deno install` we want to force the managed resolver so it can set up `node_modules/` directory.
|
2024-08-12 16:17:25 -04:00
|
|
|
create_cli_npm_resolver(if cli_options.use_byonm() && !matches!(cli_options.sub_command(), DenoSubcommand::Install(_) | DenoSubcommand::Add(_) | DenoSubcommand::Remove(_)) {
|
2023-10-25 14:39:00 -04:00
|
|
|
CliNpmResolverCreateOptions::Byonm(CliNpmResolverByonmCreateOptions {
|
|
|
|
fs: fs.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
root_node_modules_dir: Some(match cli_options.node_modules_dir_path() {
|
2024-04-05 10:34:51 -04:00
|
|
|
Some(node_modules_path) => node_modules_path.to_path_buf(),
|
2023-11-29 09:32:23 -05:00
|
|
|
// path needs to be canonicalized for node resolution
|
|
|
|
// (node_modules_dir_path above is already canonicalized)
|
2024-07-23 19:00:48 -04:00
|
|
|
None => canonicalize_path_maybe_not_exists(cli_options.initial_cwd())?
|
2023-11-29 09:32:23 -05:00
|
|
|
.join("node_modules"),
|
2024-07-10 14:46:25 -04:00
|
|
|
}),
|
2023-10-25 14:39:00 -04:00
|
|
|
})
|
|
|
|
} else {
|
2023-10-03 19:05:06 -04:00
|
|
|
CliNpmResolverCreateOptions::Managed(CliNpmResolverManagedCreateOptions {
|
2024-07-23 19:00:48 -04:00
|
|
|
snapshot: match cli_options.resolve_npm_resolution_snapshot()? {
|
2023-10-03 19:05:06 -04:00
|
|
|
Some(snapshot) => {
|
|
|
|
CliNpmResolverManagedSnapshotOption::Specified(Some(snapshot))
|
2023-10-02 17:53:55 -04:00
|
|
|
}
|
2024-07-23 19:00:48 -04:00
|
|
|
None => match cli_options.maybe_lockfile() {
|
2023-10-03 19:05:06 -04:00
|
|
|
Some(lockfile) => {
|
|
|
|
CliNpmResolverManagedSnapshotOption::ResolveFromLockfile(
|
|
|
|
lockfile.clone(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
None => CliNpmResolverManagedSnapshotOption::Specified(None),
|
|
|
|
},
|
2023-10-02 17:53:55 -04:00
|
|
|
},
|
2024-07-23 19:00:48 -04:00
|
|
|
maybe_lockfile: cli_options.maybe_lockfile().cloned(),
|
2023-10-03 19:05:06 -04:00
|
|
|
fs: fs.clone(),
|
2024-06-03 17:17:08 -04:00
|
|
|
http_client_provider: self.http_client_provider().clone(),
|
2023-10-03 19:05:06 -04:00
|
|
|
npm_global_cache_dir: self.deno_dir()?.npm_folder_path(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cache_setting: cli_options.cache_setting(),
|
2023-10-03 19:05:06 -04:00
|
|
|
text_only_progress_bar: self.text_only_progress_bar().clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
maybe_node_modules_path: cli_options.node_modules_dir_path().cloned(),
|
2024-07-03 20:54:33 -04:00
|
|
|
package_json_deps_provider: Arc::new(PackageJsonInstallDepsProvider::from_workspace(
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.workspace(),
|
2024-07-03 20:54:33 -04:00
|
|
|
)),
|
2024-07-23 19:00:48 -04:00
|
|
|
npm_system_info: cli_options.npm_system_info(),
|
|
|
|
npmrc: cli_options.npmrc().clone(),
|
|
|
|
lifecycle_scripts: cli_options.lifecycle_scripts_config(),
|
2023-10-03 19:05:06 -04:00
|
|
|
})
|
2023-10-25 14:39:00 -04:00
|
|
|
}).await
|
2024-02-20 16:29:57 -05:00
|
|
|
}.boxed_local())
|
2023-05-01 14:35:23 -04:00
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2024-07-25 09:07:59 -04:00
|
|
|
pub fn sloppy_imports_resolver(
|
|
|
|
&self,
|
|
|
|
) -> Result<Option<&Arc<SloppyImportsResolver>>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.sloppy_imports_resolver
|
|
|
|
.get_or_try_init(|| {
|
|
|
|
Ok(
|
|
|
|
self
|
|
|
|
.cli_options()?
|
|
|
|
.unstable_sloppy_imports()
|
|
|
|
.then(|| Arc::new(SloppyImportsResolver::new(self.fs().clone()))),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.map(|maybe| maybe.as_ref())
|
|
|
|
}
|
|
|
|
|
2024-07-03 20:54:33 -04:00
|
|
|
pub async fn workspace_resolver(
|
2023-05-01 14:35:23 -04:00
|
|
|
&self,
|
2024-07-03 20:54:33 -04:00
|
|
|
) -> Result<&Arc<WorkspaceResolver>, AnyError> {
|
2023-05-01 14:35:23 -04:00
|
|
|
self
|
|
|
|
.services
|
2024-07-03 20:54:33 -04:00
|
|
|
.workspace_resolver
|
2023-05-01 14:35:23 -04:00
|
|
|
.get_or_try_init_async(async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
|
|
|
let resolver = cli_options
|
2024-07-04 20:41:01 -04:00
|
|
|
.create_workspace_resolver(
|
|
|
|
self.file_fetcher()?,
|
2024-07-23 19:00:48 -04:00
|
|
|
if cli_options.use_byonm() {
|
2024-07-04 20:41:01 -04:00
|
|
|
PackageJsonDepResolution::Disabled
|
|
|
|
} else {
|
|
|
|
// todo(dsherret): this should be false for nodeModulesDir: true
|
|
|
|
PackageJsonDepResolution::Enabled
|
|
|
|
},
|
|
|
|
)
|
2024-07-03 20:54:33 -04:00
|
|
|
.await?;
|
|
|
|
if !resolver.diagnostics().is_empty() {
|
|
|
|
warn!(
|
|
|
|
"Import map diagnostics:\n{}",
|
|
|
|
resolver
|
|
|
|
.diagnostics()
|
|
|
|
.iter()
|
|
|
|
.map(|d| format!(" - {d}"))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Ok(Arc::new(resolver))
|
2023-05-01 14:35:23 -04:00
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn resolver(&self) -> Result<&Arc<CliGraphResolver>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.resolver
|
2024-02-20 16:29:57 -05:00
|
|
|
.get_or_try_init_async(
|
|
|
|
async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2024-02-20 16:29:57 -05:00
|
|
|
Ok(Arc::new(CliGraphResolver::new(CliGraphResolverOptions {
|
2024-07-25 09:07:59 -04:00
|
|
|
sloppy_imports_resolver: self.sloppy_imports_resolver()?.cloned(),
|
2024-03-05 19:23:51 -05:00
|
|
|
node_resolver: Some(self.cli_node_resolver().await?.clone()),
|
2024-07-23 19:00:48 -04:00
|
|
|
npm_resolver: if cli_options.no_npm() {
|
2024-02-20 16:29:57 -05:00
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(self.npm_resolver().await?.clone())
|
|
|
|
},
|
2024-07-03 20:54:33 -04:00
|
|
|
workspace_resolver: self.workspace_resolver().await?.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
bare_node_builtins_enabled: cli_options
|
2024-07-03 20:54:33 -04:00
|
|
|
.unstable_bare_node_builtins(),
|
2024-07-23 19:00:48 -04:00
|
|
|
maybe_jsx_import_source_config: cli_options
|
2024-07-19 15:56:07 -04:00
|
|
|
.workspace()
|
2024-02-20 16:29:57 -05:00
|
|
|
.to_maybe_jsx_import_source_config()?,
|
2024-07-23 19:00:48 -04:00
|
|
|
maybe_vendor_dir: cli_options.vendor_dir_path(),
|
2024-02-20 16:29:57 -05:00
|
|
|
})))
|
|
|
|
}
|
|
|
|
.boxed_local(),
|
|
|
|
)
|
2023-05-01 14:35:23 -04:00
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn maybe_file_watcher_reporter(&self) -> &Option<FileWatcherReporter> {
|
2023-10-19 01:05:00 -04:00
|
|
|
let maybe_file_watcher_reporter = self
|
|
|
|
.watcher_communicator
|
|
|
|
.as_ref()
|
|
|
|
.map(|i| FileWatcherReporter::new(i.clone()));
|
2023-05-01 14:35:23 -04:00
|
|
|
self
|
|
|
|
.services
|
|
|
|
.maybe_file_watcher_reporter
|
2023-10-19 01:05:00 -04:00
|
|
|
.get_or_init(|| maybe_file_watcher_reporter)
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-08-08 05:41:30 -04:00
|
|
|
pub fn emit_cache(&self) -> Result<&Arc<EmitCache>, AnyError> {
|
2023-05-01 14:35:23 -04:00
|
|
|
self.services.emit_cache.get_or_try_init(|| {
|
2024-08-08 05:41:30 -04:00
|
|
|
Ok(Arc::new(EmitCache::new(self.deno_dir()?.gen_cache.clone())))
|
2023-05-01 14:35:23 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-25 18:13:22 -04:00
|
|
|
pub fn module_info_cache(&self) -> Result<&Arc<ModuleInfoCache>, AnyError> {
|
|
|
|
self.services.module_info_cache.get_or_try_init(|| {
|
|
|
|
Ok(Arc::new(ModuleInfoCache::new(
|
2023-05-01 14:35:23 -04:00
|
|
|
self.caches()?.dep_analysis_db(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:19:55 -04:00
|
|
|
pub fn code_cache(&self) -> Result<&Arc<CodeCache>, AnyError> {
|
|
|
|
self.services.code_cache.get_or_try_init(|| {
|
|
|
|
Ok(Arc::new(CodeCache::new(self.caches()?.code_cache_db())))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-25 18:13:22 -04:00
|
|
|
pub fn parsed_source_cache(&self) -> &Arc<ParsedSourceCache> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.parsed_source_cache
|
|
|
|
.get_or_init(Default::default)
|
|
|
|
}
|
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
pub fn emitter(&self) -> Result<&Arc<Emitter>, AnyError> {
|
|
|
|
self.services.emitter.get_or_try_init(|| {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
|
|
|
let ts_config_result =
|
|
|
|
cli_options.resolve_ts_config_for_emit(TsConfigType::Emit)?;
|
2023-05-01 14:35:23 -04:00
|
|
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
|
|
|
warn!("{}", ignored_options);
|
|
|
|
}
|
2024-04-11 19:00:17 -04:00
|
|
|
let (transpile_options, emit_options) =
|
|
|
|
crate::args::ts_config_to_transpile_and_emit_options(
|
|
|
|
ts_config_result.ts_config,
|
2024-04-23 11:50:50 -04:00
|
|
|
)?;
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(Arc::new(Emitter::new(
|
|
|
|
self.emit_cache()?.clone(),
|
2023-10-25 18:13:22 -04:00
|
|
|
self.parsed_source_cache().clone(),
|
2024-04-11 19:00:17 -04:00
|
|
|
transpile_options,
|
2023-05-01 14:35:23 -04:00
|
|
|
emit_options,
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-25 09:07:59 -04:00
|
|
|
pub async fn lint_rule_provider(&self) -> Result<LintRuleProvider, AnyError> {
|
|
|
|
Ok(LintRuleProvider::new(
|
|
|
|
self.sloppy_imports_resolver()?.cloned(),
|
|
|
|
Some(self.workspace_resolver().await?.clone()),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
pub async fn node_resolver(&self) -> Result<&Arc<NodeResolver>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.node_resolver
|
2024-02-20 16:29:57 -05:00
|
|
|
.get_or_try_init_async(
|
|
|
|
async {
|
|
|
|
Ok(Arc::new(NodeResolver::new(
|
2024-07-25 19:08:14 -04:00
|
|
|
DenoFsNodeResolverEnv::new(self.fs().clone()),
|
2024-02-20 16:29:57 -05:00
|
|
|
self.npm_resolver().await?.clone().into_npm_resolver(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
.boxed_local(),
|
|
|
|
)
|
2023-05-01 14:35:23 -04:00
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn node_code_translator(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<CliNodeCodeTranslator>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.node_code_translator
|
|
|
|
.get_or_try_init_async(async {
|
|
|
|
let caches = self.caches()?;
|
|
|
|
let node_analysis_cache =
|
|
|
|
NodeAnalysisCache::new(caches.node_analysis_db());
|
2023-07-24 15:35:13 -04:00
|
|
|
let cjs_esm_analyzer =
|
|
|
|
CliCjsCodeAnalyzer::new(node_analysis_cache, self.fs().clone());
|
2023-05-01 14:35:23 -04:00
|
|
|
|
|
|
|
Ok(Arc::new(NodeCodeTranslator::new(
|
|
|
|
cjs_esm_analyzer,
|
2024-07-25 19:08:14 -04:00
|
|
|
DenoFsNodeResolverEnv::new(self.fs().clone()),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.node_resolver().await?.clone(),
|
2023-09-29 09:26:25 -04:00
|
|
|
self.npm_resolver().await?.clone().into_npm_resolver(),
|
2023-05-01 14:35:23 -04:00
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn type_checker(&self) -> Result<&Arc<TypeChecker>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.type_checker
|
|
|
|
.get_or_try_init_async(async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(Arc::new(TypeChecker::new(
|
|
|
|
self.caches()?.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.clone(),
|
2024-02-20 16:29:57 -05:00
|
|
|
self.module_graph_builder().await?.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.node_resolver().await?.clone(),
|
|
|
|
self.npm_resolver().await?.clone(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn module_graph_builder(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<ModuleGraphBuilder>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.module_graph_builder
|
|
|
|
.get_or_try_init_async(async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(Arc::new(ModuleGraphBuilder::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.clone(),
|
2024-02-20 16:29:57 -05:00
|
|
|
self.caches()?.clone(),
|
2023-12-01 15:12:10 -05:00
|
|
|
self.fs().clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.resolver().await?.clone(),
|
|
|
|
self.npm_resolver().await?.clone(),
|
2023-10-25 18:13:22 -04:00
|
|
|
self.module_info_cache()?.clone(),
|
|
|
|
self.parsed_source_cache().clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.maybe_lockfile().cloned(),
|
2023-06-14 18:29:19 -04:00
|
|
|
self.maybe_file_watcher_reporter().clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.emit_cache()?.clone(),
|
|
|
|
self.file_fetcher()?.clone(),
|
2023-08-01 20:49:09 -04:00
|
|
|
self.global_http_cache()?.clone(),
|
2024-02-20 16:29:57 -05:00
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn module_graph_creator(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<ModuleGraphCreator>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.module_graph_creator
|
|
|
|
.get_or_try_init_async(async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2024-02-20 16:29:57 -05:00
|
|
|
Ok(Arc::new(ModuleGraphCreator::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.clone(),
|
2024-02-20 16:29:57 -05:00
|
|
|
self.npm_resolver().await?.clone(),
|
|
|
|
self.module_graph_builder().await?.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.type_checker().await?.clone(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2024-05-16 03:09:35 -04:00
|
|
|
pub async fn main_module_graph_container(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<MainModuleGraphContainer>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.main_graph_container
|
|
|
|
.get_or_try_init_async(async {
|
|
|
|
Ok(Arc::new(MainModuleGraphContainer::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
self.cli_options()?.clone(),
|
2024-05-16 03:09:35 -04:00
|
|
|
self.module_load_preparer().await?.clone(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
2024-04-11 19:17:10 -04:00
|
|
|
pub fn maybe_inspector_server(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Option<Arc<InspectorServer>>, AnyError> {
|
|
|
|
self.services.maybe_inspector_server.get_or_try_init(|| {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
|
|
|
match cli_options.resolve_inspector_server() {
|
2024-04-11 19:17:10 -04:00
|
|
|
Ok(server) => Ok(server.map(Arc::new)),
|
|
|
|
Err(err) => Err(err),
|
|
|
|
}
|
|
|
|
})
|
2023-05-01 14:35:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn module_load_preparer(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<ModuleLoadPreparer>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.module_load_preparer
|
|
|
|
.get_or_try_init_async(async {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(Arc::new(ModuleLoadPreparer::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.clone(),
|
|
|
|
cli_options.maybe_lockfile().cloned(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.module_graph_builder().await?.clone(),
|
|
|
|
self.text_only_progress_bar().clone(),
|
|
|
|
self.type_checker().await?.clone(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cjs_resolutions(&self) -> &Arc<CjsResolutionStore> {
|
|
|
|
self.services.cjs_resolutions.get_or_init(Default::default)
|
|
|
|
}
|
|
|
|
|
2023-10-03 19:05:06 -04:00
|
|
|
pub async fn cli_node_resolver(
|
|
|
|
&self,
|
|
|
|
) -> Result<&Arc<CliNodeResolver>, AnyError> {
|
|
|
|
self
|
|
|
|
.services
|
|
|
|
.cli_node_resolver
|
|
|
|
.get_or_try_init_async(async {
|
|
|
|
Ok(Arc::new(CliNodeResolver::new(
|
2024-07-10 14:46:25 -04:00
|
|
|
self.cjs_resolutions().clone(),
|
2024-03-05 19:23:51 -05:00
|
|
|
self.fs().clone(),
|
2023-10-03 19:05:06 -04:00
|
|
|
self.node_resolver().await?.clone(),
|
|
|
|
self.npm_resolver().await?.clone(),
|
|
|
|
)))
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
pub fn feature_checker(&self) -> Result<&Arc<FeatureChecker>, AnyError> {
|
|
|
|
self.services.feature_checker.get_or_try_init(|| {
|
|
|
|
let cli_options = self.cli_options()?;
|
2023-10-12 11:55:50 -04:00
|
|
|
let mut checker = FeatureChecker::default();
|
|
|
|
checker.set_exit_cb(Box::new(crate::unstable_exit_cb));
|
2024-01-23 09:33:07 -05:00
|
|
|
checker.set_warn_cb(Box::new(crate::unstable_warn_cb));
|
2024-07-23 19:00:48 -04:00
|
|
|
if cli_options.legacy_unstable_flag() {
|
2023-10-12 11:55:50 -04:00
|
|
|
checker.enable_legacy_unstable();
|
2024-01-23 09:33:07 -05:00
|
|
|
checker.warn_on_legacy_unstable();
|
2023-10-12 11:55:50 -04:00
|
|
|
}
|
2024-07-23 19:00:48 -04:00
|
|
|
let unstable_features = cli_options.unstable_features();
|
2024-08-27 07:45:27 -04:00
|
|
|
for granular_flag in crate::UNSTABLE_GRANULAR_FLAGS {
|
|
|
|
if unstable_features.contains(&granular_flag.name.to_string()) {
|
|
|
|
checker.enable_feature(granular_flag.name);
|
2023-11-01 18:15:08 -04:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 11:55:50 -04:00
|
|
|
|
2024-07-23 19:00:48 -04:00
|
|
|
Ok(Arc::new(checker))
|
2023-10-12 11:55:50 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-10 20:06:59 -04:00
|
|
|
pub async fn create_compile_binary_writer(
|
|
|
|
&self,
|
|
|
|
) -> Result<DenoCompileBinaryWriter, AnyError> {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-10 20:06:59 -04:00
|
|
|
Ok(DenoCompileBinaryWriter::new(
|
|
|
|
self.deno_dir()?,
|
2024-06-03 17:17:08 -04:00
|
|
|
self.file_fetcher()?,
|
|
|
|
self.http_client_provider(),
|
2023-09-29 09:26:25 -04:00
|
|
|
self.npm_resolver().await?.as_ref(),
|
2024-07-04 20:41:01 -04:00
|
|
|
self.workspace_resolver().await?.as_ref(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.npm_system_info(),
|
2023-05-10 20:06:59 -04:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
pub async fn create_cli_main_worker_factory(
|
|
|
|
&self,
|
|
|
|
) -> Result<CliMainWorkerFactory, AnyError> {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
2023-05-01 14:35:23 -04:00
|
|
|
let node_resolver = self.node_resolver().await?;
|
2023-09-28 16:43:45 -04:00
|
|
|
let npm_resolver = self.npm_resolver().await?;
|
2023-05-10 20:06:59 -04:00
|
|
|
let fs = self.fs();
|
2023-10-03 19:05:06 -04:00
|
|
|
let cli_node_resolver = self.cli_node_resolver().await?;
|
2024-07-23 19:00:48 -04:00
|
|
|
let maybe_file_watcher_communicator = if cli_options.has_hmr() {
|
2023-10-30 20:25:58 -04:00
|
|
|
Some(self.watcher_communicator.clone().unwrap())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2023-10-19 01:05:00 -04:00
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(CliMainWorkerFactory::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
StorageKeyResolver::from_options(cli_options),
|
|
|
|
cli_options.sub_command().clone(),
|
2023-09-28 16:43:45 -04:00
|
|
|
npm_resolver.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
node_resolver.clone(),
|
|
|
|
self.blob_store().clone(),
|
|
|
|
Box::new(CliModuleLoaderFactory::new(
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options,
|
|
|
|
if cli_options.code_cache_enabled() {
|
2024-05-16 03:09:35 -04:00
|
|
|
Some(self.code_cache()?.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
2023-05-01 14:35:23 -04:00
|
|
|
self.emitter()?.clone(),
|
2024-05-16 03:09:35 -04:00
|
|
|
self.main_module_graph_container().await?.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.module_load_preparer().await?.clone(),
|
2023-10-03 19:05:06 -04:00
|
|
|
cli_node_resolver.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
NpmModuleLoader::new(
|
|
|
|
self.cjs_resolutions().clone(),
|
|
|
|
self.node_code_translator().await?.clone(),
|
2023-05-10 20:06:59 -04:00
|
|
|
fs.clone(),
|
2023-10-03 19:05:06 -04:00
|
|
|
cli_node_resolver.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
),
|
2024-05-16 03:09:35 -04:00
|
|
|
self.parsed_source_cache().clone(),
|
|
|
|
self.resolver().await?.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
)),
|
2023-05-01 16:42:05 -04:00
|
|
|
self.root_cert_store_provider().clone(),
|
2023-05-05 12:44:24 -04:00
|
|
|
self.fs().clone(),
|
2023-10-30 20:25:58 -04:00
|
|
|
maybe_file_watcher_communicator,
|
2024-04-11 19:17:10 -04:00
|
|
|
self.maybe_inspector_server()?.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.maybe_lockfile().cloned(),
|
|
|
|
self.feature_checker()?.clone(),
|
2023-05-01 14:35:23 -04:00
|
|
|
self.create_cli_main_worker_options()?,
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.node_ipc_fd(),
|
|
|
|
cli_options.serve_port(),
|
|
|
|
cli_options.serve_host(),
|
|
|
|
cli_options.enable_future_features(),
|
2024-01-31 17:18:14 -05:00
|
|
|
// TODO(bartlomieju): temporarily disabled
|
2024-07-23 19:00:48 -04:00
|
|
|
// cli_options.disable_deprecated_api_warning,
|
2024-01-31 17:18:14 -05:00
|
|
|
true,
|
2024-07-23 19:00:48 -04:00
|
|
|
cli_options.verbose_deprecated_api_warning,
|
|
|
|
if cli_options.code_cache_enabled() {
|
2024-04-17 10:19:55 -04:00
|
|
|
Some(self.code_cache()?.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
2023-05-01 14:35:23 -04:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_cli_main_worker_options(
|
|
|
|
&self,
|
|
|
|
) -> Result<CliMainWorkerOptions, AnyError> {
|
2024-07-23 19:00:48 -04:00
|
|
|
let cli_options = self.cli_options()?;
|
|
|
|
let create_hmr_runner = if cli_options.has_hmr() {
|
2024-02-13 11:22:30 -05:00
|
|
|
let watcher_communicator = self.watcher_communicator.clone().unwrap();
|
|
|
|
let emitter = self.emitter()?.clone();
|
|
|
|
let fn_: crate::worker::CreateHmrRunnerCb = Box::new(move |session| {
|
|
|
|
Box::new(HmrRunner::new(
|
|
|
|
emitter.clone(),
|
|
|
|
session,
|
|
|
|
watcher_communicator.clone(),
|
|
|
|
))
|
|
|
|
});
|
|
|
|
Some(fn_)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let create_coverage_collector =
|
2024-07-23 19:00:48 -04:00
|
|
|
if let Some(coverage_dir) = cli_options.coverage_dir() {
|
2024-02-13 11:22:30 -05:00
|
|
|
let coverage_dir = PathBuf::from(coverage_dir);
|
|
|
|
let fn_: crate::worker::CreateCoverageCollectorCb =
|
|
|
|
Box::new(move |session| {
|
|
|
|
Box::new(CoverageCollector::new(coverage_dir.clone(), session))
|
|
|
|
});
|
|
|
|
Some(fn_)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
Ok(CliMainWorkerOptions {
|
2024-07-23 19:00:48 -04:00
|
|
|
argv: cli_options.argv().clone(),
|
2023-11-11 12:01:48 -05:00
|
|
|
// This optimization is only available for "run" subcommand
|
|
|
|
// because we need to register new ops for testing and jupyter
|
|
|
|
// integration.
|
2024-07-23 19:00:48 -04:00
|
|
|
skip_op_registration: cli_options.sub_command().is_run(),
|
|
|
|
log_level: cli_options.log_level().unwrap_or(log::Level::Info).into(),
|
|
|
|
enable_op_summary_metrics: cli_options.enable_op_summary_metrics(),
|
|
|
|
enable_testing_features: cli_options.enable_testing_features(),
|
|
|
|
has_node_modules_dir: cli_options.has_node_modules_dir(),
|
|
|
|
hmr: cli_options.has_hmr(),
|
|
|
|
inspect_brk: cli_options.inspect_brk().is_some(),
|
|
|
|
inspect_wait: cli_options.inspect_wait().is_some(),
|
|
|
|
strace_ops: cli_options.strace_ops().clone(),
|
|
|
|
is_inspecting: cli_options.is_inspecting(),
|
|
|
|
is_npm_main: cli_options.is_npm_main(),
|
|
|
|
location: cli_options.location_flag().clone(),
|
2023-12-06 16:36:06 -05:00
|
|
|
// if the user ran a binary command, we'll need to set process.argv[0]
|
|
|
|
// to be the name of the binary command instead of deno
|
2024-07-23 19:00:48 -04:00
|
|
|
argv0: cli_options
|
2024-02-23 11:30:29 -05:00
|
|
|
.take_binary_npm_command_name()
|
|
|
|
.or(std::env::args().next()),
|
2024-05-05 10:16:02 -04:00
|
|
|
node_debug: std::env::var("NODE_DEBUG").ok(),
|
2023-05-01 14:35:23 -04:00
|
|
|
origin_data_folder_path: Some(self.deno_dir()?.origin_data_folder_path()),
|
2024-07-23 19:00:48 -04:00
|
|
|
seed: cli_options.seed(),
|
|
|
|
unsafely_ignore_certificate_errors: cli_options
|
2023-05-01 14:35:23 -04:00
|
|
|
.unsafely_ignore_certificate_errors()
|
|
|
|
.clone(),
|
2024-07-23 19:00:48 -04:00
|
|
|
unstable: cli_options.legacy_unstable_flag(),
|
2024-02-13 11:22:30 -05:00
|
|
|
create_hmr_runner,
|
|
|
|
create_coverage_collector,
|
2023-05-01 14:35:23 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|