feat(compile): unstable npm and node specifier support (#19005)

This is the initial support for npm and node specifiers in `deno
compile`. The npm packages are included in the binary and read from it via
a virtual file system. This also supports the `--node-modules-dir` flag,
dependencies specified in a package.json, and npm binary commands (ex.
`deno compile --unstable npm:cowsay`)

Closes #16632
This commit is contained in:
David Sherret 2023-05-10 20:06:59 -04:00 committed by GitHub
parent 5fd74bfa1c
commit 28aa489de9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 2733 additions and 261 deletions

View file

@ -46,6 +46,7 @@ use deno_semver::npm::NpmPackageReqReference;
use indexmap::IndexMap;
use lsp::Url;
use once_cell::sync::Lazy;
use package_json::PackageJsonDepsProvider;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
@ -1218,10 +1219,12 @@ impl Documents {
maybe_jsx_config.as_ref(),
maybe_package_json_deps.as_ref(),
);
let deps_provider =
Arc::new(PackageJsonDepsProvider::new(maybe_package_json_deps));
let deps_installer = Arc::new(PackageJsonDepsInstaller::new(
deps_provider.clone(),
npm_registry_api.clone(),
npm_resolution.clone(),
maybe_package_json_deps,
));
self.resolver = Arc::new(CliGraphResolver::new(
maybe_jsx_config,
@ -1229,6 +1232,7 @@ impl Documents {
false,
npm_registry_api,
npm_resolution,
deps_provider,
deps_installer,
));
self.imports = Arc::new(

View file

@ -457,8 +457,9 @@ fn create_lsp_structs(
));
let resolution =
Arc::new(NpmResolution::from_serialized(api.clone(), None, None));
let fs = Arc::new(deno_fs::RealFs);
let fs_resolver = create_npm_fs_resolver(
Arc::new(deno_fs::RealFs),
fs.clone(),
npm_cache.clone(),
&progress_bar,
registry_url.clone(),
@ -468,7 +469,12 @@ fn create_lsp_structs(
(
api,
npm_cache,
Arc::new(CliNpmResolver::new(resolution.clone(), fs_resolver, None)),
Arc::new(CliNpmResolver::new(
fs,
resolution.clone(),
fs_resolver,
None,
)),
resolution,
)
}
@ -711,6 +717,7 @@ impl Inner {
));
let node_fs = Arc::new(deno_fs::RealFs);
let npm_resolver = Arc::new(CliNpmResolver::new(
node_fs.clone(),
npm_resolution.clone(),
create_npm_fs_resolver(
node_fs.clone(),