summaryrefslogtreecommitdiff
path: root/cli/npm/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-10-25 14:39:00 -0400
committerGitHub <noreply@github.com>2023-10-25 14:39:00 -0400
commitbe97170a193e8cecc5ce03ecd3c1d0add4a06bf7 (patch)
treefab7d266e208db93dcf0870dda70f7da56ade735 /cli/npm/mod.rs
parent093b3eee58181ec45839d0fe10b8157326a102b2 (diff)
feat(unstable): ability to `npm install` then `deno run main.ts` (#20967)
This PR adds a new unstable "bring your own node_modules" (BYONM) functionality currently behind a `--unstable-byonm` flag (`"unstable": ["byonm"]` in a deno.json). This enables users to run a separate install command (ex. `npm install`, `pnpm install`) then run `deno run main.ts` and Deno will respect the layout of the node_modules directory as setup by the separate install command. It also works with npm/yarn/pnpm workspaces. For this PR, the behaviour is opted into by specifying `--unstable-byonm`/`"unstable": ["byonm"]`, but in the future we may make this the default behaviour as outlined in https://github.com/denoland/deno/issues/18967#issuecomment-1761248941 This is an extremely rough initial implementation. Errors are terrible in this and the LSP requires frequent restarts. Improvements will be done in follow up PRs.
Diffstat (limited to 'cli/npm/mod.rs')
-rw-r--r--cli/npm/mod.rs21
1 files changed, 7 insertions, 14 deletions
diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs
index 81f46419e..761c99dba 100644
--- a/cli/npm/mod.rs
+++ b/cli/npm/mod.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+mod byonm;
mod cache_dir;
mod common;
mod managed;
@@ -12,17 +13,18 @@ use deno_core::error::AnyError;
use deno_runtime::deno_node::NpmResolver;
use deno_semver::package::PackageReq;
+pub use self::byonm::CliNpmResolverByonmCreateOptions;
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;
+use self::byonm::ByonmCliNpmResolver;
+
pub enum CliNpmResolverCreateOptions {
Managed(CliNpmResolverManagedCreateOptions),
- // todo(dsherret): implement this
- #[allow(dead_code)]
- Byonm,
+ Byonm(CliNpmResolverByonmCreateOptions),
}
pub async fn create_cli_npm_resolver_for_lsp(
@@ -33,7 +35,7 @@ pub async fn create_cli_npm_resolver_for_lsp(
Managed(options) => {
managed::create_managed_npm_resolver_for_lsp(options).await
}
- Byonm => todo!(),
+ Byonm(options) => byonm::create_byonm_npm_resolver(options),
}
}
@@ -43,7 +45,7 @@ pub async fn create_cli_npm_resolver(
use CliNpmResolverCreateOptions::*;
match options {
Managed(options) => managed::create_managed_npm_resolver(options).await,
- Byonm => todo!(),
+ Byonm(options) => Ok(byonm::create_byonm_npm_resolver(options)),
}
}
@@ -76,12 +78,6 @@ pub trait CliNpmResolver: NpmResolver {
fn root_node_modules_path(&self) -> Option<PathBuf>;
- /// 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,
@@ -95,6 +91,3 @@ pub trait CliNpmResolver: NpmResolver {
/// or `None` if the state currently can't be determined.
fn check_state_hash(&self) -> Option<u64>;
}
-
-// todo(#18967): implement this
-pub struct ByonmCliNpmResolver;