2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2023-10-02 17:53:55 -04:00
|
|
|
mod cache_dir;
|
2023-10-03 19:05:06 -04:00
|
|
|
mod common;
|
2023-09-30 12:06:38 -04:00
|
|
|
mod managed;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use deno_ast::ModuleSpecifier;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_runtime::deno_node::NpmResolver;
|
|
|
|
use deno_semver::package::PackageReq;
|
2023-10-02 17:53:55 -04:00
|
|
|
|
|
|
|
pub use self::cache_dir::NpmCacheDir;
|
|
|
|
pub use self::managed::CliNpmResolverManagedCreateOptions;
|
|
|
|
pub use self::managed::CliNpmResolverManagedPackageJsonInstallerOption;
|
|
|
|
pub use self::managed::CliNpmResolverManagedSnapshotOption;
|
|
|
|
pub use self::managed::ManagedCliNpmResolver;
|
|
|
|
|
|
|
|
pub enum CliNpmResolverCreateOptions {
|
|
|
|
Managed(CliNpmResolverManagedCreateOptions),
|
|
|
|
// todo(dsherret): implement this
|
|
|
|
#[allow(dead_code)]
|
|
|
|
Byonm,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn create_cli_npm_resolver_for_lsp(
|
|
|
|
options: CliNpmResolverCreateOptions,
|
|
|
|
) -> Arc<dyn CliNpmResolver> {
|
|
|
|
use CliNpmResolverCreateOptions::*;
|
|
|
|
match options {
|
|
|
|
Managed(options) => {
|
|
|
|
managed::create_managed_npm_resolver_for_lsp(options).await
|
|
|
|
}
|
|
|
|
Byonm => todo!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn create_cli_npm_resolver(
|
|
|
|
options: CliNpmResolverCreateOptions,
|
|
|
|
) -> Result<Arc<dyn CliNpmResolver>, AnyError> {
|
|
|
|
use CliNpmResolverCreateOptions::*;
|
|
|
|
match options {
|
|
|
|
Managed(options) => managed::create_managed_npm_resolver(options).await,
|
|
|
|
Byonm => todo!(),
|
|
|
|
}
|
|
|
|
}
|
2023-09-30 12:06:38 -04:00
|
|
|
|
|
|
|
pub enum InnerCliNpmResolverRef<'a> {
|
|
|
|
Managed(&'a ManagedCliNpmResolver),
|
|
|
|
#[allow(dead_code)]
|
|
|
|
Byonm(&'a ByonmCliNpmResolver),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait CliNpmResolver: NpmResolver {
|
|
|
|
fn into_npm_resolver(self: Arc<Self>) -> Arc<dyn NpmResolver>;
|
|
|
|
|
2023-10-02 17:53:55 -04:00
|
|
|
fn clone_snapshotted(&self) -> Arc<dyn CliNpmResolver>;
|
|
|
|
|
2023-09-30 12:06:38 -04:00
|
|
|
fn as_inner(&self) -> InnerCliNpmResolverRef;
|
|
|
|
|
|
|
|
fn as_managed(&self) -> Option<&ManagedCliNpmResolver> {
|
|
|
|
match self.as_inner() {
|
|
|
|
InnerCliNpmResolverRef::Managed(inner) => Some(inner),
|
|
|
|
InnerCliNpmResolverRef::Byonm(_) => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 19:05:06 -04:00
|
|
|
fn as_byonm(&self) -> Option<&ByonmCliNpmResolver> {
|
|
|
|
match self.as_inner() {
|
|
|
|
InnerCliNpmResolverRef::Managed(_) => None,
|
|
|
|
InnerCliNpmResolverRef::Byonm(inner) => Some(inner),
|
|
|
|
}
|
|
|
|
}
|
2023-09-30 12:06:38 -04:00
|
|
|
|
2023-10-03 19:05:06 -04:00
|
|
|
fn root_node_modules_path(&self) -> Option<PathBuf>;
|
2023-09-30 12:06:38 -04:00
|
|
|
|
|
|
|
/// Resolve the root folder of the package the provided specifier is in.
|
|
|
|
fn resolve_pkg_folder_from_specifier(
|
|
|
|
&self,
|
|
|
|
specifier: &ModuleSpecifier,
|
|
|
|
) -> Result<Option<PathBuf>, AnyError>;
|
|
|
|
|
|
|
|
fn resolve_pkg_folder_from_deno_module_req(
|
|
|
|
&self,
|
|
|
|
req: &PackageReq,
|
2023-10-03 19:05:06 -04:00
|
|
|
referrer: &ModuleSpecifier,
|
2023-09-30 12:06:38 -04:00
|
|
|
) -> Result<PathBuf, AnyError>;
|
|
|
|
|
|
|
|
/// Gets the state of npm for the process.
|
|
|
|
fn get_npm_process_state(&self) -> String;
|
|
|
|
|
2023-10-03 19:05:06 -04:00
|
|
|
/// Returns a hash returning the state of the npm resolver
|
|
|
|
/// or `None` if the state currently can't be determined.
|
|
|
|
fn check_state_hash(&self) -> Option<u64>;
|
2023-09-30 12:06:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo(#18967): implement this
|
|
|
|
pub struct ByonmCliNpmResolver;
|