From be97170a193e8cecc5ce03ecd3c1d0add4a06bf7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 25 Oct 2023 14:39:00 -0400 Subject: 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. --- cli/tools/vendor/test.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'cli/tools') diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index 810daf4fb..73a4324cf 100644 --- a/cli/tools/vendor/test.rs +++ b/cli/tools/vendor/test.rs @@ -19,6 +19,7 @@ use deno_graph::source::LoadResponse; use deno_graph::source::Loader; use deno_graph::GraphKind; use deno_graph::ModuleGraph; +use deno_runtime::deno_fs::RealFs; use import_map::ImportMap; use crate::args::JsxImportSourceConfig; @@ -293,16 +294,17 @@ fn build_resolver( maybe_jsx_import_source_config: Option, original_import_map: Option, ) -> CliGraphResolver { - CliGraphResolver::new( - None, - Default::default(), - CliGraphResolverOptions { - maybe_jsx_import_source_config, - maybe_import_map: original_import_map.map(Arc::new), - maybe_vendor_dir: None, - bare_node_builtins_enabled: false, - }, - ) + CliGraphResolver::new(CliGraphResolverOptions { + fs: Arc::new(RealFs), + node_resolver: None, + npm_resolver: None, + cjs_resolutions: None, + package_json_deps_provider: Default::default(), + maybe_jsx_import_source_config, + maybe_import_map: original_import_map.map(Arc::new), + maybe_vendor_dir: None, + bare_node_builtins_enabled: false, + }) } async fn build_test_graph( -- cgit v1.2.3