From 419ce997a85367aee140d65ea8eba5b53b0b890d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 4 Jan 2023 13:24:50 +0100 Subject: [PATCH 01/60] feat: support node built-in module imports --- cli/cache/mod.rs | 12 +++++++++++- cli/proc_state.rs | 7 +++++++ node_builtin.js | 8 ++++++++ node_builtin.ts | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 node_builtin.js create mode 100644 node_builtin.ts diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 68bf1e4c62a6b4..9c98996eae77f6 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -103,7 +103,17 @@ impl Loader for FetchCacher { )); } - let specifier = specifier.clone(); + let specifier = if specifier.scheme() == "node" { + match crate::node::resolve_builtin_node_module( + specifier.as_str().strip_prefix("node:").unwrap(), + ) { + Ok(specifier) => specifier, + Err(err) => return Box::pin(futures::future::ready(Err(err))), + } + } else { + specifier.clone() + }; + let mut permissions = if is_dynamic { self.dynamic_permissions.clone() } else { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 5ec8bc4e3e8747..19064d71047f3c 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -591,6 +591,13 @@ impl ProcState { } } + // Built-in Node modules + if specifier.starts_with("node:") { + return node::resolve_builtin_node_module( + specifier.strip_prefix("node:").unwrap(), + ); + } + // FIXME(bartlomieju): this is a hacky way to provide compatibility with REPL // and `Deno.core.evalContext` API. Ideally we should always have a referrer filled // but sadly that's not the case due to missing APIs in V8. diff --git a/node_builtin.js b/node_builtin.js new file mode 100644 index 00000000000000..7ba49ab49da255 --- /dev/null +++ b/node_builtin.js @@ -0,0 +1,8 @@ +import fs from "node:fs"; + +try { + const data = fs.readFileSync("./node_builtin.ts", "utf8"); + console.log(data); +} catch (err) { + console.error(err); +} diff --git a/node_builtin.ts b/node_builtin.ts new file mode 100644 index 00000000000000..fbbb3129596d19 --- /dev/null +++ b/node_builtin.ts @@ -0,0 +1,8 @@ +import fs from "node:fs"; + +try { + const data = fs.readFileSync("./node_builtin.js", "utf8"); + console.log(data); +} catch (err) { + console.error(err); +} From 80adb4d70560524540a8eff578d176e7019732ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 4 Jan 2023 13:24:50 +0100 Subject: [PATCH 02/60] feat: support node built-in module imports --- cli/cache/mod.rs | 12 +++++++++++- cli/proc_state.rs | 7 +++++++ node_builtin.js | 8 ++++++++ node_builtin.ts | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 node_builtin.js create mode 100644 node_builtin.ts diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 68bf1e4c62a6b4..9c98996eae77f6 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -103,7 +103,17 @@ impl Loader for FetchCacher { )); } - let specifier = specifier.clone(); + let specifier = if specifier.scheme() == "node" { + match crate::node::resolve_builtin_node_module( + specifier.as_str().strip_prefix("node:").unwrap(), + ) { + Ok(specifier) => specifier, + Err(err) => return Box::pin(futures::future::ready(Err(err))), + } + } else { + specifier.clone() + }; + let mut permissions = if is_dynamic { self.dynamic_permissions.clone() } else { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 5ec8bc4e3e8747..19064d71047f3c 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -591,6 +591,13 @@ impl ProcState { } } + // Built-in Node modules + if specifier.starts_with("node:") { + return node::resolve_builtin_node_module( + specifier.strip_prefix("node:").unwrap(), + ); + } + // FIXME(bartlomieju): this is a hacky way to provide compatibility with REPL // and `Deno.core.evalContext` API. Ideally we should always have a referrer filled // but sadly that's not the case due to missing APIs in V8. diff --git a/node_builtin.js b/node_builtin.js new file mode 100644 index 00000000000000..7ba49ab49da255 --- /dev/null +++ b/node_builtin.js @@ -0,0 +1,8 @@ +import fs from "node:fs"; + +try { + const data = fs.readFileSync("./node_builtin.ts", "utf8"); + console.log(data); +} catch (err) { + console.error(err); +} diff --git a/node_builtin.ts b/node_builtin.ts new file mode 100644 index 00000000000000..fbbb3129596d19 --- /dev/null +++ b/node_builtin.ts @@ -0,0 +1,8 @@ +import fs from "node:fs"; + +try { + const data = fs.readFileSync("./node_builtin.js", "utf8"); + console.log(data); +} catch (err) { + console.error(err); +} From 44bddacf41ad2b9c526bc710c8da08df807053ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Jan 2023 02:27:32 +0100 Subject: [PATCH 03/60] [WIP] experiment: read package.json to discover dependencies for bare specifiers --- cli/args/flags.rs | 4 + cli/args/mod.rs | 4 + cli/proc_state.rs | 10 +- cli/resolver.rs | 34 ++ cli/worker.rs | 31 ++ ext/node/package_json.rs | 26 ++ foo.js | 3 + package-lock.json | 711 +++++++++++++++++++++++++++++++++++++++ package.json | 8 + 9 files changed, 829 insertions(+), 2 deletions(-) create mode 100644 foo.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/cli/args/flags.rs b/cli/args/flags.rs index f3ba85e45166a5..477ad44ae91d8f 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -329,6 +329,8 @@ pub struct Flags { pub version: bool, pub watch: Option>, pub no_clear_screen: bool, + + pub node: bool, } fn join_paths(allowlist: &[PathBuf], d: &str) -> String { @@ -1487,6 +1489,7 @@ fn run_subcommand<'a>() -> Command<'a> { ) .arg(no_clear_screen_arg()) .trailing_var_arg(true) + .arg(Arg::new("node").long("node")) .arg(script_arg().required(true)) .about("Run a JavaScript or TypeScript program") .long_about( @@ -2692,6 +2695,7 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.argv.push(v); } + flags.node = matches.is_present("node"); watch_arg_parse(flags, matches, true); flags.subcommand = DenoSubcommand::Run(RunFlags { script }); } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 97b70698ddb8ba..ef4cf427df731f 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -378,6 +378,10 @@ impl CliOptions { .and_then(|c| c.to_maybe_jsx_import_source_config()) } + pub fn node(&self) -> bool { + self.flags.node + } + /// Return any imports that should be brought into the scope of the module /// graph. pub fn to_maybe_imports(&self) -> MaybeImportsResult { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 19064d71047f3c..ba6d4030bd1bc0 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -332,9 +332,14 @@ impl ProcState { dynamic_permissions.clone(), ); let maybe_imports = self.options.to_maybe_imports()?; - let maybe_resolver = + let mut maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); + if self.options.node() { + maybe_resolver = + Some(crate::resolver::BareSpecifierResolver.as_graph_resolver()) + } + struct ProcStateLoader<'a> { inner: &'a mut cache::FetchCacher, graph_data: Arc>, @@ -412,7 +417,8 @@ impl ProcState { self.options.type_check_mode() != TypeCheckMode::None, check_js, ) - .unwrap()?; + .unwrap() + .context("Failed to check module graph")?; graph_data.npm_package_reqs().clone() }; diff --git a/cli/resolver.rs b/cli/resolver.rs index ec46165e02ba12..9615514c32046d 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -1,6 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::resolve_import; +use deno_core::ModuleResolutionError; use deno_core::ModuleSpecifier; use deno_graph::source::ResolveResponse; use deno_graph::source::Resolver; @@ -79,3 +80,36 @@ impl Resolver for CliResolver { } } } + +#[derive(Debug)] +pub struct BareSpecifierResolver; + +impl BareSpecifierResolver { + pub fn as_graph_resolver(&self) -> &dyn Resolver { + self + } +} + +impl Resolver for BareSpecifierResolver { + fn resolve( + &self, + specifier: &str, + referrer: &ModuleSpecifier, + ) -> ResolveResponse { + match resolve_import(specifier, referrer.as_str()) { + Ok(specifier) => ResolveResponse::Specifier(specifier), + Err(err) => match err { + ModuleResolutionError::ImportPrefixMissing(_, _) => { + ResolveResponse::Specifier( + resolve_import( + format!("npm:{}", specifier).as_str(), + referrer.as_str(), + ) + .unwrap(), + ) + } + _ => ResolveResponse::Err(err.into()), + }, + } + } +} diff --git a/cli/worker.rs b/cli/worker.rs index 0b991fdd68445b..7d4f07002d3c0e 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -3,6 +3,7 @@ use std::rc::Rc; use std::sync::Arc; use deno_ast::ModuleSpecifier; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::task::LocalFutureObj; use deno_core::futures::FutureExt; @@ -13,6 +14,7 @@ use deno_core::v8; use deno_core::Extension; use deno_core::ModuleId; use deno_runtime::colors; +use deno_runtime::deno_node::PackageJson; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; @@ -63,6 +65,35 @@ impl CliMainWorker { self.maybe_setup_coverage_collector().await?; log::debug!("main_module {}", self.main_module); + if self.ps.options.node() { + // We're in Node compat mode, try to find `package.json` and load it. + let package_json = PackageJson::load_skip_read_permission( + std::env::current_dir().unwrap().join("package.json"), + ) + .context("Unable to load package.json from CWD")?; + + if let Some(deps) = &package_json.dependencies { + let mut reqs = vec![]; + for (key, value) in deps { + let npm_ref = + NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + .unwrap(); + reqs.push(npm_ref.req); + } + self.ps.npm_resolver.add_package_reqs(reqs).await?; + } + if let Some(deps) = &package_json.dev_dependencies { + let mut reqs = vec![]; + for (key, value) in deps { + let npm_ref = + NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + .unwrap(); + reqs.push(npm_ref.req); + } + self.ps.npm_resolver.add_package_reqs(reqs).await?; + } + } + if self.is_main_cjs { self.ps.prepare_node_std_graph().await?; self.initialize_main_module_for_node().await?; diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs index f0a2b4f4dc6dca..f577ee26eec3c4 100644 --- a/ext/node/package_json.rs +++ b/ext/node/package_json.rs @@ -10,6 +10,7 @@ use deno_core::serde_json; use deno_core::serde_json::Map; use deno_core::serde_json::Value; use serde::Serialize; +use std::collections::HashMap; use std::io::ErrorKind; use std::path::PathBuf; @@ -26,6 +27,8 @@ pub struct PackageJson { pub path: PathBuf, pub typ: String, pub types: Option, + pub dependencies: Option>, + pub dev_dependencies: Option>, } impl PackageJson { @@ -42,6 +45,8 @@ impl PackageJson { path, typ: "none".to_string(), types: None, + dependencies: None, + dev_dependencies: None, } } @@ -100,6 +105,25 @@ impl PackageJson { let version = version_val.and_then(|s| s.as_str()).map(|s| s.to_string()); let module = module_val.and_then(|s| s.as_str()).map(|s| s.to_string()); + let dependencies = package_json.get("dependencies").and_then(|d| { + if d.is_object() { + let deps: HashMap = + serde_json::from_value(d.to_owned()).unwrap(); + Some(deps) + } else { + None + } + }); + let dev_dependencies = package_json.get("devDependencies").and_then(|d| { + if d.is_object() { + let deps: HashMap = + serde_json::from_value(d.to_owned()).unwrap(); + Some(deps) + } else { + None + } + }); + // Ignore unknown types for forwards compatibility let typ = if let Some(t) = type_val { if let Some(t) = t.as_str() { @@ -133,6 +157,8 @@ impl PackageJson { exports, imports, bin, + dependencies, + dev_dependencies, }; Ok(package_json) } diff --git a/foo.js b/foo.js new file mode 100644 index 00000000000000..53838926553470 --- /dev/null +++ b/foo.js @@ -0,0 +1,3 @@ +import cowsay from "cowsay"; + +console.log(cowsay); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000000000..d985284950afc2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,711 @@ +{ + "name": "deno", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "cowsay": "^1.5.0" + } + }, + "node_modules/ansi-regex": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", + "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "engines": { + "node": ">=4" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "engines": { + "node": ">=6" + } + }, + "node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/cliui/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/cowsay": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/cowsay/-/cowsay-1.5.0.tgz", + "integrity": "sha512-8Ipzr54Z8zROr/62C8f0PdhQcDusS05gKTS87xxdji8VbWefWly0k8BwGK7+VqamOrkv3eGsCkPtvlHzrhWsCA==", + "dependencies": { + "get-stdin": "8.0.0", + "string-width": "~2.1.1", + "strip-final-newline": "2.0.0", + "yargs": "15.4.1" + }, + "bin": { + "cowsay": "cli.js", + "cowthink": "cli.js" + }, + "engines": { + "node": ">= 4" + } + }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", + "engines": { + "node": ">=4" + } + }, + "node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, + "node_modules/string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dependencies": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", + "dependencies": { + "ansi-regex": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "engines": { + "node": ">=6" + } + }, + "node_modules/which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" + }, + "node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + }, + "node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/yargs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + } + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", + "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==" + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "requires": { + "ansi-regex": "^5.0.1" + } + } + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "cowsay": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/cowsay/-/cowsay-1.5.0.tgz", + "integrity": "sha512-8Ipzr54Z8zROr/62C8f0PdhQcDusS05gKTS87xxdji8VbWefWly0k8BwGK7+VqamOrkv3eGsCkPtvlHzrhWsCA==", + "requires": { + "get-stdin": "8.0.0", + "string-width": "~2.1.1", + "strip-final-newline": "2.0.0", + "yargs": "15.4.1" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==" + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==" + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==" + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "requires": { + "p-limit": "^2.2.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==" + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "requires": { + "ansi-regex": "^5.0.1" + } + } + } + }, + "y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "requires": { + "ansi-regex": "^5.0.1" + } + } + } + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000000000..ea1024629a383e --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "foobar", + "version": "0.0.1", + "type": "module", + "dependencies": { + "cowsay": "^1.5.0" + } +} From 23287d51ecaea22cdb8af673e435add02c693fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 6 Jan 2023 22:16:26 +0100 Subject: [PATCH 04/60] temp --- foo2.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 foo2.js diff --git a/foo2.js b/foo2.js new file mode 100644 index 00000000000000..866975c39d6360 --- /dev/null +++ b/foo2.js @@ -0,0 +1 @@ +imp; From 8ffe400265fad0ccb4012ca61f832a42c1b3a8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 7 Jan 2023 18:09:52 +0100 Subject: [PATCH 05/60] check if is cjs --- cli/worker.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/worker.rs b/cli/worker.rs index e664a959700d81..99b0210d4ff607 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -72,6 +72,8 @@ impl CliMainWorker { ) .context("Unable to load package.json from CWD")?; + self.is_main_cjs = package_json.typ != "module"; + if let Some(deps) = &package_json.dependencies { let mut reqs = vec![]; for (key, value) in deps { From 26cdd9831a6373c980c3a3e8df5ff189ab70a456 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 10 Jan 2023 16:36:56 -0500 Subject: [PATCH 06/60] Add half of typescript support. --- cli/build.rs | 53 +++++++++++++++++++++++++++++++++++++ cli/cache/mod.rs | 19 +++++++------ cli/lsp/diagnostics.rs | 9 +++++++ cli/proc_state.rs | 6 ++--- cli/tsc/00_typescript.js | 15 ++++++++++- cli/tsc/99_main_compiler.js | 6 +++-- cli/tsc/compiler.d.ts | 1 + 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index 24898a7a1bdebb..a7e9b6b99dc540 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -153,10 +153,63 @@ mod ts { #[op] fn op_build_info(state: &mut OpState) -> Value { let build_specifier = "asset:///bootstrap.ts"; + // todo(dsherret): this is a temporary solution as we should have a + // single source of truth for this stored in the Rust code that we + // send to TypeScript, but from cli/build.rs we can't access anything + // in the CLI crate. When refactoring that code out of the CLI, then + // we can use that information here. + let node_built_in_module_names = vec![ + "assert", + "assert/strict", + "async_hooks", + "buffer", + "child_process", + "cluster", + "console", + "constants", + "crypto", + "dgram", + "dns", + "dns/promises", + "domain", + "events", + "fs", + "fs/promises", + "http", + "https", + "module", + "net", + "os", + "path", + "path/posix", + "path/win32", + "perf_hooks", + "process", + "querystring", + "readline", + "stream", + "stream/consumers", + "stream/promises", + "stream/web", + "string_decoder", + "sys", + "timers", + "timers/promises", + "tls", + "tty", + "url", + "util", + "util/types", + "v8", + "vm", + "worker_threads", + "zlib", + ]; let build_libs = state.borrow::>(); json!({ "buildSpecifier": build_specifier, "libs": build_libs, + "nodeBuiltInModuleNames": node_built_in_module_names, }) } diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index c1a4a5a4a30de2..52fa61246d2d18 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -101,16 +101,15 @@ impl Loader for FetchCacher { )); } - let specifier = if specifier.scheme() == "node" { - match crate::node::resolve_builtin_node_module( - specifier.as_str().strip_prefix("node:").unwrap(), - ) { - Ok(specifier) => specifier, - Err(err) => return Box::pin(futures::future::ready(Err(err))), - } - } else { - specifier.clone() - }; + let specifier = + if let Some(module_name) = specifier.as_str().strip_prefix("node:") { + match crate::node::resolve_builtin_node_module(module_name) { + Ok(specifier) => specifier, + Err(err) => return Box::pin(futures::future::ready(Err(err))), + } + } else { + specifier.clone() + }; let permissions = if is_dynamic { self.dynamic_permissions.clone() diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 605bd85ac26d73..4b4ef5800d5b50 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -13,6 +13,7 @@ use super::tsc; use super::tsc::TsServer; use crate::args::LintOptions; +use crate::node; use crate::npm::NpmPackageReference; use crate::tools::lint::get_configured_rules; @@ -874,6 +875,14 @@ fn diagnose_resolved( ); } } + } else if let Some(module_name) = specifier.as_str().strip_prefix("node:") + { + if node::resolve_builtin_node_module(module_name).is_err() { + diagnostics.push( + DenoDiagnostic::NoCache(specifier.clone()) + .to_lsp_diagnostic(&range), + ); + } } else { // When the document is not available, it means that it cannot be found // in the cache or locally on the disk, so we want to issue a diagnostic diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 2c249d1aa789ce..0cc41f006ebf0c 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -621,10 +621,8 @@ impl ProcState { } // Built-in Node modules - if specifier.starts_with("node:") { - return node::resolve_builtin_node_module( - specifier.strip_prefix("node:").unwrap(), - ); + if let Some(module_name) = specifier.strip_prefix("node:") { + return node::resolve_builtin_node_module(module_name); } // FIXME(bartlomieju): this is a hacky way to provide compatibility with REPL diff --git a/cli/tsc/00_typescript.js b/cli/tsc/00_typescript.js index 789de3a66af134..3fbf4624a2b952 100644 --- a/cli/tsc/00_typescript.js +++ b/cli/tsc/00_typescript.js @@ -91389,10 +91389,15 @@ var ts; var deno; (function (deno) { var isNodeSourceFile = function () { return false; }; + var nodeBuiltInModuleNames = new ts.Set(); function setIsNodeSourceFileCallback(callback) { isNodeSourceFile = callback; } deno.setIsNodeSourceFileCallback = setIsNodeSourceFileCallback; + function setNodeBuiltInModuleNames(names) { + nodeBuiltInModuleNames = new ts.Set(names); + } + deno.setNodeBuiltInModuleNames = setNodeBuiltInModuleNames; // When upgrading: // 1. Inspect all usages of "globals" and "globalThisSymbol" in checker.ts // - Beware that `globalThisType` might refer to the global `this` type @@ -91452,8 +91457,16 @@ var ts; function getGlobalsForName(id) { // Node ambient modules are only accessible in the node code, // so put them on the node globals - if (ambientModuleSymbolRegex.test(id)) + if (ambientModuleSymbolRegex.test(id)) { + if (id.startsWith('"node:')) { + // check if it's a node specifier that we support + var name = id.slice(6, -1); + if (nodeBuiltInModuleNames.has(name)) { + return globals; + } + } return nodeGlobals; + } return nodeOnlyGlobalNames.has(id) ? nodeGlobals : globals; } function mergeGlobalSymbolTable(node, source, unidirectional) { diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index a3cdad742ec913..bf256ff20dca43 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -1267,9 +1267,11 @@ delete Object.prototype.__proto__; // A build time only op that provides some setup information that is used to // ensure the snapshot is setup properly. - /** @type {{ buildSpecifier: string; libs: string[] }} */ + /** @type {{ buildSpecifier: string; libs: string[]; nodeBuiltInModuleNames: string[] }} */ + const { buildSpecifier, libs, nodeBuiltInModuleNames } = ops.op_build_info(); + + ts.deno.setNodeBuiltInModuleNames(nodeBuiltInModuleNames); - const { buildSpecifier, libs } = ops.op_build_info(); for (const lib of libs) { const specifier = `lib.${lib}.d.ts`; // we are using internal APIs here to "inject" our custom libraries into diff --git a/cli/tsc/compiler.d.ts b/cli/tsc/compiler.d.ts index ab6f95bd359553..03784ae84b3ea9 100644 --- a/cli/tsc/compiler.d.ts +++ b/cli/tsc/compiler.d.ts @@ -30,6 +30,7 @@ declare global { function setIsNodeSourceFileCallback( callback: (sourceFile: SourceFile) => boolean, ); + function setNodeBuiltInModuleNames(names: string[]); } } From d40b7e0f20769196fda9e17570a3582da1dc56c0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 10 Jan 2023 19:15:14 -0500 Subject: [PATCH 07/60] Adding automatic @types/node package resolution - Note: Not working in lsp... wee need to somehow tell typescript to load this package's type declarations so it will get the ambient modules --- cli/cache/mod.rs | 9 +++++++++ cli/graph_util.rs | 11 +++++++++++ cli/lsp/documents.rs | 17 +++++++++++++++-- cli/node/mod.rs | 1 + cli/proc_state.rs | 18 ++++++++++++++++-- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 52fa61246d2d18..e2c461d6c4ae81 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -103,6 +103,15 @@ impl Loader for FetchCacher { let specifier = if let Some(module_name) = specifier.as_str().strip_prefix("node:") { + if module_name == "module" { + // We use the built-in module for "module", so resolve it as external + return Box::pin(futures::future::ready(Ok(Some( + deno_graph::source::LoadResponse::External { + specifier: specifier.clone(), + }, + )))); + } + match crate::node::resolve_builtin_node_module(module_name) { Ok(specifier) => specifier, Err(err) => return Box::pin(futures::future::ready(Err(err))), diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 35eaae1274713e..c0c1f7399b0c44 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -63,6 +63,7 @@ pub enum ModuleEntry { pub struct GraphData { modules: HashMap, npm_packages: Vec, + has_node_specifier: bool, /// Map of first known referrer locations for each module. Used to enhance /// error messages. referrer_map: HashMap>, @@ -96,6 +97,10 @@ impl GraphData { continue; } + if !self.has_node_specifier && specifier.scheme() == "node" { + self.has_node_specifier = true; + } + if self.modules.contains_key(specifier) { continue; } @@ -165,6 +170,11 @@ impl GraphData { self.modules.iter() } + /// Gets if the graph had a "node:" specifier. + pub fn has_node_specifier(&self) -> bool { + self.has_node_specifier + } + /// Gets the npm package requirements from all the encountered graphs /// in the order that they should be resolved. pub fn npm_package_reqs(&self) -> &Vec { @@ -292,6 +302,7 @@ impl GraphData { } Some(Self { modules, + has_node_specifier: self.has_node_specifier, npm_packages: self.npm_packages.clone(), referrer_map, graph_imports: self.graph_imports.to_vec(), diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 92dfdf54337054..5cb7bac7557988 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1129,6 +1129,7 @@ impl Documents { analyzed_specifiers: HashSet, pending_specifiers: VecDeque, npm_reqs: HashSet, + has_node_specifier: bool, } impl DocAnalyzer { @@ -1152,7 +1153,11 @@ impl Documents { fn analyze_doc(&mut self, specifier: &ModuleSpecifier, doc: &Document) { self.analyzed_specifiers.insert(specifier.clone()); - for dependency in doc.dependencies().values() { + for (name, dependency) in doc.dependencies() { + if !self.has_node_specifier && name.starts_with("node:") { + self.has_node_specifier = true; + } + if let Some(dep) = dependency.get_code() { self.add(dep, specifier); } @@ -1189,8 +1194,16 @@ impl Documents { } } + let mut npm_reqs = doc_analyzer.npm_reqs; + // ensure a @types/node package exists when any module uses a node: specifier + if doc_analyzer.has_node_specifier + && !npm_reqs.iter().any(|r| r.name == "@types/node") + { + npm_reqs.insert(NpmPackageReq::from_str("@types/node").unwrap()); + } + self.dependents_map = Arc::new(doc_analyzer.dependents_map); - self.npm_reqs = Arc::new(doc_analyzer.npm_reqs); + self.npm_reqs = Arc::new(npm_reqs); self.dirty = false; file_system_docs.dirty = false; } diff --git a/cli/node/mod.rs b/cli/node/mod.rs index aed639bc48769c..916319ceb3fc1b 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -114,6 +114,7 @@ struct NodeModulePolyfill { specifier: &'static str, } +// note: also update build.rs if adding a module here static SUPPORTED_MODULES: &[NodeModulePolyfill] = &[ NodeModulePolyfill { name: "assert", diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 0cc41f006ebf0c..fdbfbef7a47067 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -26,6 +26,7 @@ use crate::node::NodeResolution; use crate::npm::resolve_npm_package_reqs; use crate::npm::NpmCache; use crate::npm::NpmPackageReference; +use crate::npm::NpmPackageReq; use crate::npm::NpmPackageResolver; use crate::npm::RealNpmRegistryApi; use crate::resolver::CliResolver; @@ -429,7 +430,7 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; - let npm_package_reqs = { + let (mut npm_package_reqs, has_node_specifier) = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); let check_js = self.options.check_js(); @@ -440,9 +441,22 @@ impl ProcState { check_js, ) .unwrap()?; - graph_data.npm_package_reqs().clone() + ( + graph_data.npm_package_reqs().clone(), + graph_data.has_node_specifier(), + ) }; + // add a @types/node package if the code has a "node:" specifier, + // the code is type checking, and there aren't any existing @types/node + // packages specified + if has_node_specifier + && self.options.type_check_mode() != TypeCheckMode::None + && !npm_package_reqs.iter().any(|r| r.name == "@types/node") + { + npm_package_reqs.push(NpmPackageReq::from_str("@types/node").unwrap()); + } + if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; self.prepare_node_std_graph().await?; From 1082f868fd225c8c6516404bdeface02aebc761f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 11 Jan 2023 14:18:45 -0500 Subject: [PATCH 08/60] Update name. --- cli/graph_util.rs | 12 ++++++------ cli/lsp/documents.rs | 8 ++++---- cli/proc_state.rs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index c0c1f7399b0c44..93d4865dc65a67 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -63,7 +63,7 @@ pub enum ModuleEntry { pub struct GraphData { modules: HashMap, npm_packages: Vec, - has_node_specifier: bool, + has_node_builtin_specifier: bool, /// Map of first known referrer locations for each module. Used to enhance /// error messages. referrer_map: HashMap>, @@ -97,8 +97,8 @@ impl GraphData { continue; } - if !self.has_node_specifier && specifier.scheme() == "node" { - self.has_node_specifier = true; + if !self.has_node_builtin_specifier && specifier.scheme() == "node" { + self.has_node_builtin_specifier = true; } if self.modules.contains_key(specifier) { @@ -171,8 +171,8 @@ impl GraphData { } /// Gets if the graph had a "node:" specifier. - pub fn has_node_specifier(&self) -> bool { - self.has_node_specifier + pub fn has_node_builtin_specifier(&self) -> bool { + self.has_node_builtin_specifier } /// Gets the npm package requirements from all the encountered graphs @@ -302,7 +302,7 @@ impl GraphData { } Some(Self { modules, - has_node_specifier: self.has_node_specifier, + has_node_builtin_specifier: self.has_node_builtin_specifier, npm_packages: self.npm_packages.clone(), referrer_map, graph_imports: self.graph_imports.to_vec(), diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 5cb7bac7557988..dad7cf46530738 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1129,7 +1129,7 @@ impl Documents { analyzed_specifiers: HashSet, pending_specifiers: VecDeque, npm_reqs: HashSet, - has_node_specifier: bool, + has_node_builtin_specifier: bool, } impl DocAnalyzer { @@ -1154,8 +1154,8 @@ impl Documents { fn analyze_doc(&mut self, specifier: &ModuleSpecifier, doc: &Document) { self.analyzed_specifiers.insert(specifier.clone()); for (name, dependency) in doc.dependencies() { - if !self.has_node_specifier && name.starts_with("node:") { - self.has_node_specifier = true; + if !self.has_node_builtin_specifier && name.starts_with("node:") { + self.has_node_builtin_specifier = true; } if let Some(dep) = dependency.get_code() { @@ -1196,7 +1196,7 @@ impl Documents { let mut npm_reqs = doc_analyzer.npm_reqs; // ensure a @types/node package exists when any module uses a node: specifier - if doc_analyzer.has_node_specifier + if doc_analyzer.has_node_builtin_specifier && !npm_reqs.iter().any(|r| r.name == "@types/node") { npm_reqs.insert(NpmPackageReq::from_str("@types/node").unwrap()); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index fdbfbef7a47067..477a7f463c8df0 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -430,7 +430,7 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; - let (mut npm_package_reqs, has_node_specifier) = { + let (mut npm_package_reqs, has_node_builtin_specifier) = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); let check_js = self.options.check_js(); @@ -443,14 +443,14 @@ impl ProcState { .unwrap()?; ( graph_data.npm_package_reqs().clone(), - graph_data.has_node_specifier(), + graph_data.has_node_builtin_specifier(), ) }; // add a @types/node package if the code has a "node:" specifier, // the code is type checking, and there aren't any existing @types/node // packages specified - if has_node_specifier + if has_node_builtin_specifier && self.options.type_check_mode() != TypeCheckMode::None && !npm_package_reqs.iter().any(|r| r.name == "@types/node") { From cb2d000ac702887b1c4f714b5c7844aceeed0f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 11 Jan 2023 22:28:53 +0100 Subject: [PATCH 09/60] move NodeModulePolyfill to ext/node --- cli/build.rs | 58 ++------------ cli/node/mod.rs | 201 ++---------------------------------------------- ext/node/lib.rs | 194 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 248 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index a7e9b6b99dc540..baafcc45701d9d 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -17,6 +17,7 @@ mod ts { use deno_core::error::AnyError; use deno_core::op; use deno_core::OpState; + use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES; use regex::Regex; use serde::Deserialize; use serde_json::json; @@ -153,58 +154,11 @@ mod ts { #[op] fn op_build_info(state: &mut OpState) -> Value { let build_specifier = "asset:///bootstrap.ts"; - // todo(dsherret): this is a temporary solution as we should have a - // single source of truth for this stored in the Rust code that we - // send to TypeScript, but from cli/build.rs we can't access anything - // in the CLI crate. When refactoring that code out of the CLI, then - // we can use that information here. - let node_built_in_module_names = vec![ - "assert", - "assert/strict", - "async_hooks", - "buffer", - "child_process", - "cluster", - "console", - "constants", - "crypto", - "dgram", - "dns", - "dns/promises", - "domain", - "events", - "fs", - "fs/promises", - "http", - "https", - "module", - "net", - "os", - "path", - "path/posix", - "path/win32", - "perf_hooks", - "process", - "querystring", - "readline", - "stream", - "stream/consumers", - "stream/promises", - "stream/web", - "string_decoder", - "sys", - "timers", - "timers/promises", - "tls", - "tty", - "url", - "util", - "util/types", - "v8", - "vm", - "worker_threads", - "zlib", - ]; + + let node_built_in_module_names = SUPPORTED_BUILTIN_NODE_MODULES + .iter() + .map(|s| s.name) + .collect::>(); let build_libs = state.borrow::>(); json!({ "buildSpecifier": build_specifier, diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 916319ceb3fc1b..48f857a41e9d7e 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -25,6 +25,7 @@ use deno_runtime::deno_node::package_imports_resolve; use deno_runtime::deno_node::package_resolve; use deno_runtime::deno_node::path_to_declaration_path; use deno_runtime::deno_node::NodeModuleKind; +use deno_runtime::deno_node::NodeModulePolyfill; use deno_runtime::deno_node::NodePermissions; use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::PackageJson; @@ -32,6 +33,7 @@ use deno_runtime::deno_node::PathClean; use deno_runtime::deno_node::RequireNpmResolver; use deno_runtime::deno_node::DEFAULT_CONDITIONS; use deno_runtime::deno_node::NODE_GLOBAL_THIS_NAME; +use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES; use deno_runtime::permissions::PermissionsContainer; use once_cell::sync::Lazy; use regex::Regex; @@ -106,201 +108,6 @@ impl NodeResolution { } } -struct NodeModulePolyfill { - /// Name of the module like "assert" or "timers/promises" - name: &'static str, - - /// Specifier relative to the root of `deno_std` repo, like "node/asser.ts" - specifier: &'static str, -} - -// note: also update build.rs if adding a module here -static SUPPORTED_MODULES: &[NodeModulePolyfill] = &[ - NodeModulePolyfill { - name: "assert", - specifier: "node/assert.ts", - }, - NodeModulePolyfill { - name: "assert/strict", - specifier: "node/assert/strict.ts", - }, - NodeModulePolyfill { - name: "async_hooks", - specifier: "node/async_hooks.ts", - }, - NodeModulePolyfill { - name: "buffer", - specifier: "node/buffer.ts", - }, - NodeModulePolyfill { - name: "child_process", - specifier: "node/child_process.ts", - }, - NodeModulePolyfill { - name: "cluster", - specifier: "node/cluster.ts", - }, - NodeModulePolyfill { - name: "console", - specifier: "node/console.ts", - }, - NodeModulePolyfill { - name: "constants", - specifier: "node/constants.ts", - }, - NodeModulePolyfill { - name: "crypto", - specifier: "node/crypto.ts", - }, - NodeModulePolyfill { - name: "dgram", - specifier: "node/dgram.ts", - }, - NodeModulePolyfill { - name: "dns", - specifier: "node/dns.ts", - }, - NodeModulePolyfill { - name: "dns/promises", - specifier: "node/dns/promises.ts", - }, - NodeModulePolyfill { - name: "domain", - specifier: "node/domain.ts", - }, - NodeModulePolyfill { - name: "events", - specifier: "node/events.ts", - }, - NodeModulePolyfill { - name: "fs", - specifier: "node/fs.ts", - }, - NodeModulePolyfill { - name: "fs/promises", - specifier: "node/fs/promises.ts", - }, - NodeModulePolyfill { - name: "http", - specifier: "node/http.ts", - }, - NodeModulePolyfill { - name: "https", - specifier: "node/https.ts", - }, - NodeModulePolyfill { - name: "module", - // NOTE(bartlomieju): `module` is special, because we don't want to use - // `deno_std/node/module.ts`, but instead use a special shim that we - // provide in `ext/node`. - specifier: "[USE `deno_node::MODULE_ES_SHIM` to get this module]", - }, - NodeModulePolyfill { - name: "net", - specifier: "node/net.ts", - }, - NodeModulePolyfill { - name: "os", - specifier: "node/os.ts", - }, - NodeModulePolyfill { - name: "path", - specifier: "node/path.ts", - }, - NodeModulePolyfill { - name: "path/posix", - specifier: "node/path/posix.ts", - }, - NodeModulePolyfill { - name: "path/win32", - specifier: "node/path/win32.ts", - }, - NodeModulePolyfill { - name: "perf_hooks", - specifier: "node/perf_hooks.ts", - }, - NodeModulePolyfill { - name: "process", - specifier: "node/process.ts", - }, - NodeModulePolyfill { - name: "querystring", - specifier: "node/querystring.ts", - }, - NodeModulePolyfill { - name: "readline", - specifier: "node/readline.ts", - }, - NodeModulePolyfill { - name: "stream", - specifier: "node/stream.ts", - }, - NodeModulePolyfill { - name: "stream/consumers", - specifier: "node/stream/consumers.mjs", - }, - NodeModulePolyfill { - name: "stream/promises", - specifier: "node/stream/promises.mjs", - }, - NodeModulePolyfill { - name: "stream/web", - specifier: "node/stream/web.ts", - }, - NodeModulePolyfill { - name: "string_decoder", - specifier: "node/string_decoder.ts", - }, - NodeModulePolyfill { - name: "sys", - specifier: "node/sys.ts", - }, - NodeModulePolyfill { - name: "timers", - specifier: "node/timers.ts", - }, - NodeModulePolyfill { - name: "timers/promises", - specifier: "node/timers/promises.ts", - }, - NodeModulePolyfill { - name: "tls", - specifier: "node/tls.ts", - }, - NodeModulePolyfill { - name: "tty", - specifier: "node/tty.ts", - }, - NodeModulePolyfill { - name: "url", - specifier: "node/url.ts", - }, - NodeModulePolyfill { - name: "util", - specifier: "node/util.ts", - }, - NodeModulePolyfill { - name: "util/types", - specifier: "node/util/types.ts", - }, - NodeModulePolyfill { - name: "v8", - specifier: "node/v8.ts", - }, - NodeModulePolyfill { - name: "vm", - specifier: "node/vm.ts", - }, - NodeModulePolyfill { - name: "worker_threads", - specifier: "node/worker_threads.ts", - }, - NodeModulePolyfill { - name: "zlib", - specifier: "node/zlib.ts", - }, -]; - static NODE_COMPAT_URL: Lazy = Lazy::new(|| { if let Ok(url_str) = std::env::var("DENO_NODE_COMPAT_URL") { let url = Url::parse(&url_str).expect( @@ -316,7 +123,9 @@ pub static MODULE_ALL_URL: Lazy = Lazy::new(|| NODE_COMPAT_URL.join("node/module_all.ts").unwrap()); fn find_builtin_node_module(specifier: &str) -> Option<&NodeModulePolyfill> { - SUPPORTED_MODULES.iter().find(|m| m.name == specifier) + SUPPORTED_BUILTIN_NODE_MODULES + .iter() + .find(|m| m.name == specifier) } fn is_builtin_node_module(specifier: &str) -> bool { diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 8a36e95fa27fde..dbf7984e4590b2 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -675,3 +675,197 @@ fn op_require_break_on_next_statement(state: &mut OpState) { .borrow_mut() .wait_for_session_and_break_on_next_statement() } + +pub struct NodeModulePolyfill { + /// Name of the module like "assert" or "timers/promises" + pub name: &'static str, + + /// Specifier relative to the root of `deno_std` repo, like "node/asser.ts" + pub specifier: &'static str, +} + +pub static SUPPORTED_BUILTIN_NODE_MODULES: &[NodeModulePolyfill] = &[ + NodeModulePolyfill { + name: "assert", + specifier: "node/assert.ts", + }, + NodeModulePolyfill { + name: "assert/strict", + specifier: "node/assert/strict.ts", + }, + NodeModulePolyfill { + name: "async_hooks", + specifier: "node/async_hooks.ts", + }, + NodeModulePolyfill { + name: "buffer", + specifier: "node/buffer.ts", + }, + NodeModulePolyfill { + name: "child_process", + specifier: "node/child_process.ts", + }, + NodeModulePolyfill { + name: "cluster", + specifier: "node/cluster.ts", + }, + NodeModulePolyfill { + name: "console", + specifier: "node/console.ts", + }, + NodeModulePolyfill { + name: "constants", + specifier: "node/constants.ts", + }, + NodeModulePolyfill { + name: "crypto", + specifier: "node/crypto.ts", + }, + NodeModulePolyfill { + name: "dgram", + specifier: "node/dgram.ts", + }, + NodeModulePolyfill { + name: "dns", + specifier: "node/dns.ts", + }, + NodeModulePolyfill { + name: "dns/promises", + specifier: "node/dns/promises.ts", + }, + NodeModulePolyfill { + name: "domain", + specifier: "node/domain.ts", + }, + NodeModulePolyfill { + name: "events", + specifier: "node/events.ts", + }, + NodeModulePolyfill { + name: "fs", + specifier: "node/fs.ts", + }, + NodeModulePolyfill { + name: "fs/promises", + specifier: "node/fs/promises.ts", + }, + NodeModulePolyfill { + name: "http", + specifier: "node/http.ts", + }, + NodeModulePolyfill { + name: "https", + specifier: "node/https.ts", + }, + NodeModulePolyfill { + name: "module", + // NOTE(bartlomieju): `module` is special, because we don't want to use + // `deno_std/node/module.ts`, but instead use a special shim that we + // provide in `ext/node`. + specifier: "[USE `deno_node::MODULE_ES_SHIM` to get this module]", + }, + NodeModulePolyfill { + name: "net", + specifier: "node/net.ts", + }, + NodeModulePolyfill { + name: "os", + specifier: "node/os.ts", + }, + NodeModulePolyfill { + name: "path", + specifier: "node/path.ts", + }, + NodeModulePolyfill { + name: "path/posix", + specifier: "node/path/posix.ts", + }, + NodeModulePolyfill { + name: "path/win32", + specifier: "node/path/win32.ts", + }, + NodeModulePolyfill { + name: "perf_hooks", + specifier: "node/perf_hooks.ts", + }, + NodeModulePolyfill { + name: "process", + specifier: "node/process.ts", + }, + NodeModulePolyfill { + name: "querystring", + specifier: "node/querystring.ts", + }, + NodeModulePolyfill { + name: "readline", + specifier: "node/readline.ts", + }, + NodeModulePolyfill { + name: "stream", + specifier: "node/stream.ts", + }, + NodeModulePolyfill { + name: "stream/consumers", + specifier: "node/stream/consumers.mjs", + }, + NodeModulePolyfill { + name: "stream/promises", + specifier: "node/stream/promises.mjs", + }, + NodeModulePolyfill { + name: "stream/web", + specifier: "node/stream/web.ts", + }, + NodeModulePolyfill { + name: "string_decoder", + specifier: "node/string_decoder.ts", + }, + NodeModulePolyfill { + name: "sys", + specifier: "node/sys.ts", + }, + NodeModulePolyfill { + name: "timers", + specifier: "node/timers.ts", + }, + NodeModulePolyfill { + name: "timers/promises", + specifier: "node/timers/promises.ts", + }, + NodeModulePolyfill { + name: "tls", + specifier: "node/tls.ts", + }, + NodeModulePolyfill { + name: "tty", + specifier: "node/tty.ts", + }, + NodeModulePolyfill { + name: "url", + specifier: "node/url.ts", + }, + NodeModulePolyfill { + name: "util", + specifier: "node/util.ts", + }, + NodeModulePolyfill { + name: "util/types", + specifier: "node/util/types.ts", + }, + NodeModulePolyfill { + name: "v8", + specifier: "node/v8.ts", + }, + NodeModulePolyfill { + name: "vm", + specifier: "node/vm.ts", + }, + NodeModulePolyfill { + name: "worker_threads", + specifier: "node/worker_threads.ts", + }, + NodeModulePolyfill { + name: "zlib", + specifier: "node/zlib.ts", + }, +]; From 08a661d1f3c6d1a28028accd63d1dd87f1c00c4b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 13 Jan 2023 16:42:12 -0500 Subject: [PATCH 10/60] Make node: specifiers use the @types/node ambient module for `deno check` --- cli/tools/check.rs | 19 +++- cli/tsc/99_main_compiler.js | 20 +--- cli/tsc/mod.rs | 214 ++++++++++++++++++++---------------- 3 files changed, 132 insertions(+), 121 deletions(-) diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 6e2ccd4ffe3fd4..23e9abdeecbdac 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -233,10 +233,16 @@ fn get_tsc_roots( graph_data: &GraphData, check_js: bool, ) -> Vec<(ModuleSpecifier, MediaType)> { - graph_data - .entries() - .into_iter() - .filter_map(|(specifier, module_entry)| match module_entry { + let mut result = Vec::new(); + if graph_data.has_node_builtin_specifier() { + // inject a specifier that will resolve node types + result.push(( + ModuleSpecifier::parse("deno:///node_types.d.ts").unwrap(), + MediaType::Dts, + )); + } + result.extend(graph_data.entries().into_iter().filter_map( + |(specifier, module_entry)| match module_entry { ModuleEntry::Module { media_type, code, .. } => match media_type { @@ -253,8 +259,9 @@ fn get_tsc_roots( _ => None, }, _ => None, - }) - .collect() + }, + )); + result } /// Matches the `@ts-check` pragma. diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index bf256ff20dca43..de8a4d8cbaa2ad 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -854,25 +854,7 @@ delete Object.prototype.__proto__; ...program.getOptionsDiagnostics(), ...program.getGlobalDiagnostics(), ...program.getSemanticDiagnostics(), - ].filter((diagnostic) => { - if (IGNORED_DIAGNOSTICS.includes(diagnostic.code)) { - return false; - } else if ( - diagnostic.code === 1259 && - typeof diagnostic.messageText === "string" && - diagnostic.messageText.startsWith( - "Module '\"deno:///missing_dependency.d.ts\"' can only be default-imported using the 'allowSyntheticDefaultImports' flag", - ) - ) { - // For now, ignore diagnostics like: - // > TS1259 [ERROR]: Module '"deno:///missing_dependency.d.ts"' can only be default-imported using the 'allowSyntheticDefaultImports' flag - // This diagnostic has surfaced due to supporting node cjs imports because this module does `export =`. - // See discussion in https://github.com/microsoft/TypeScript/pull/51136 - return false; - } else { - return true; - } - }); + ].filter((diagnostic) => !IGNORED_DIAGNOSTICS.includes(diagnostic.code)); // emit the tsbuildinfo file // @ts-ignore: emitBuildInfo is not exposed (https://github.com/microsoft/TypeScript/issues/49871) diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 6ea037522d24e0..f96346f01b431d 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -501,6 +501,12 @@ fn op_load(state: &mut OpState, args: Value) -> Result { hash = Some("1".to_string()); media_type = MediaType::Dts; Some(Cow::Borrowed("declare const __: any;\nexport = __;\n")) + } else if &v.specifier == "deno:///node_types.d.ts" { + hash = Some("1".to_string()); + media_type = MediaType::Dts; + Some(Cow::Borrowed( + "/// \n", + )) } else if v.specifier.starts_with("asset:///") { let name = v.specifier.replace("asset:///", ""); let maybe_source = get_asset(&name); @@ -581,117 +587,133 @@ fn op_resolve( "Error converting a string module specifier for \"op_resolve\".", )? }; - for specifier in &args.specifiers { + for specifier in args.specifiers { + if let Some(module_name) = specifier.strip_prefix("node:") { + if crate::node::resolve_builtin_node_module(module_name).is_ok() { + // return itself for node: specifiers because during type checking + // we resolve to the ambient modules in the @types/node package + // rather than deno_std/node + resolved.push((specifier, MediaType::Dts.to_string())); + continue; + } + } + if specifier.starts_with("asset:///") { - resolved.push(( - specifier.clone(), - MediaType::from(specifier).as_ts_extension().to_string(), - )); - } else { - let graph_data = state.graph_data.read(); - let resolved_dep = match graph_data.get_dependencies(&referrer) { - Some(dependencies) => dependencies.get(specifier).map(|d| { - if matches!(d.maybe_type, Resolved::Ok { .. }) { - &d.maybe_type - } else { - &d.maybe_code - } - }), - None => None, - }; - let maybe_result = match resolved_dep { - Some(Resolved::Ok { specifier, .. }) => { - let specifier = graph_data.follow_redirect(specifier); - match graph_data.get(&specifier) { - Some(ModuleEntry::Module { - media_type, - maybe_types, - .. - }) => match maybe_types { - Some(Resolved::Ok { specifier, .. }) => { - let types = graph_data.follow_redirect(specifier); - match graph_data.get(&types) { - Some(ModuleEntry::Module { media_type, .. }) => { - Some((types, *media_type)) - } - _ => None, + let media_type = + MediaType::from(&specifier).as_ts_extension().to_string(); + resolved.push((specifier, media_type)); + continue; + } + + let graph_data = state.graph_data.read(); + let resolved_dep = match graph_data.get_dependencies(&referrer) { + Some(dependencies) => dependencies.get(&specifier).map(|d| { + if matches!(d.maybe_type, Resolved::Ok { .. }) { + &d.maybe_type + } else { + &d.maybe_code + } + }), + None => None, + }; + let maybe_result = match resolved_dep { + Some(Resolved::Ok { specifier, .. }) => { + let specifier = graph_data.follow_redirect(specifier); + match graph_data.get(&specifier) { + Some(ModuleEntry::Module { + media_type, + maybe_types, + .. + }) => match maybe_types { + Some(Resolved::Ok { specifier, .. }) => { + let types = graph_data.follow_redirect(specifier); + match graph_data.get(&types) { + Some(ModuleEntry::Module { media_type, .. }) => { + Some((types, *media_type)) } + _ => None, } - _ => Some((specifier, *media_type)), - }, - _ => { - // handle npm: urls - if let Ok(npm_ref) = - NpmPackageReference::from_specifier(&specifier) - { - if let Some(npm_resolver) = &state.maybe_npm_resolver { - Some(resolve_npm_package_reference_types( - &npm_ref, - npm_resolver, - )?) - } else { - None - } + } + _ => Some((specifier, *media_type)), + }, + _ => { + // handle npm: urls + if let Ok(npm_ref) = NpmPackageReference::from_specifier(&specifier) + { + if let Some(npm_resolver) = &state.maybe_npm_resolver { + Some(resolve_npm_package_reference_types( + &npm_ref, + npm_resolver, + )?) } else { None } - } - } - } - _ => { - state.maybe_npm_resolver.as_ref().and_then(|npm_resolver| { - if npm_resolver.in_npm_package(&referrer) { - // we're in an npm package, so use node resolution - Some(NodeResolution::into_specifier_and_media_type( - node::node_resolve( - specifier, - &referrer, - NodeResolutionMode::Types, - npm_resolver, - &mut PermissionsContainer::allow_all(), - ) - .ok() - .flatten(), - )) } else { None } - }) + } } - }; - let result = match maybe_result { - Some((specifier, media_type)) => { - let specifier_str = match specifier.scheme() { - "data" | "blob" => { - let specifier_str = hash_url(&specifier, media_type); + } + _ => { + if let Some(npm_resolver) = state.maybe_npm_resolver.as_ref() { + if npm_resolver.in_npm_package(&referrer) { + // we're in an npm package, so use node resolution + Some(NodeResolution::into_specifier_and_media_type( + node::node_resolve( + &specifier, + &referrer, + NodeResolutionMode::Types, + npm_resolver, + &mut PermissionsContainer::allow_all(), + ) + .ok() + .flatten(), + )) + } else if let Ok(npm_ref) = NpmPackageReference::from_str(&specifier) + { + // this could occur when resolving npm:@types/node when it is + // injected and not part of the graph + Some(resolve_npm_package_reference_types(&npm_ref, npm_resolver)?) + } else { + None + } + } else { + None + } + } + }; + let result = match maybe_result { + Some((specifier, media_type)) => { + let specifier_str = match specifier.scheme() { + "data" | "blob" => { + let specifier_str = hash_url(&specifier, media_type); + state + .remapped_specifiers + .insert(specifier_str.clone(), specifier); + specifier_str + } + _ => { + if let Some(specifier_str) = + maybe_remap_specifier(&specifier, media_type) + { state .remapped_specifiers .insert(specifier_str.clone(), specifier); specifier_str + } else { + specifier.to_string() } - _ => { - if let Some(specifier_str) = - maybe_remap_specifier(&specifier, media_type) - { - state - .remapped_specifiers - .insert(specifier_str.clone(), specifier); - specifier_str - } else { - specifier.to_string() - } - } - }; - (specifier_str, media_type.as_ts_extension().into()) - } - None => ( - "deno:///missing_dependency.d.ts".to_string(), - ".d.ts".to_string(), - ), - }; - log::debug!("Resolved {} to {:?}", specifier, result); - resolved.push(result); - } + } + }; + (specifier_str, media_type.as_ts_extension().into()) + } + None => ( + "deno:///missing_dependency.d.ts".to_string(), + ".d.ts".to_string(), + ), + }; + log::debug!("Resolved {} to {:?}", specifier, result); + resolved.push(result); } Ok(resolved) From c7b1514fdf1170137ff1280e2f5cc291e15eddf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 15 Jan 2023 02:21:35 +0100 Subject: [PATCH 11/60] add some tests --- cli/tests/integration/check_tests.rs | 12 +++++++++++ cli/tests/integration/run_tests.rs | 20 +++++++++++++++++++ .../check/node_builtin_modules/mod.js | 3 +++ .../check/node_builtin_modules/mod.js.out | 10 ++++++++++ .../check/node_builtin_modules/mod.ts | 2 ++ .../check/node_builtin_modules/mod.ts.out | 10 ++++++++++ .../testdata/run/node_builtin_modules/mod.js | 2 ++ .../run/node_builtin_modules/mod.js.out | 1 + .../testdata/run/node_builtin_modules/mod.ts | 2 ++ .../run/node_builtin_modules/mod.ts.out | 1 + node_builtin.js | 8 -------- node_builtin.ts | 8 -------- 12 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.js create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.js.out create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.ts create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.ts.out create mode 100644 cli/tests/testdata/run/node_builtin_modules/mod.js create mode 100644 cli/tests/testdata/run/node_builtin_modules/mod.js.out create mode 100644 cli/tests/testdata/run/node_builtin_modules/mod.ts create mode 100644 cli/tests/testdata/run/node_builtin_modules/mod.ts.out delete mode 100644 node_builtin.js delete mode 100644 node_builtin.ts diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 38301f079466f3..66433f81dadd14 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -64,6 +64,18 @@ itest!(check_static_response_json { exit_code: 0, }); +itest!(check_node_builtin_modules_ts { + args: "check --quiet check/node_builtin_modules/mod.ts", + output: "check/node_builtin_modules/mod.ts.out", + exit_code: 1, +}); + +itest!(check_node_builtin_modules_js { + args: "check --quiet check/node_builtin_modules/mod.js", + output: "check/node_builtin_modules/mod.js.out", + exit_code: 1, +}); + itest!(check_no_error_truncation { args: "check --quiet check/no_error_truncation/main.ts --config check/no_error_truncation/deno.json", output: "check/no_error_truncation/main.out", diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 564b7355fcc614..f12282b9fc89c1 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -3743,3 +3743,23 @@ fn stdio_streams_are_locked_in_permission_prompt() { assert_eq!(output, expected_output); }); } + +itest!(run_node_builtin_modules_ts { + args: "run --quiet run/node_builtin_modules/mod.ts", + output: "run/node_builtin_modules/mod.ts.out", + envs: vec![( + "DENO_NODE_COMPAT_URL".to_string(), + test_util::std_file_url() + )], + exit_code: 0, +}); + +itest!(run_node_builtin_modules_js { + args: "run --quiet run/node_builtin_modules/mod.js", + output: "run/node_builtin_modules/mod.js.out", + envs: vec![( + "DENO_NODE_COMPAT_URL".to_string(), + test_util::std_file_url() + )], + exit_code: 0, +}); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js b/cli/tests/testdata/check/node_builtin_modules/mod.js new file mode 100644 index 00000000000000..0c899fc2ba51f5 --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js @@ -0,0 +1,3 @@ +// @ts-check +import fs from "node:fs"; +const data = fs.readFileSync("./node_builtin.js", 123); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js.out b/cli/tests/testdata/check/node_builtin_modules/mod.js.out new file mode 100644 index 00000000000000..4f9ac7eabf5e82 --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js.out @@ -0,0 +1,10 @@ +error: TS2769 [ERROR]: No overload matches this call. + Overload 1 of 3, '(path: PathOrFileDescriptor, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer', gave the following error. + Type '123' has no properties in common with type '{ encoding?: null | undefined; flag?: string | undefined; }'. Overload 2 of 3, '(path: PathOrFileDescriptor, options: BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }): string', gave the following error. + Argument of type '123' is not assignable to parameter of type 'BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }'. Overload 3 of 3, '(path: PathOrFileDescriptor, options?: BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined): string | Buffer', gave the following error. + Argument of type '123' is not assignable to parameter of type 'BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined'. +const data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.js:3:51 + + diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts b/cli/tests/testdata/check/node_builtin_modules/mod.ts new file mode 100644 index 00000000000000..e3c7f938822eb5 --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts @@ -0,0 +1,2 @@ +import fs from "node:fs"; +const data = fs.readFileSync("./node_builtin.js", 123); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts.out b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out new file mode 100644 index 00000000000000..d87b21016f8cd1 --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out @@ -0,0 +1,10 @@ +error: TS2769 [ERROR]: No overload matches this call. + Overload 1 of 3, '(path: PathOrFileDescriptor, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer', gave the following error. + Type '123' has no properties in common with type '{ encoding?: null | undefined; flag?: string | undefined; }'. Overload 2 of 3, '(path: PathOrFileDescriptor, options: BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }): string', gave the following error. + Argument of type '123' is not assignable to parameter of type 'BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }'. Overload 3 of 3, '(path: PathOrFileDescriptor, options?: BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined): string | Buffer', gave the following error. + Argument of type '123' is not assignable to parameter of type 'BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined'. +const data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:51 + + diff --git a/cli/tests/testdata/run/node_builtin_modules/mod.js b/cli/tests/testdata/run/node_builtin_modules/mod.js new file mode 100644 index 00000000000000..70e39be5689ae1 --- /dev/null +++ b/cli/tests/testdata/run/node_builtin_modules/mod.js @@ -0,0 +1,2 @@ +import process from "node:process"; +console.log(process.version); diff --git a/cli/tests/testdata/run/node_builtin_modules/mod.js.out b/cli/tests/testdata/run/node_builtin_modules/mod.js.out new file mode 100644 index 00000000000000..37e391febb91fe --- /dev/null +++ b/cli/tests/testdata/run/node_builtin_modules/mod.js.out @@ -0,0 +1 @@ +v16.17.0 diff --git a/cli/tests/testdata/run/node_builtin_modules/mod.ts b/cli/tests/testdata/run/node_builtin_modules/mod.ts new file mode 100644 index 00000000000000..70e39be5689ae1 --- /dev/null +++ b/cli/tests/testdata/run/node_builtin_modules/mod.ts @@ -0,0 +1,2 @@ +import process from "node:process"; +console.log(process.version); diff --git a/cli/tests/testdata/run/node_builtin_modules/mod.ts.out b/cli/tests/testdata/run/node_builtin_modules/mod.ts.out new file mode 100644 index 00000000000000..37e391febb91fe --- /dev/null +++ b/cli/tests/testdata/run/node_builtin_modules/mod.ts.out @@ -0,0 +1 @@ +v16.17.0 diff --git a/node_builtin.js b/node_builtin.js deleted file mode 100644 index 7ba49ab49da255..00000000000000 --- a/node_builtin.js +++ /dev/null @@ -1,8 +0,0 @@ -import fs from "node:fs"; - -try { - const data = fs.readFileSync("./node_builtin.ts", "utf8"); - console.log(data); -} catch (err) { - console.error(err); -} diff --git a/node_builtin.ts b/node_builtin.ts deleted file mode 100644 index fbbb3129596d19..00000000000000 --- a/node_builtin.ts +++ /dev/null @@ -1,8 +0,0 @@ -import fs from "node:fs"; - -try { - const data = fs.readFileSync("./node_builtin.js", "utf8"); - console.log(data); -} catch (err) { - console.error(err); -} From 3971ae0c920cbdc90de5677b0d6afc6570fc62db Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 08:59:55 -0500 Subject: [PATCH 12/60] Make work in lsp. --- cli/lsp/documents.rs | 56 +++++++++++++++++++++++++++++---------- cli/lsp/tsc.rs | 63 ++++++++++++++++++++++++++------------------ cli/tools/check.rs | 2 +- cli/tsc/mod.rs | 2 +- 4 files changed, 81 insertions(+), 42 deletions(-) diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index dad7cf46530738..1636f55ae50ce8 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -774,6 +774,9 @@ pub struct Documents { maybe_resolver: Option, /// The npm package requirements. npm_reqs: Arc>, + /// Gets if any document had a node: specifier such that a @types/node package + /// should be injected. + has_injected_types_node_package: bool, /// Resolves a specifier to its final redirected to specifier. specifier_resolver: Arc, } @@ -789,6 +792,7 @@ impl Documents { imports: Default::default(), maybe_resolver: None, npm_reqs: Default::default(), + has_injected_types_node_package: false, specifier_resolver: Arc::new(SpecifierResolver::new(location)), } } @@ -929,6 +933,12 @@ impl Documents { (*self.npm_reqs).clone() } + /// Returns if a @types/node package was injected into the package + /// requirements based on the state of the documents. + pub fn has_injected_types_node_package(&self) -> bool { + self.has_injected_types_node_package + } + /// Return a document for the specifier. pub fn get(&self, original_specifier: &ModuleSpecifier) -> Option { let specifier = self.specifier_resolver.resolve(original_specifier)?; @@ -989,11 +999,15 @@ impl Documents { /// tsc when type checking. pub fn resolve( &self, - specifiers: &[String], - referrer: &ModuleSpecifier, + specifiers: Vec, + referrer_doc: &AssetOrDocument, maybe_npm_resolver: Option<&NpmPackageResolver>, - ) -> Option>> { - let dependencies = self.get(referrer)?.0.dependencies.clone(); + ) -> Vec> { + let referrer = referrer_doc.specifier(); + let dependencies = match referrer_doc { + AssetOrDocument::Asset(_) => None, + AssetOrDocument::Document(doc) => Some(doc.0.dependencies.clone()), + }; let mut results = Vec::new(); for specifier in specifiers { if let Some(npm_resolver) = maybe_npm_resolver { @@ -1001,7 +1015,7 @@ impl Documents { // we're in an npm package, so use node resolution results.push(Some(NodeResolution::into_specifier_and_media_type( node::node_resolve( - specifier, + &specifier, referrer, NodeResolutionMode::Types, npm_resolver, @@ -1013,15 +1027,28 @@ impl Documents { continue; } } - // handle npm: urls + if let Some(module_name) = specifier.strip_prefix("node:") { + if crate::node::resolve_builtin_node_module(module_name).is_ok() { + // return itself for node: specifiers because during type checking + // we resolve to the ambient modules in the @types/node package + // rather than deno_std/node + results.push(Some(( + ModuleSpecifier::parse(&specifier).unwrap(), + MediaType::Dts, + ))); + continue; + } + } if specifier.starts_with("asset:") { - if let Ok(specifier) = ModuleSpecifier::parse(specifier) { + if let Ok(specifier) = ModuleSpecifier::parse(&specifier) { let media_type = MediaType::from(&specifier); results.push(Some((specifier, media_type))); } else { results.push(None); } - } else if let Some(dep) = dependencies.deps.get(specifier) { + } else if let Some(dep) = + dependencies.as_ref().and_then(|d| d.deps.get(&specifier)) + { if let Resolved::Ok { specifier, .. } = &dep.maybe_type { results.push(self.resolve_dependency(specifier, maybe_npm_resolver)); } else if let Resolved::Ok { specifier, .. } = &dep.maybe_code { @@ -1030,12 +1057,12 @@ impl Documents { results.push(None); } } else if let Some(Resolved::Ok { specifier, .. }) = - self.resolve_imports_dependency(specifier) + self.resolve_imports_dependency(&specifier) { // clone here to avoid double borrow of self let specifier = specifier.clone(); results.push(self.resolve_dependency(&specifier, maybe_npm_resolver)); - } else if let Ok(npm_ref) = NpmPackageReference::from_str(specifier) { + } else if let Ok(npm_ref) = NpmPackageReference::from_str(&specifier) { results.push(maybe_npm_resolver.map(|npm_resolver| { NodeResolution::into_specifier_and_media_type( node_resolve_npm_reference( @@ -1052,7 +1079,7 @@ impl Documents { results.push(None); } } - Some(results) + results } /// Update the location of the on disk cache for the document store. @@ -1196,9 +1223,10 @@ impl Documents { let mut npm_reqs = doc_analyzer.npm_reqs; // ensure a @types/node package exists when any module uses a node: specifier - if doc_analyzer.has_node_builtin_specifier - && !npm_reqs.iter().any(|r| r.name == "@types/node") - { + self.has_injected_types_node_package = doc_analyzer + .has_node_builtin_specifier + && !npm_reqs.iter().any(|r| r.name == "@types/node"); + if self.has_injected_types_node_package { npm_reqs.insert(NpmPackageReq::from_str("@types/node").unwrap()); } diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index ced8fb69930db8..b69022f84d710e 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -216,7 +216,12 @@ fn new_assets_map() -> Arc> { let asset = AssetDocument::new(specifier.clone(), v); (specifier, asset) }) - .collect(); + .collect::(); + let node_types_asset = AssetDocument::new( + ModuleSpecifier::parse("asset:///node_types.d.ts").unwrap(), + "/// \n", + ); + assets.insert(node_types_asset.specifier().clone(), node_types_asset); Arc::new(Mutex::new(assets)) } @@ -2728,28 +2733,29 @@ fn op_resolve( let state = state.borrow_mut::(); let mark = state.performance.mark("op_resolve", Some(&args)); let referrer = state.normalize_specifier(&args.base)?; - - let result = if let Some(resolved) = state.state_snapshot.documents.resolve( - &args.specifiers, - &referrer, - state.state_snapshot.maybe_npm_resolver.as_ref(), - ) { - Ok( - resolved - .into_iter() - .map(|o| { - o.map(|(s, mt)| (s.to_string(), mt.as_ts_extension().to_string())) - }) - .collect(), - ) - } else { - Err(custom_error( + let result = match state.get_asset_or_document(&referrer) { + Some(referrer_doc) => { + let resolved = state.state_snapshot.documents.resolve( + args.specifiers, + &referrer_doc, + state.state_snapshot.maybe_npm_resolver.as_ref(), + ); + Ok( + resolved + .into_iter() + .map(|o| { + o.map(|(s, mt)| (s.to_string(), mt.as_ts_extension().to_string())) + }) + .collect(), + ) + } + None => Err(custom_error( "NotFound", format!( "Error resolving. Referring specifier \"{}\" was not found.", args.base ), - )) + )), }; state.performance.measure(mark); @@ -2764,15 +2770,20 @@ fn op_respond(state: &mut OpState, args: Response) -> bool { } #[op] -fn op_script_names(state: &mut OpState) -> Vec { +fn op_script_names(state: &mut OpState) -> Vec { let state = state.borrow_mut::(); - state - .state_snapshot - .documents - .documents(true, true) - .into_iter() - .map(|d| d.specifier().clone()) - .collect() + let documents = &state.state_snapshot.documents; + let open_docs = documents.documents(true, true); + + let mut result = Vec::with_capacity(open_docs.len() + 1); + + if documents.has_injected_types_node_package() { + // ensure this is first so it resolves the node types first + result.push("asset:///node_types.d.ts".to_string()); + } + + result.extend(open_docs.into_iter().map(|d| d.specifier().to_string())); + result } #[derive(Debug, Deserialize, Serialize)] diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 23e9abdeecbdac..489277373a0556 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -237,7 +237,7 @@ fn get_tsc_roots( if graph_data.has_node_builtin_specifier() { // inject a specifier that will resolve node types result.push(( - ModuleSpecifier::parse("deno:///node_types.d.ts").unwrap(), + ModuleSpecifier::parse("asset:///node_types.d.ts").unwrap(), MediaType::Dts, )); } diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index eb8ceaad3a4a78..b42216c2336122 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -520,7 +520,7 @@ fn op_load(state: &mut OpState, args: Value) -> Result { hash = Some("1".to_string()); media_type = MediaType::Dts; Some(Cow::Borrowed("declare const __: any;\nexport = __;\n")) - } else if &v.specifier == "deno:///node_types.d.ts" { + } else if &v.specifier == "asset:///node_types.d.ts" { hash = Some("1".to_string()); media_type = MediaType::Dts; Some(Cow::Borrowed( From 7c389942be64460c996f6f43f7b16138f15d676b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 09:19:33 -0500 Subject: [PATCH 13/60] Updates for rebase/merge --- cli/lsp/tsc.rs | 5 ----- cli/tsc/mod.rs | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index b69022f84d710e..3619f529c1f255 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -217,11 +217,6 @@ fn new_assets_map() -> Arc> { (specifier, asset) }) .collect::(); - let node_types_asset = AssetDocument::new( - ModuleSpecifier::parse("asset:///node_types.d.ts").unwrap(), - "/// \n", - ); - assets.insert(node_types_asset.specifier().clone(), node_types_asset); Arc::new(Mutex::new(assets)) } diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index b42216c2336122..f637378f888ecc 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -165,6 +165,12 @@ pub static LAZILY_LOADED_STATIC_ASSETS: Lazy< "lib.webworker.iterable.d.ts", inc!("lib.webworker.iterable.d.ts"), ), + ( + // Special file that can be used to inject the @types/node package. + // This is used for `node:` specifiers. + "node_types.d.ts", + "/// \n", + ), ]) .iter() .cloned() @@ -520,12 +526,6 @@ fn op_load(state: &mut OpState, args: Value) -> Result { hash = Some("1".to_string()); media_type = MediaType::Dts; Some(Cow::Borrowed("declare const __: any;\nexport = __;\n")) - } else if &v.specifier == "asset:///node_types.d.ts" { - hash = Some("1".to_string()); - media_type = MediaType::Dts; - Some(Cow::Borrowed( - "/// \n", - )) } else if let Some(name) = v.specifier.strip_prefix("asset:///") { let maybe_source = get_lazily_loaded_asset(name); hash = get_maybe_hash(maybe_source, &state.hash_data); From dfbb9eab2438199f3fb322d44399e1887e4cf938 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 09:29:06 -0500 Subject: [PATCH 14/60] Stop log spam --- cli/lsp/cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index 47f6e44ba9c479..23469a583ff8b4 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -68,7 +68,7 @@ impl CacheMetadata { &self, specifier: &ModuleSpecifier, ) -> Option>> { - if specifier.scheme() == "file" || specifier.scheme() == "npm" { + if matches!(specifier.scheme(), "file" | "npm" | "node") { return None; } let version = self From 01566b152bafef099d373c01e6113bae492b71bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 16 Jan 2023 16:10:17 +0100 Subject: [PATCH 15/60] default to ESM instead of CJS --- cli/worker.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/worker.rs b/cli/worker.rs index 51b60daa9ce64c..6e91a49fc2349e 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -68,14 +68,19 @@ impl CliMainWorker { log::debug!("main_module {}", self.main_module); if self.ps.options.node() { + // TODO(bartlomieju): make it graceful looking for closes package.json // We're in Node compat mode, try to find `package.json` and load it. let package_json = PackageJson::load_skip_read_permission( std::env::current_dir().unwrap().join("package.json"), ) .context("Unable to load package.json from CWD")?; - self.is_main_cjs = package_json.typ != "module"; + // NOTE(bartlomieju): we are explicitly not compatible with Node.js here - + // Node defaults to "commonjs" if the "type" entry is missing. We default + // to ESM and only enable CJS if "type" is "commonjs". + self.is_main_cjs = package_json.typ == "commonjs"; + // TODO(bartlomieju): could be extracted into a helper function if let Some(deps) = &package_json.dependencies { let mut reqs = vec![]; for (key, value) in deps { From 907291c42723a7d4d7da795f7883a91b023566c7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 11:39:21 -0500 Subject: [PATCH 16/60] Diagnostics for uncached @types/node package and invalid node: specifier --- cli/graph_util.rs | 10 ++++++ cli/lsp/diagnostics.rs | 19 +++++++++- cli/npm/resolution/graph.rs | 2 +- cli/npm/resolution/specifier.rs | 36 ++++++++++++++++--- cli/proc_state.rs | 18 ++-------- .../check/node_builtin_modules/mod.js | 2 +- .../check/node_builtin_modules/mod.js.out | 11 +++--- .../check/node_builtin_modules/mod.ts | 2 +- .../check/node_builtin_modules/mod.ts.out | 11 +++--- 9 files changed, 73 insertions(+), 38 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 93d4865dc65a67..9c08bbffb4060b 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -162,6 +162,16 @@ impl GraphData { if has_npm_specifier_in_graph { self.npm_packages.extend(resolve_npm_package_reqs(graph)); } + + // ensure a @types/node package is in the list of npm package requirements + // if a node: specifier was in the graph + if self.has_node_builtin_specifier + && !self.npm_packages.iter().any(|a| a.name == "@types/node") + { + self + .npm_packages + .insert(0, NpmPackageReq::from_str("@types/node").unwrap()); + } } pub fn entries( diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 4b4ef5800d5b50..d8cb0e8f8f9416 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -617,6 +617,8 @@ pub enum DenoDiagnostic { }, /// An error occurred when resolving the specifier string. ResolutionError(deno_graph::ResolutionError), + /// Invalid `node:` specifier. + InvalidNodeSpecifier(ModuleSpecifier), } impl DenoDiagnostic { @@ -644,6 +646,7 @@ impl DenoDiagnostic { }, ResolutionError::ResolverError { .. } => "resolver-error", }, + Self::InvalidNodeSpecifier(_) => "resolver-error", } } @@ -794,6 +797,7 @@ impl DenoDiagnostic { Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unable to load a local module: \"{}\".\n Please check the file path.", specifier), None), Self::Redirect { from, to} => (lsp::DiagnosticSeverity::INFORMATION, format!("The import of \"{}\" was redirected to \"{}\".", from, to), Some(json!({ "specifier": from, "redirect": to }))), Self::ResolutionError(err) => (lsp::DiagnosticSeverity::ERROR, err.to_string(), None), + Self::InvalidNodeSpecifier(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unknown Node built-in module: {}", specifier.path()), None), }; lsp::Diagnostic { range: *range, @@ -879,9 +883,22 @@ fn diagnose_resolved( { if node::resolve_builtin_node_module(module_name).is_err() { diagnostics.push( - DenoDiagnostic::NoCache(specifier.clone()) + DenoDiagnostic::InvalidNodeSpecifier(specifier.clone()) .to_lsp_diagnostic(&range), ); + } else if let Some(npm_resolver) = &snapshot.maybe_npm_resolver { + // check that a @types/node package exists in the resolver + let types_node_ref = + NpmPackageReference::from_str("npm:@types/node").unwrap(); + if npm_resolver + .resolve_package_folder_from_deno_module(&types_node_ref.req) + .is_err() + { + diagnostics.push( + DenoDiagnostic::NoCacheNpm(types_node_ref, specifier.clone()) + .to_lsp_diagnostic(&range), + ); + } } } else { // When the document is not available, it means that it cannot be found diff --git a/cli/npm/resolution/graph.rs b/cli/npm/resolution/graph.rs index 81ff58546f2e01..e2104814996a4e 100644 --- a/cli/npm/resolution/graph.rs +++ b/cli/npm/resolution/graph.rs @@ -1081,7 +1081,7 @@ fn tag_to_version_info<'a>( // explicit version. if tag == "latest" && info.name == "@types/node" { return get_resolved_package_version_and_info( - &NpmVersionReq::parse("18.0.0 - 18.8.2").unwrap(), + &NpmVersionReq::parse("18.0.0 - 18.11.18").unwrap(), info, parent, ); diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 06efac156b2e63..7bd49d86e7f5e7 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -168,7 +168,7 @@ impl NpmVersionMatcher for NpmPackageReq { } } -/// Resolves the npm package requirements from the graph attempting. The order +/// Resolves the npm package requirements from the graph. The order /// returned is the order they should be resolved in. /// /// This function will analyze the module graph for parent-most folder @@ -248,6 +248,7 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { graph: &ModuleGraph, specifier_graph: &mut SpecifierTree, seen: &mut HashSet, + has_node_builtin_specifier: &mut bool, ) { if !seen.insert(module.specifier.clone()) { return; // already visited @@ -267,12 +268,22 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { .dependencies .insert(get_folder_path_specifier(specifier)); } + + if !*has_node_builtin_specifier && specifier.scheme() == "node" { + *has_node_builtin_specifier = true; + } } // now visit all the dependencies for specifier in &specifiers { if let Some(module) = graph.get(specifier) { - analyze_module(module, graph, specifier_graph, seen); + analyze_module( + module, + graph, + specifier_graph, + seen, + has_node_builtin_specifier, + ); } } } @@ -284,9 +295,16 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { .collect::>(); let mut seen = HashSet::new(); let mut specifier_graph = SpecifierTree::default(); + let mut has_node_builtin_specifier = false; for root in &root_specifiers { if let Some(module) = graph.get(root) { - analyze_module(module, graph, &mut specifier_graph, &mut seen); + analyze_module( + module, + graph, + &mut specifier_graph, + &mut seen, + &mut has_node_builtin_specifier, + ); } } @@ -324,7 +342,17 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { } } - result + // if we have a built-in node specifier + if has_node_builtin_specifier + && !result.iter().any(|r| r.name == "@types/node") + { + let mut final_result = Vec::with_capacity(result.len() + 1); + final_result.push(NpmPackageReq::from_str("@types/node").unwrap()); + final_result.extend(result); + final_result + } else { + result + } } fn get_folder_path_specifier(specifier: &ModuleSpecifier) -> ModuleSpecifier { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index c9958360709383..5f7b5c07a5c5a2 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -26,7 +26,6 @@ use crate::node::NodeResolution; use crate::npm::resolve_npm_package_reqs; use crate::npm::NpmCache; use crate::npm::NpmPackageReference; -use crate::npm::NpmPackageReq; use crate::npm::NpmPackageResolver; use crate::npm::RealNpmRegistryApi; use crate::resolver::CliResolver; @@ -430,7 +429,7 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; - let (mut npm_package_reqs, has_node_builtin_specifier) = { + let npm_package_reqs = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); let check_js = self.options.check_js(); @@ -441,22 +440,9 @@ impl ProcState { check_js, ) .unwrap()?; - ( - graph_data.npm_package_reqs().clone(), - graph_data.has_node_builtin_specifier(), - ) + graph_data.npm_package_reqs().clone() }; - // add a @types/node package if the code has a "node:" specifier, - // the code is type checking, and there aren't any existing @types/node - // packages specified - if has_node_builtin_specifier - && self.options.type_check_mode() != TypeCheckMode::None - && !npm_package_reqs.iter().any(|r| r.name == "@types/node") - { - npm_package_reqs.push(NpmPackageReq::from_str("@types/node").unwrap()); - } - if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; self.prepare_node_std_graph().await?; diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js b/cli/tests/testdata/check/node_builtin_modules/mod.js index 0c899fc2ba51f5..196fb9be98c008 100644 --- a/cli/tests/testdata/check/node_builtin_modules/mod.js +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js @@ -1,3 +1,3 @@ // @ts-check import fs from "node:fs"; -const data = fs.readFileSync("./node_builtin.js", 123); +const _data = fs.readFileSync("./node_builtin.js", 123); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js.out b/cli/tests/testdata/check/node_builtin_modules/mod.js.out index 4f9ac7eabf5e82..42ffcdeb79f93a 100644 --- a/cli/tests/testdata/check/node_builtin_modules/mod.js.out +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js.out @@ -1,10 +1,7 @@ error: TS2769 [ERROR]: No overload matches this call. - Overload 1 of 3, '(path: PathOrFileDescriptor, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer', gave the following error. - Type '123' has no properties in common with type '{ encoding?: null | undefined; flag?: string | undefined; }'. Overload 2 of 3, '(path: PathOrFileDescriptor, options: BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }): string', gave the following error. - Argument of type '123' is not assignable to parameter of type 'BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }'. Overload 3 of 3, '(path: PathOrFileDescriptor, options?: BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined): string | Buffer', gave the following error. - Argument of type '123' is not assignable to parameter of type 'BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined'. -const data = fs.readFileSync("./node_builtin.js", 123); - ~~~ - at file:///[WILDCARD]/node_builtin_modules/mod.js:3:51 + [WILDCARD] +const _data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.js:3:52 diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts b/cli/tests/testdata/check/node_builtin_modules/mod.ts index e3c7f938822eb5..a7c536056f6cb4 100644 --- a/cli/tests/testdata/check/node_builtin_modules/mod.ts +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts @@ -1,2 +1,2 @@ import fs from "node:fs"; -const data = fs.readFileSync("./node_builtin.js", 123); +const _data = fs.readFileSync("./node_builtin.js", 123); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts.out b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out index d87b21016f8cd1..77c19948d06448 100644 --- a/cli/tests/testdata/check/node_builtin_modules/mod.ts.out +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out @@ -1,10 +1,7 @@ error: TS2769 [ERROR]: No overload matches this call. - Overload 1 of 3, '(path: PathOrFileDescriptor, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer', gave the following error. - Type '123' has no properties in common with type '{ encoding?: null | undefined; flag?: string | undefined; }'. Overload 2 of 3, '(path: PathOrFileDescriptor, options: BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }): string', gave the following error. - Argument of type '123' is not assignable to parameter of type 'BufferEncoding | { encoding: BufferEncoding; flag?: string | undefined; }'. Overload 3 of 3, '(path: PathOrFileDescriptor, options?: BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined): string | Buffer', gave the following error. - Argument of type '123' is not assignable to parameter of type 'BufferEncoding | (ObjectEncodingOptions & { flag?: string | undefined; }) | null | undefined'. -const data = fs.readFileSync("./node_builtin.js", 123); - ~~~ - at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:51 + [WILDCARD] +const _data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:52 From b631b0a589e4c3e976054f4447d6647eb85e3b6c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 16:37:29 -0500 Subject: [PATCH 17/60] Synthetic reqs barely done... committing for historical reasons before a revert because it's going to get too complex. --- cli/npm/resolution/graph.rs | 31 +++++++++++++++++++++++++++++++ cli/npm/resolution/snapshot.rs | 14 ++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cli/npm/resolution/graph.rs b/cli/npm/resolution/graph.rs index e2104814996a4e..3b73ee308c59d9 100644 --- a/cli/npm/resolution/graph.rs +++ b/cli/npm/resolution/graph.rs @@ -124,6 +124,9 @@ enum NodeParent { /// These are top of the graph npm package requirements /// as specified in Deno code. Req, + /// These are top of the graph npm package requirements + /// that were injected by the runtime. + SyntheticReq, /// A reference to another node, which is a resolved package. Node(NpmPackageId), } @@ -164,6 +167,7 @@ impl Node { #[derive(Debug, Default)] pub struct Graph { package_reqs: HashMap, + synthetic_package_reqs: HashMap, packages_by_name: HashMap>, // Ideally this value would be Rc>, but we need to use a Mutex // because the lsp requires Send and this code is executed in the lsp. @@ -210,6 +214,16 @@ impl Graph { .add_parent(package_req_text.clone(), NodeParent::Req); graph.package_reqs.insert(package_req_text, id.clone()); } + for (package_req, id) in &snapshot.synthetic_package_reqs { + let node = fill_for_id(&mut graph, id, &snapshot.packages); + let package_req_text = package_req.to_string(); + (*node) + .lock() + .add_parent(package_req_text.clone(), NodeParent::SyntheticReq); + graph + .synthetic_package_reqs + .insert(package_req_text, id.clone()); + } graph } @@ -293,6 +307,13 @@ impl Graph { .package_reqs .insert(specifier.to_string(), node.id.clone()); } + NodeParent::SyntheticReq => { + let mut node = (*child).lock(); + node.add_parent(specifier.to_string(), parent.clone()); + self + .synthetic_package_reqs + .insert(specifier.to_string(), node.id.clone()); + } } } @@ -337,6 +358,13 @@ impl Graph { assert_eq!(removed_child_id, *child_id); } } + NodeParent::SyntheticReq => { + if let Some(removed_child_id) = + self.synthetic_package_reqs.remove(specifier) + { + assert_eq!(removed_child_id, *child_id); + } + } } self.borrow_node(child_id).remove_parent(specifier, parent); } @@ -832,6 +860,9 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi> ))); } } + NodeParent::SyntheticReq => { + // ignore + } } } diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs index ad6aee6d955b3c..e897b3e738a4fc 100644 --- a/cli/npm/resolution/snapshot.rs +++ b/cli/npm/resolution/snapshot.rs @@ -48,6 +48,10 @@ impl NpmPackagesPartitioned { pub struct NpmResolutionSnapshot { #[serde(with = "map_to_vec")] pub(super) package_reqs: HashMap, + /// Package requirements injected by the runtime. These are never saved + /// or loaded from the lockfile. + #[serde(with = "map_to_vec")] + pub(super) synthetic_package_reqs: HashMap, pub(super) packages_by_name: HashMap>, #[serde(with = "map_to_vec")] pub(super) packages: HashMap, @@ -98,7 +102,11 @@ impl NpmResolutionSnapshot { &self, req: &NpmPackageReq, ) -> Result<&NpmResolutionPackage, AnyError> { - match self.package_reqs.get(req) { + match self + .package_reqs + .get(req) + .or_else(|| self.synthetic_package_reqs.get(req)) + { Some(id) => Ok(self.packages.get(id).unwrap()), None => bail!("could not find npm package directory for '{}'", req), } @@ -108,9 +116,10 @@ impl NpmResolutionSnapshot { self .package_reqs .values() - .cloned() + .chain(self.synthetic_package_reqs.values()) .collect::>() .into_iter() + .cloned() .collect::>() } @@ -333,6 +342,7 @@ impl NpmResolutionSnapshot { Ok(Self { package_reqs, + synthetic_package_reqs: Default::default(), packages_by_name, packages, }) From b0e9551e3e72fc5648a812cac0c4c4163838a556 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 16 Jan 2023 16:37:41 -0500 Subject: [PATCH 18/60] Revert "Synthetic reqs barely done... committing for historical reasons before a revert because it's going to get too complex." This reverts commit b631b0a589e4c3e976054f4447d6647eb85e3b6c. --- cli/npm/resolution/graph.rs | 31 ------------------------------- cli/npm/resolution/snapshot.rs | 14 ++------------ 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/cli/npm/resolution/graph.rs b/cli/npm/resolution/graph.rs index 3b73ee308c59d9..e2104814996a4e 100644 --- a/cli/npm/resolution/graph.rs +++ b/cli/npm/resolution/graph.rs @@ -124,9 +124,6 @@ enum NodeParent { /// These are top of the graph npm package requirements /// as specified in Deno code. Req, - /// These are top of the graph npm package requirements - /// that were injected by the runtime. - SyntheticReq, /// A reference to another node, which is a resolved package. Node(NpmPackageId), } @@ -167,7 +164,6 @@ impl Node { #[derive(Debug, Default)] pub struct Graph { package_reqs: HashMap, - synthetic_package_reqs: HashMap, packages_by_name: HashMap>, // Ideally this value would be Rc>, but we need to use a Mutex // because the lsp requires Send and this code is executed in the lsp. @@ -214,16 +210,6 @@ impl Graph { .add_parent(package_req_text.clone(), NodeParent::Req); graph.package_reqs.insert(package_req_text, id.clone()); } - for (package_req, id) in &snapshot.synthetic_package_reqs { - let node = fill_for_id(&mut graph, id, &snapshot.packages); - let package_req_text = package_req.to_string(); - (*node) - .lock() - .add_parent(package_req_text.clone(), NodeParent::SyntheticReq); - graph - .synthetic_package_reqs - .insert(package_req_text, id.clone()); - } graph } @@ -307,13 +293,6 @@ impl Graph { .package_reqs .insert(specifier.to_string(), node.id.clone()); } - NodeParent::SyntheticReq => { - let mut node = (*child).lock(); - node.add_parent(specifier.to_string(), parent.clone()); - self - .synthetic_package_reqs - .insert(specifier.to_string(), node.id.clone()); - } } } @@ -358,13 +337,6 @@ impl Graph { assert_eq!(removed_child_id, *child_id); } } - NodeParent::SyntheticReq => { - if let Some(removed_child_id) = - self.synthetic_package_reqs.remove(specifier) - { - assert_eq!(removed_child_id, *child_id); - } - } } self.borrow_node(child_id).remove_parent(specifier, parent); } @@ -860,9 +832,6 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi> ))); } } - NodeParent::SyntheticReq => { - // ignore - } } } diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs index e897b3e738a4fc..ad6aee6d955b3c 100644 --- a/cli/npm/resolution/snapshot.rs +++ b/cli/npm/resolution/snapshot.rs @@ -48,10 +48,6 @@ impl NpmPackagesPartitioned { pub struct NpmResolutionSnapshot { #[serde(with = "map_to_vec")] pub(super) package_reqs: HashMap, - /// Package requirements injected by the runtime. These are never saved - /// or loaded from the lockfile. - #[serde(with = "map_to_vec")] - pub(super) synthetic_package_reqs: HashMap, pub(super) packages_by_name: HashMap>, #[serde(with = "map_to_vec")] pub(super) packages: HashMap, @@ -102,11 +98,7 @@ impl NpmResolutionSnapshot { &self, req: &NpmPackageReq, ) -> Result<&NpmResolutionPackage, AnyError> { - match self - .package_reqs - .get(req) - .or_else(|| self.synthetic_package_reqs.get(req)) - { + match self.package_reqs.get(req) { Some(id) => Ok(self.packages.get(id).unwrap()), None => bail!("could not find npm package directory for '{}'", req), } @@ -116,10 +108,9 @@ impl NpmResolutionSnapshot { self .package_reqs .values() - .chain(self.synthetic_package_reqs.values()) + .cloned() .collect::>() .into_iter() - .cloned() .collect::>() } @@ -342,7 +333,6 @@ impl NpmResolutionSnapshot { Ok(Self { package_reqs, - synthetic_package_reqs: Default::default(), packages_by_name, packages, }) From 10d75c5934acba7b935cb4f69197d21a571dc41f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 17 Jan 2023 09:27:51 -0500 Subject: [PATCH 19/60] Refactor creating resolver with lockfile --- cli/npm/resolvers/mod.rs | 77 +++++++++++++++++----------------------- cli/proc_state.rs | 11 +++--- 2 files changed, 37 insertions(+), 51 deletions(-) diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 767187f5e5e5e2..3baf6d7dfb6dc5 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -95,59 +95,47 @@ impl NpmPackageResolver { no_npm: bool, local_node_modules_path: Option, ) -> Self { - Self::new_with_maybe_snapshot( + Self::new_inner(cache, api, no_npm, local_node_modules_path, None, None) + } + + pub async fn new_with_maybe_lockfile( + cache: NpmCache, + api: RealNpmRegistryApi, + no_npm: bool, + local_node_modules_path: Option, + maybe_lockfile: Option>>, + ) -> Result { + let maybe_snapshot = if let Some(lockfile) = &maybe_lockfile { + Some( + NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &api) + .await + .with_context(|| { + format!( + "failed reading lockfile '{}'", + lockfile.lock().filename.display() + ) + })?, + ) + } else { + None + }; + Ok(Self::new_inner( cache, api, no_npm, local_node_modules_path, - None, - ) - } - - /// This function will replace current resolver with a new one built from a - /// snapshot created out of the lockfile. - pub async fn add_lockfile_and_maybe_regenerate_snapshot( - &mut self, - lockfile: Arc>, - ) -> Result<(), AnyError> { - self.maybe_lockfile = Some(lockfile.clone()); - - if lockfile.lock().overwrite { - return Ok(()); - } - - let snapshot = - NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &self.api) - .await - .with_context(|| { - format!( - "failed reading lockfile '{}'", - lockfile.lock().filename.display() - ) - })?; - if let Some(node_modules_folder) = &self.local_node_modules_path { - self.inner = Arc::new(LocalNpmPackageResolver::new( - self.cache.clone(), - self.api.clone(), - node_modules_folder.clone(), - Some(snapshot), - )); - } else { - self.inner = Arc::new(GlobalNpmPackageResolver::new( - self.cache.clone(), - self.api.clone(), - Some(snapshot), - )); - } - Ok(()) + maybe_snapshot, + maybe_lockfile, + )) } - fn new_with_maybe_snapshot( + fn new_inner( cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, local_node_modules_path: Option, initial_snapshot: Option, + maybe_lockfile: Option>>, ) -> Self { let process_npm_state = NpmProcessState::take(); let local_node_modules_path = local_node_modules_path.or_else(|| { @@ -177,7 +165,7 @@ impl NpmPackageResolver { local_node_modules_path, api, cache, - maybe_lockfile: None, + maybe_lockfile, } } @@ -320,12 +308,13 @@ impl NpmPackageResolver { /// Gets a new resolver with a new snapshotted state. pub fn snapshotted(&self) -> Self { - Self::new_with_maybe_snapshot( + Self::new_inner( self.cache.clone(), self.api.clone(), self.no_npm, self.local_node_modules_path.clone(), Some(self.snapshot()), + None, ) } diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 5f7b5c07a5c5a2..1f3b1698413df4 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -263,19 +263,16 @@ impl ProcState { progress_bar.clone(), ); let maybe_lockfile = lockfile.as_ref().cloned(); - let mut npm_resolver = NpmPackageResolver::new( + let npm_resolver = NpmPackageResolver::new_with_maybe_lockfile( npm_cache.clone(), api, cli_options.no_npm(), cli_options .resolve_local_node_modules_folder() .with_context(|| "Resolving local node_modules folder.")?, - ); - if let Some(lockfile) = maybe_lockfile { - npm_resolver - .add_lockfile_and_maybe_regenerate_snapshot(lockfile) - .await?; - } + maybe_lockfile, + ) + .await?; let node_analysis_cache = NodeAnalysisCache::new(Some(dir.node_analysis_db_file_path())); From a3bc37701bbe36e7e571d7b9ef1d724855f2b251 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 17 Jan 2023 10:38:53 -0500 Subject: [PATCH 20/60] Fix bug introduced by latest refactor --- cli/npm/resolvers/mod.rs | 24 ++++++++++++++---------- cli/proc_state.rs | 3 +-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 3baf6d7dfb6dc5..6c766dcc126028 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -106,16 +106,20 @@ impl NpmPackageResolver { maybe_lockfile: Option>>, ) -> Result { let maybe_snapshot = if let Some(lockfile) = &maybe_lockfile { - Some( - NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &api) - .await - .with_context(|| { - format!( - "failed reading lockfile '{}'", - lockfile.lock().filename.display() - ) - })?, - ) + if lockfile.lock().overwrite { + None + } else { + Some( + NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &api) + .await + .with_context(|| { + format!( + "failed reading lockfile '{}'", + lockfile.lock().filename.display() + ) + })?, + ) + } } else { None }; diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 1f3b1698413df4..1b7a6c42854a9b 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -262,7 +262,6 @@ impl ProcState { http_client.clone(), progress_bar.clone(), ); - let maybe_lockfile = lockfile.as_ref().cloned(); let npm_resolver = NpmPackageResolver::new_with_maybe_lockfile( npm_cache.clone(), api, @@ -270,7 +269,7 @@ impl ProcState { cli_options .resolve_local_node_modules_folder() .with_context(|| "Resolving local node_modules folder.")?, - maybe_lockfile, + lockfile.as_ref().cloned(), ) .await?; let node_analysis_cache = From 8c16c3f6c3e0e2b0a03b41a6fca3f24822d9777a Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 17 Jan 2023 12:32:23 -0500 Subject: [PATCH 21/60] Don't store @types/node in the lockfile --- cli/graph_util.rs | 20 +++++++++---------- cli/npm/mod.rs | 2 +- cli/npm/resolution/mod.rs | 2 +- cli/npm/resolution/specifier.rs | 29 ++++++++++++++------------- cli/npm/resolvers/mod.rs | 20 +++++++++++++++++++ cli/proc_state.rs | 35 +++++++++++++++++++++++++++------ 6 files changed, 76 insertions(+), 32 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 9c08bbffb4060b..9b2df9ad3e7e00 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -8,7 +8,7 @@ use crate::cache; use crate::cache::TypeCheckCache; use crate::colors; use crate::errors::get_error_class_name; -use crate::npm::resolve_npm_package_reqs; +use crate::npm::resolve_graph_npm_info; use crate::npm::NpmPackageReference; use crate::npm::NpmPackageReq; use crate::proc_state::ProcState; @@ -160,17 +160,9 @@ impl GraphData { } if has_npm_specifier_in_graph { - self.npm_packages.extend(resolve_npm_package_reqs(graph)); - } - - // ensure a @types/node package is in the list of npm package requirements - // if a node: specifier was in the graph - if self.has_node_builtin_specifier - && !self.npm_packages.iter().any(|a| a.name == "@types/node") - { self .npm_packages - .insert(0, NpmPackageReq::from_str("@types/node").unwrap()); + .extend(resolve_graph_npm_info(graph).package_reqs); } } @@ -579,6 +571,14 @@ pub async fn create_graph_and_maybe_check( } if ps.options.type_check_mode() != TypeCheckMode::None { + // node built-in specifiers use the @types/node package to determine + // types, so inject that now after the lockfile has been written + if graph_data.has_node_builtin_specifier() { + ps.npm_resolver + .inject_synthetic_types_node_package() + .await?; + } + let ts_config_result = ps.options.resolve_ts_config_for_emit(TsConfigType::Check { lib: ps.options.ts_type_lib_window(), diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index ce6fec5e51f0d2..9f41e508a8e2f2 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -14,7 +14,7 @@ pub use cache::NpmCache; pub use registry::NpmPackageVersionDistInfo; pub use registry::NpmRegistryApi; pub use registry::RealNpmRegistryApi; -pub use resolution::resolve_npm_package_reqs; +pub use resolution::resolve_graph_npm_info; pub use resolution::NpmPackageId; pub use resolution::NpmPackageReference; pub use resolution::NpmPackageReq; diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index c4d05598c88912..e84d342aa1ed75 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -28,7 +28,7 @@ mod specifier; use graph::Graph; pub use snapshot::NpmResolutionSnapshot; -pub use specifier::resolve_npm_package_reqs; +pub use specifier::resolve_graph_npm_info; pub use specifier::NpmPackageReference; pub use specifier::NpmPackageReq; diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 7bd49d86e7f5e7..d4d6443ef69ea6 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -168,8 +168,15 @@ impl NpmVersionMatcher for NpmPackageReq { } } -/// Resolves the npm package requirements from the graph. The order -/// returned is the order they should be resolved in. +pub struct GraphNpmInfo { + /// The order of these package requirements is the order they + /// should be resolved in. + pub package_reqs: Vec, + /// Gets if the graph had a built-in node specifier (ex. `node:fs`). + pub has_node_builtin_specifier: bool, +} + +/// Resolves npm specific information from the graph. /// /// This function will analyze the module graph for parent-most folder /// specifiers of all modules, then group npm specifiers together as found in @@ -211,7 +218,7 @@ impl NpmVersionMatcher for NpmPackageReq { /// /// Then it would resolve the npm specifiers in each of those groups according /// to that tree going by tree depth. -pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { +pub fn resolve_graph_npm_info(graph: &ModuleGraph) -> GraphNpmInfo { fn collect_specifiers<'a>( graph: &'a ModuleGraph, module: &'a deno_graph::Module, @@ -342,16 +349,9 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { } } - // if we have a built-in node specifier - if has_node_builtin_specifier - && !result.iter().any(|r| r.name == "@types/node") - { - let mut final_result = Vec::with_capacity(result.len() + 1); - final_result.push(NpmPackageReq::from_str("@types/node").unwrap()); - final_result.extend(result); - final_result - } else { - result + GraphNpmInfo { + has_node_builtin_specifier, + package_reqs: result, } } @@ -1014,7 +1014,8 @@ mod tests { }, ) .await; - let reqs = resolve_npm_package_reqs(&graph) + let reqs = resolve_graph_npm_info(&graph) + .package_reqs .into_iter() .map(|r| r.to_string()) .collect::>(); diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 6c766dcc126028..e6e565a7be6c65 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -329,6 +329,26 @@ impl NpmPackageResolver { pub fn lock(&self, lockfile: &mut Lockfile) -> Result<(), AnyError> { self.inner.lock(lockfile) } + + pub async fn inject_synthetic_types_node_package( + &self, + ) -> Result<(), AnyError> { + if self.no_npm { + return Err(custom_error( + "NoNpm", + "A node built-in specifier was used; but --no-npm is specified.", + )); + } + + // add and ensure this isn't added to the lockfile + self + .inner + .add_package_reqs(vec![NpmPackageReq::from_str("@types/node").unwrap()]) + .await?; + self.inner.cache_packages().await?; + + Ok(()) + } } impl RequireNpmResolver for NpmPackageResolver { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 1b7a6c42854a9b..bca3de5f3c0ab5 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -23,7 +23,7 @@ use crate::graph_util::ModuleEntry; use crate::http_util::HttpClient; use crate::node; use crate::node::NodeResolution; -use crate::npm::resolve_npm_package_reqs; +use crate::npm::resolve_graph_npm_info; use crate::npm::NpmCache; use crate::npm::NpmPackageReference; use crate::npm::NpmPackageResolver; @@ -425,7 +425,7 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; - let npm_package_reqs = { + let (npm_package_reqs, has_node_builtin_specifier) = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); let check_js = self.options.check_js(); @@ -436,7 +436,10 @@ impl ProcState { check_js, ) .unwrap()?; - graph_data.npm_package_reqs().clone() + ( + graph_data.npm_package_reqs().clone(), + graph_data.has_node_builtin_specifier(), + ) }; if !npm_package_reqs.is_empty() { @@ -444,6 +447,15 @@ impl ProcState { self.prepare_node_std_graph().await?; } + if has_node_builtin_specifier + && self.options.type_check_mode() != TypeCheckMode::None + { + self + .npm_resolver + .inject_synthetic_types_node_package() + .await?; + } + drop(_pb_clear_guard); // type check if necessary @@ -741,9 +753,20 @@ impl ProcState { .await; // add the found npm package requirements to the npm resolver and cache them - let npm_package_reqs = resolve_npm_package_reqs(&graph); - if !npm_package_reqs.is_empty() { - self.npm_resolver.add_package_reqs(npm_package_reqs).await?; + let graph_npm_info = resolve_graph_npm_info(&graph); + if !graph_npm_info.package_reqs.is_empty() { + self + .npm_resolver + .add_package_reqs(graph_npm_info.package_reqs) + .await?; + } + if graph_npm_info.has_node_builtin_specifier + && self.options.type_check_mode() != TypeCheckMode::None + { + self + .npm_resolver + .inject_synthetic_types_node_package() + .await?; } Ok(graph) From b8b4d398a294e17beae6218e283cf9ad30f79a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Jan 2023 17:01:05 +0100 Subject: [PATCH 22/60] wip to autodiscover --- cli/args/flags.rs | 19 +++++++-- cli/args/mod.rs | 81 +++++++++++++++++++++++++++++++++++--- cli/lsp/language_server.rs | 2 + cli/proc_state.rs | 2 +- cli/worker.rs | 16 +------- ext/node/lib.rs | 1 + ext/node/resolution.rs | 2 +- 7 files changed, 98 insertions(+), 25 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 7793931038cfa4..7523dd22eb355a 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -349,8 +349,6 @@ pub struct Flags { pub version: bool, pub watch: Option>, pub no_clear_screen: bool, - - pub node: bool, } fn join_paths(allowlist: &[PathBuf], d: &str) -> String { @@ -503,6 +501,21 @@ impl Flags { } } + pub fn package_json_args(&self) -> Option { + use DenoSubcommand::*; + + if let Run(RunFlags { script }) = &self.subcommand { + if let Ok(module_specifier) = deno_core::resolve_url_or_path(script) { + if module_specifier.scheme() == "file" { + let p = module_specifier.to_file_path().unwrap(); + return Some(p); + } + } + } + + None + } + pub fn has_permission(&self) -> bool { self.allow_all || self.allow_hrtime @@ -1508,7 +1521,6 @@ fn run_subcommand<'a>() -> Command<'a> { ) .arg(no_clear_screen_arg()) .trailing_var_arg(true) - .arg(Arg::new("node").long("node")) .arg(script_arg().required(true)) .about("Run a JavaScript or TypeScript program") .long_about( @@ -2717,7 +2729,6 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.argv.push(v); } - flags.node = matches.is_present("node"); watch_arg_parse(flags, matches, true); flags.subcommand = DenoSubcommand::Run(RunFlags { script }); } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 2d7b2b159d10f2..c8fbcdf1ac8429 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -6,6 +6,7 @@ mod lockfile; mod flags_allow_net; +use crate::util::fs::canonicalize_path; pub use config_file::BenchConfig; pub use config_file::CompilerOptions; pub use config_file::ConfigFile; @@ -19,6 +20,7 @@ pub use config_file::TsConfig; pub use config_file::TsConfigForEmit; pub use config_file::TsConfigType; pub use config_file::TsTypeLib; +use deno_runtime::deno_node::PackageJson; pub use flags::*; pub use lockfile::Lockfile; pub use lockfile::LockfileError; @@ -40,11 +42,13 @@ use deno_runtime::deno_tls::webpki_roots; use deno_runtime::inspector_server::InspectorServer; use deno_runtime::permissions::PermissionsOptions; use std::collections::BTreeMap; +use std::collections::HashSet; use std::env; use std::io::BufReader; use std::io::Cursor; use std::net::SocketAddr; use std::num::NonZeroUsize; +use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -57,6 +61,64 @@ use self::config_file::LintConfig; use self::config_file::MaybeImportsResult; use self::config_file::TestConfig; +fn discover_package_json( + flags: &Flags, +) -> Result, AnyError> { + fn discover_from( + start: &Path, + checked: &mut HashSet, + ) -> Result, AnyError> { + for ancestor in start.ancestors() { + if checked.insert(ancestor.to_path_buf()) { + let f = ancestor.join("package.json"); + match PackageJson::load_skip_read_permission(f) { + Ok(cf) => { + return Ok(Some(cf)); + } + Err(e) => { + if let Some(ioerr) = e.downcast_ref::() { + use std::io::ErrorKind::*; + match ioerr.kind() { + InvalidInput | PermissionDenied | NotFound => { + // ok keep going + } + _ => { + return Err(e); // Unknown error. Stop. + } + } + } else { + return Err(e); // Parse error or something else. Stop. + } + } + } + } + } + Ok(None) + } + + let mut checked = HashSet::new(); + if let Some(package_json_arg) = flags.package_json_args() { + if let Some(pjson) = discover_from(&package_json_arg, &mut checked)? { + return Ok(Some(pjson)); + } + } + + // attempt to resolve the config file from the task subcommand's + // `--cwd` when specified + if let crate::args::DenoSubcommand::Task(TaskFlags { + cwd: Some(path), .. + }) = &flags.subcommand + { + let task_cwd = canonicalize_path(&PathBuf::from(path))?; + if let Some(path) = discover_from(&task_cwd, &mut checked)? { + return Ok(Some(path)); + } + }; + // From CWD walk up to root looking for deno.json or deno.jsonc + let cwd = std::env::current_dir()?; + discover_from(&cwd, &mut checked) +} + /// Indicates how cached source files should be handled. #[derive(Debug, Clone, Eq, PartialEq)] pub enum CacheSetting { @@ -465,6 +527,7 @@ pub struct CliOptions { // application need not concern itself with, so keep these private flags: Flags, maybe_config_file: Option, + maybe_package_json: Option, maybe_lockfile: Option>>, overrides: CliOptionOverrides, } @@ -474,6 +537,7 @@ impl CliOptions { flags: Flags, maybe_config_file: Option, maybe_lockfile: Option, + maybe_package_json: Option, ) -> Self { if let Some(insecure_allowlist) = flags.unsafely_ignore_certificate_errors.as_ref() @@ -494,6 +558,7 @@ impl CliOptions { Self { maybe_config_file, maybe_lockfile, + maybe_package_json, flags, overrides: Default::default(), } @@ -501,9 +566,15 @@ impl CliOptions { pub fn from_flags(flags: Flags) -> Result { let maybe_config_file = ConfigFile::discover(&flags)?; + let maybe_package_json = discover_package_json(&flags)?; let maybe_lock_file = Lockfile::discover(&flags, maybe_config_file.as_ref())?; - Ok(Self::new(flags, maybe_config_file, maybe_lock_file)) + Ok(Self::new( + flags, + maybe_config_file, + maybe_lock_file, + maybe_package_json, + )) } pub fn maybe_config_file_specifier(&self) -> Option { @@ -659,10 +730,6 @@ impl CliOptions { .and_then(|c| c.to_maybe_jsx_import_source_config()) } - pub fn node(&self) -> bool { - self.flags.node - } - /// Return any imports that should be brought into the scope of the module /// graph. pub fn to_maybe_imports(&self) -> MaybeImportsResult { @@ -683,6 +750,10 @@ impl CliOptions { &self.maybe_config_file } + pub fn get_maybe_package_json(&self) -> &Option { + &self.maybe_package_json + } + pub fn resolve_fmt_options( &self, fmt_flags: FmtFlags, diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index b90f613e9fe807..8a95aca71af5fa 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -2963,6 +2963,8 @@ impl Inner { self.maybe_config_file.clone(), // TODO(#16510): add support for lockfile None, + // TODO(bartlomieju): + None, ); cli_options.set_import_map_specifier(self.maybe_import_map_uri.clone()); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index f49c7bf8cf555d..f18169a51a6cdc 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -366,7 +366,7 @@ impl ProcState { let mut maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); - if self.options.node() { + if self.options.get_maybe_package_json().is_some() { maybe_resolver = Some(crate::resolver::BareSpecifierResolver.as_graph_resolver()) } diff --git a/cli/worker.rs b/cli/worker.rs index 6e91a49fc2349e..dfab12628507ea 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -5,7 +5,6 @@ use std::rc::Rc; use std::sync::Arc; use deno_ast::ModuleSpecifier; -use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::task::LocalFutureObj; use deno_core::futures::FutureExt; @@ -16,7 +15,6 @@ use deno_core::v8; use deno_core::Extension; use deno_core::ModuleId; use deno_runtime::colors; -use deno_runtime::deno_node::PackageJson; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; @@ -67,18 +65,8 @@ impl CliMainWorker { self.maybe_setup_coverage_collector().await?; log::debug!("main_module {}", self.main_module); - if self.ps.options.node() { - // TODO(bartlomieju): make it graceful looking for closes package.json - // We're in Node compat mode, try to find `package.json` and load it. - let package_json = PackageJson::load_skip_read_permission( - std::env::current_dir().unwrap().join("package.json"), - ) - .context("Unable to load package.json from CWD")?; - - // NOTE(bartlomieju): we are explicitly not compatible with Node.js here - - // Node defaults to "commonjs" if the "type" entry is missing. We default - // to ESM and only enable CJS if "type" is "commonjs". - self.is_main_cjs = package_json.typ == "commonjs"; + if let Some(package_json) = self.ps.options.get_maybe_package_json() { + self.is_main_cjs = package_json.typ != "module"; // TODO(bartlomieju): could be extracted into a helper function if let Some(deps) = &package_json.dependencies { diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 8a36e95fa27fde..615c940923e387 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -23,6 +23,7 @@ mod resolution; pub use package_json::PackageJson; pub use path::PathClean; pub use resolution::get_closest_package_json; +pub use resolution::get_closest_package_json_path; pub use resolution::get_package_scope_config; pub use resolution::legacy_main_resolve; pub use resolution::package_exports_resolve; diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs index 81a2521b5644f3..98c02511b89d7a 100644 --- a/ext/node/resolution.rs +++ b/ext/node/resolution.rs @@ -831,7 +831,7 @@ pub fn get_closest_package_json( PackageJson::load(npm_resolver, permissions, package_json_path) } -fn get_closest_package_json_path( +pub fn get_closest_package_json_path( url: &ModuleSpecifier, npm_resolver: &dyn RequireNpmResolver, ) -> Result { From f9e4c03903d26e00d0cd82b21e2f9d58659d6cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Jan 2023 17:28:07 +0100 Subject: [PATCH 23/60] wip --- cli/cache/mod.rs | 4 ++++ cli/graph_util.rs | 9 ++++++++- cli/npm/registry.rs | 9 ++++++++- cli/npm/resolution/mod.rs | 3 +++ cli/proc_state.rs | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index e2c461d6c4ae81..2e496a60101d7f 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -69,6 +69,10 @@ impl Loader for FetchCacher { return None; } + if specifier.scheme() == "node" { + return None; + } + let local = self.file_fetcher.get_local_path(specifier)?; if local.is_file() { let emit = self diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 9b2df9ad3e7e00..8074a9b4e449cf 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -219,9 +219,16 @@ impl GraphData { continue; // skip analyzing npm specifiers } + if specifier.as_str().starts_with("node:") { + continue; // skip analyzing node builtins + } + let (specifier, entry) = match self.modules.get_key_value(specifier) { Some(pair) => pair, - None => return None, + None => { + eprintln!("unknown specifier: {}", specifier); + return None; + } }; result.insert(specifier, entry); match entry { diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 0b35079de69ac7..8de3bdd2f3aaeb 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -349,12 +349,19 @@ impl RealNpmRegistryApiInner { maybe_package_info = self.load_file_cached_package_info(name); } + if name == "." { + panic!(); + } if maybe_package_info.is_none() { maybe_package_info = self .load_package_info_from_registry(name) .await .with_context(|| { - format!("Error getting response at {}", self.get_package_url(name)) + format!( + "Error getting response at {} for package {}", + self.get_package_url(name), + name + ) })?; } let maybe_package_info = maybe_package_info.map(Arc::new); diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index e84d342aa1ed75..ffaaeedd4e26b1 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -309,6 +309,9 @@ impl NpmResolution { } else { let api = self.api.clone(); let package_name = package_req.name.clone(); + if package_name == "." { + panic!(); + } unresolved_tasks.push(tokio::task::spawn(async move { // This is ok to call because api will internally cache // the package information in memory. diff --git a/cli/proc_state.rs b/cli/proc_state.rs index d7009d99e79163..cccca688c856d5 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -447,6 +447,7 @@ impl ProcState { ) }; + eprintln!("npm package reqs {:?}", npm_package_reqs); if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; self.prepare_node_std_graph().await?; From 704b95faaba0f21aa2c8de576e92d06de87f2818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Jan 2023 22:47:51 +0100 Subject: [PATCH 24/60] debug --- cli/proc_state.rs | 1 + cli/resolver.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cli/proc_state.rs b/cli/proc_state.rs index cccca688c856d5..79f2f53dca4218 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -430,6 +430,7 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; + eprintln!("before!"); let (npm_package_reqs, has_node_builtin_specifier) = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); diff --git a/cli/resolver.rs b/cli/resolver.rs index 9615514c32046d..b24faac5a1eea9 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -100,6 +100,7 @@ impl Resolver for BareSpecifierResolver { Ok(specifier) => ResolveResponse::Specifier(specifier), Err(err) => match err { ModuleResolutionError::ImportPrefixMissing(_, _) => { + eprintln!("mapping {} {}", specifier, referrer.as_str()); ResolveResponse::Specifier( resolve_import( format!("npm:{}", specifier).as_str(), From 50e135d0ec79f4bd88bb2961cb4e33a341195c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Jan 2023 23:30:09 +0100 Subject: [PATCH 25/60] temp --- cli/args/flags.rs | 4 ++++ cli/args/mod.rs | 4 ++++ cli/cache/mod.rs | 3 ++- cli/graph_util.rs | 7 ++++++- cli/npm/registry.rs | 6 +++++- cli/proc_state.rs | 17 +++++++++++++++-- cli/resolver.rs | 34 ++++++++++++++++++++++++++++++++++ cli/worker.rs | 33 +++++++++++++++++++++++++++++++++ ext/node/package_json.rs | 26 ++++++++++++++++++++++++++ 9 files changed, 129 insertions(+), 5 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 903f936390509e..4761e21833acbf 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -340,6 +340,8 @@ pub struct Flags { pub version: bool, pub watch: Option>, pub no_clear_screen: bool, + + pub node: bool, } fn join_paths(allowlist: &[PathBuf], d: &str) -> String { @@ -1497,6 +1499,7 @@ fn run_subcommand<'a>() -> Command<'a> { ) .arg(no_clear_screen_arg()) .trailing_var_arg(true) + .arg(Arg::new("node").long("node")) .arg(script_arg().required(true)) .about("Run a JavaScript or TypeScript program") .long_about( @@ -2705,6 +2708,7 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.argv.push(v); } + flags.node = matches.is_present("node"); watch_arg_parse(flags, matches, true); flags.subcommand = DenoSubcommand::Run(RunFlags { script }); } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 0f60d09c378002..b76f270ab6c5d5 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -648,6 +648,10 @@ impl CliOptions { .and_then(|c| c.to_maybe_jsx_import_source_config()) } + pub fn node(&self) -> bool { + self.flags.node + } + /// Return any imports that should be brought into the scope of the module /// graph. pub fn to_maybe_imports(&self) -> MaybeImportsResult { diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index e2c461d6c4ae81..cbec1ab5c13fe0 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -65,7 +65,8 @@ impl FetchCacher { impl Loader for FetchCacher { fn get_cache_info(&self, specifier: &ModuleSpecifier) -> Option { - if specifier.scheme() == "npm" { + let scheme = specifier.scheme(); + if scheme == "npm" || scheme == "node" { return None; } diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 9b2df9ad3e7e00..dcae996fcf5ccb 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -217,11 +217,16 @@ impl GraphData { while let Some(specifier) = visiting.pop_front() { if NpmPackageReference::from_specifier(specifier).is_ok() { continue; // skip analyzing npm specifiers + } else if specifier.scheme() == "node" { + continue; // skip analyzing node builtins } let (specifier, entry) = match self.modules.get_key_value(specifier) { Some(pair) => pair, - None => return None, + None => { + eprintln!("Missing module: {}", specifier); + return None; + } }; result.insert(specifier, entry); match entry { diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 0b35079de69ac7..9b0c3c2dc66276 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -354,7 +354,11 @@ impl RealNpmRegistryApiInner { .load_package_info_from_registry(name) .await .with_context(|| { - format!("Error getting response at {}", self.get_package_url(name)) + format!( + "Error getting package info for {} from {}", + name, + self.get_package_url(name), + ) })?; } let maybe_package_info = maybe_package_info.map(Arc::new); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index bca3de5f3c0ab5..b6938d1a5e7b09 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -328,7 +328,15 @@ impl ProcState { }); let roots = roots .into_iter() - .map(|s| (s, ModuleKind::Esm)) + .map(|s| { + (s, { + if self.options.node() { + ModuleKind::External + } else { + ModuleKind::Esm + } + }) + }) .collect::>(); if !has_root_npm_specifier { @@ -359,9 +367,14 @@ impl ProcState { dynamic_permissions, ); let maybe_imports = self.options.to_maybe_imports()?; - let maybe_resolver = + let mut maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); + if self.options.node() { + maybe_resolver = + Some(crate::resolver::BareSpecifierResolver.as_graph_resolver()) + } + struct ProcStateLoader<'a> { inner: &'a mut cache::FetchCacher, graph_data: Arc>, diff --git a/cli/resolver.rs b/cli/resolver.rs index ec46165e02ba12..9615514c32046d 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -1,6 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::resolve_import; +use deno_core::ModuleResolutionError; use deno_core::ModuleSpecifier; use deno_graph::source::ResolveResponse; use deno_graph::source::Resolver; @@ -79,3 +80,36 @@ impl Resolver for CliResolver { } } } + +#[derive(Debug)] +pub struct BareSpecifierResolver; + +impl BareSpecifierResolver { + pub fn as_graph_resolver(&self) -> &dyn Resolver { + self + } +} + +impl Resolver for BareSpecifierResolver { + fn resolve( + &self, + specifier: &str, + referrer: &ModuleSpecifier, + ) -> ResolveResponse { + match resolve_import(specifier, referrer.as_str()) { + Ok(specifier) => ResolveResponse::Specifier(specifier), + Err(err) => match err { + ModuleResolutionError::ImportPrefixMissing(_, _) => { + ResolveResponse::Specifier( + resolve_import( + format!("npm:{}", specifier).as_str(), + referrer.as_str(), + ) + .unwrap(), + ) + } + _ => ResolveResponse::Err(err.into()), + }, + } + } +} diff --git a/cli/worker.rs b/cli/worker.rs index b6ebd793012119..51b60daa9ce64c 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -5,6 +5,7 @@ use std::rc::Rc; use std::sync::Arc; use deno_ast::ModuleSpecifier; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::task::LocalFutureObj; use deno_core::futures::FutureExt; @@ -15,6 +16,7 @@ use deno_core::v8; use deno_core::Extension; use deno_core::ModuleId; use deno_runtime::colors; +use deno_runtime::deno_node::PackageJson; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; @@ -65,6 +67,37 @@ impl CliMainWorker { self.maybe_setup_coverage_collector().await?; log::debug!("main_module {}", self.main_module); + if self.ps.options.node() { + // We're in Node compat mode, try to find `package.json` and load it. + let package_json = PackageJson::load_skip_read_permission( + std::env::current_dir().unwrap().join("package.json"), + ) + .context("Unable to load package.json from CWD")?; + + self.is_main_cjs = package_json.typ != "module"; + + if let Some(deps) = &package_json.dependencies { + let mut reqs = vec![]; + for (key, value) in deps { + let npm_ref = + NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + .unwrap(); + reqs.push(npm_ref.req); + } + self.ps.npm_resolver.add_package_reqs(reqs).await?; + } + if let Some(deps) = &package_json.dev_dependencies { + let mut reqs = vec![]; + for (key, value) in deps { + let npm_ref = + NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + .unwrap(); + reqs.push(npm_ref.req); + } + self.ps.npm_resolver.add_package_reqs(reqs).await?; + } + } + if self.is_main_cjs { self.ps.prepare_node_std_graph().await?; self.initialize_main_module_for_node().await?; diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs index 5894b883138c57..debbe0cb6d2969 100644 --- a/ext/node/package_json.rs +++ b/ext/node/package_json.rs @@ -11,6 +11,7 @@ use deno_core::serde_json; use deno_core::serde_json::Map; use deno_core::serde_json::Value; use serde::Serialize; +use std::collections::HashMap; use std::io::ErrorKind; use std::path::PathBuf; @@ -27,6 +28,8 @@ pub struct PackageJson { pub path: PathBuf, pub typ: String, pub types: Option, + pub dependencies: Option>, + pub dev_dependencies: Option>, } impl PackageJson { @@ -43,6 +46,8 @@ impl PackageJson { path, typ: "none".to_string(), types: None, + dependencies: None, + dev_dependencies: None, } } @@ -102,6 +107,25 @@ impl PackageJson { let version = version_val.and_then(|s| s.as_str()).map(|s| s.to_string()); let module = module_val.and_then(|s| s.as_str()).map(|s| s.to_string()); + let dependencies = package_json.get("dependencies").and_then(|d| { + if d.is_object() { + let deps: HashMap = + serde_json::from_value(d.to_owned()).unwrap(); + Some(deps) + } else { + None + } + }); + let dev_dependencies = package_json.get("devDependencies").and_then(|d| { + if d.is_object() { + let deps: HashMap = + serde_json::from_value(d.to_owned()).unwrap(); + Some(deps) + } else { + None + } + }); + // Ignore unknown types for forwards compatibility let typ = if let Some(t) = type_val { if let Some(t) = t.as_str() { @@ -135,6 +159,8 @@ impl PackageJson { exports, imports, bin, + dependencies, + dev_dependencies, }; Ok(package_json) } From b1177afdd7fe601a8b46b0e81bc8bca88c330242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 20 Jan 2023 00:01:42 +0100 Subject: [PATCH 26/60] Debug --- cli/args/mod.rs | 9 +++++++++ cli/cache/mod.rs | 14 ++++++++++++++ cli/graph_util.rs | 1 + cli/proc_state.rs | 7 ++++++- cli/resolver.rs | 3 +++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index c8fbcdf1ac8429..1efe5c17bcd73b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -20,6 +20,7 @@ pub use config_file::TsConfig; pub use config_file::TsConfigForEmit; pub use config_file::TsConfigType; pub use config_file::TsTypeLib; +use deno_core::resolve_url_or_path; use deno_runtime::deno_node::PackageJson; pub use flags::*; pub use lockfile::Lockfile; @@ -672,6 +673,14 @@ impl CliOptions { ) } + pub fn main_module(&self) -> Option { + if let DenoSubcommand::Run(run_flags) = &self.flags.subcommand { + Some(resolve_url_or_path(&run_flags.script).unwrap()) + } else { + None + } + } + /// Resolves the storage key to use based on the current flags, config, or main module. pub fn resolve_storage_key( &self, diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 2e496a60101d7f..83060479019458 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -45,6 +45,7 @@ pub struct FetchCacher { dynamic_permissions: PermissionsContainer, file_fetcher: Arc, root_permissions: PermissionsContainer, + package_json_main_module: Option, } impl FetchCacher { @@ -53,12 +54,14 @@ impl FetchCacher { file_fetcher: Arc, root_permissions: PermissionsContainer, dynamic_permissions: PermissionsContainer, + package_json_main_module: Option, ) -> Self { Self { emit_cache, dynamic_permissions, file_fetcher, root_permissions, + package_json_main_module, } } } @@ -94,6 +97,17 @@ impl Loader for FetchCacher { specifier: &ModuleSpecifier, is_dynamic: bool, ) -> LoadFuture { + if let Some(package_json_main_module) = &self.package_json_main_module { + eprintln!("returning external {} {}", specifier.as_str(), is_dynamic); + if specifier == package_json_main_module { + return Box::pin(futures::future::ready(Ok(Some( + deno_graph::source::LoadResponse::External { + specifier: specifier.clone(), + }, + )))); + } + } + if specifier.scheme() == "npm" { return Box::pin(futures::future::ready( match npm::NpmPackageReference::from_specifier(specifier) { diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 8074a9b4e449cf..916d943075e766 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -536,6 +536,7 @@ pub async fn create_graph_and_maybe_check( ps.file_fetcher.clone(), PermissionsContainer::allow_all(), PermissionsContainer::allow_all(), + None, ); let maybe_imports = ps.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 79f2f53dca4218..14761ee52212c7 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -357,6 +357,11 @@ impl ProcState { self.file_fetcher.clone(), root_permissions, dynamic_permissions, + if self.options.get_maybe_package_json().is_some() { + Some(roots[0].0.clone()) + } else { + None + }, ); let maybe_imports = self.options.to_maybe_imports()?; let mut maybe_resolver = @@ -430,7 +435,6 @@ impl ProcState { graph_data.entries().map(|(s, _)| s).cloned().collect() }; - eprintln!("before!"); let (npm_package_reqs, has_node_builtin_specifier) = { let mut graph_data = self.graph_data.write(); graph_data.add_graph(&graph); @@ -720,6 +724,7 @@ impl ProcState { self.file_fetcher.clone(), PermissionsContainer::allow_all(), PermissionsContainer::allow_all(), + None, ) } diff --git a/cli/resolver.rs b/cli/resolver.rs index b24faac5a1eea9..93d910da95bfff 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -100,6 +100,9 @@ impl Resolver for BareSpecifierResolver { Ok(specifier) => ResolveResponse::Specifier(specifier), Err(err) => match err { ModuleResolutionError::ImportPrefixMissing(_, _) => { + if specifier == "." { + panic!() + } eprintln!("mapping {} {}", specifier, referrer.as_str()); ResolveResponse::Specifier( resolve_import( From 739a885f68a3b09f21d270af75c76e98605a482a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 28 Jan 2023 22:24:54 +0100 Subject: [PATCH 27/60] lint --- cli/args/flags.rs | 3 --- cli/args/mod.rs | 13 ---------- cli/proc_state.rs | 4 +-- cli/resolver.rs | 57 +++++++------------------------------------ cli/worker.rs | 6 ++--- foo.js | 3 --- foo2.js | 1 - node_builtin.js | 8 ------ node_builtin.ts | 8 ------ runtime/ops/signal.rs | 4 +-- 10 files changed, 15 insertions(+), 92 deletions(-) delete mode 100644 foo.js delete mode 100644 foo2.js delete mode 100644 node_builtin.js delete mode 100644 node_builtin.ts diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 9d15ff7586db19..f01792378e52ef 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -350,8 +350,6 @@ pub struct Flags { pub version: bool, pub watch: Option>, pub no_clear_screen: bool, - - pub node: bool, } fn join_paths(allowlist: &[PathBuf], d: &str) -> String { @@ -2757,7 +2755,6 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.argv.push(v); } - flags.node = matches.is_present("node"); watch_arg_parse(flags, matches, true); flags.subcommand = DenoSubcommand::Run(RunFlags { script }); } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f47a44240887c8..cd75a5dfb26849 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -23,7 +23,6 @@ pub use config_file::TsConfig; pub use config_file::TsConfigForEmit; pub use config_file::TsConfigType; pub use config_file::TsTypeLib; -use deno_core::resolve_url_or_path; use deno_runtime::deno_node::PackageJson; pub use flags::*; pub use lockfile::Lockfile; @@ -702,14 +701,6 @@ impl CliOptions { ) } - pub fn main_module(&self) -> Option { - if let DenoSubcommand::Run(run_flags) = &self.flags.subcommand { - Some(resolve_url_or_path(&run_flags.script).unwrap()) - } else { - None - } - } - /// Resolves the storage key to use based on the current flags, config, or main module. pub fn resolve_storage_key( &self, @@ -768,10 +759,6 @@ impl CliOptions { .and_then(|c| c.to_maybe_jsx_import_source_config()) } - pub fn node(&self) -> bool { - self.flags.node - } - /// Return any imports that should be brought into the scope of the module /// graph. pub fn to_maybe_imports(&self) -> MaybeImportsResult { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 08634f5507692f..9de44957712cac 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -338,7 +338,7 @@ impl ProcState { root_permissions, dynamic_permissions, if self.options.get_maybe_package_json().is_some() { - Some(roots[0].0.clone()) + Some(roots[0].clone()) } else { None }, @@ -432,7 +432,7 @@ impl ProcState { ) }; - eprintln!("npm package reqs {:?}", npm_package_reqs); + eprintln!("npm package reqs {npm_package_reqs:?}"); if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; self.prepare_node_std_graph().await?; diff --git a/cli/resolver.rs b/cli/resolver.rs index 5184ccb24c1abe..16e3e136c869bb 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -89,57 +89,18 @@ impl Resolver for BareSpecifierResolver { &self, specifier: &str, referrer: &ModuleSpecifier, - ) -> ResolveResponse { - match resolve_import(specifier, referrer.as_str()) { - Ok(specifier) => ResolveResponse::Specifier(specifier), - Err(err) => match err { - ModuleResolutionError::ImportPrefixMissing(_, _) => { - ResolveResponse::Specifier( - resolve_import( - format!("npm:{}", specifier).as_str(), - referrer.as_str(), - ) - .unwrap(), - ) - } - _ => ResolveResponse::Err(err.into()), - }, - } - } -} - -#[derive(Debug)] -pub struct BareSpecifierResolver; - -impl BareSpecifierResolver { - pub fn as_graph_resolver(&self) -> &dyn Resolver { - self - } -} - -impl Resolver for BareSpecifierResolver { - fn resolve( - &self, - specifier: &str, - referrer: &ModuleSpecifier, - ) -> ResolveResponse { + ) -> Result { match resolve_import(specifier, referrer.as_str()) { - Ok(specifier) => ResolveResponse::Specifier(specifier), + Ok(specifier) => Ok(specifier), Err(err) => match err { - ModuleResolutionError::ImportPrefixMissing(_, _) => { - if specifier == "." { - panic!() - } - eprintln!("mapping {} {}", specifier, referrer.as_str()); - ResolveResponse::Specifier( - resolve_import( - format!("npm:{}", specifier).as_str(), - referrer.as_str(), - ) - .unwrap(), + ModuleResolutionError::ImportPrefixMissing(_, _) => Ok( + resolve_import( + format!("npm:{specifier}").as_str(), + referrer.as_str(), ) - } - _ => ResolveResponse::Err(err.into()), + .unwrap(), + ), + _ => Err(err.into()), }, } } diff --git a/cli/worker.rs b/cli/worker.rs index 82e6768fe2dab2..601c8e5a13d1ad 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -5,7 +5,6 @@ use std::rc::Rc; use std::sync::Arc; use deno_ast::ModuleSpecifier; -use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::task::LocalFutureObj; use deno_core::futures::FutureExt; @@ -16,7 +15,6 @@ use deno_core::v8; use deno_core::Extension; use deno_core::ModuleId; use deno_runtime::colors; -use deno_runtime::deno_node::PackageJson; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::WorkerEventCb; @@ -75,7 +73,7 @@ impl CliMainWorker { let mut reqs = vec![]; for (key, value) in deps { let npm_ref = - NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + NpmPackageReference::from_str(&format!("npm:{key}@{value}")) .unwrap(); reqs.push(npm_ref.req); } @@ -85,7 +83,7 @@ impl CliMainWorker { let mut reqs = vec![]; for (key, value) in deps { let npm_ref = - NpmPackageReference::from_str(&format!("npm:{}@{}", key, value)) + NpmPackageReference::from_str(&format!("npm:{key}@{value}")) .unwrap(); reqs.push(npm_ref.req); } diff --git a/foo.js b/foo.js deleted file mode 100644 index 53838926553470..00000000000000 --- a/foo.js +++ /dev/null @@ -1,3 +0,0 @@ -import cowsay from "cowsay"; - -console.log(cowsay); diff --git a/foo2.js b/foo2.js deleted file mode 100644 index 866975c39d6360..00000000000000 --- a/foo2.js +++ /dev/null @@ -1 +0,0 @@ -imp; diff --git a/node_builtin.js b/node_builtin.js deleted file mode 100644 index 7ba49ab49da255..00000000000000 --- a/node_builtin.js +++ /dev/null @@ -1,8 +0,0 @@ -import fs from "node:fs"; - -try { - const data = fs.readFileSync("./node_builtin.ts", "utf8"); - console.log(data); -} catch (err) { - console.error(err); -} diff --git a/node_builtin.ts b/node_builtin.ts deleted file mode 100644 index fbbb3129596d19..00000000000000 --- a/node_builtin.ts +++ /dev/null @@ -1,8 +0,0 @@ -import fs from "node:fs"; - -try { - const data = fs.readFileSync("./node_builtin.js", "utf8"); - console.log(data); -} catch (err) { - console.error(err); -} diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index f88d870582f001..39458bad98fc27 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -298,7 +298,7 @@ pub fn signal_str_to_int(s: &str) -> Result { "SIGINFO" => Ok(29), "SIGUSR1" => Ok(30), "SIGUSR2" => Ok(31), - _ => Err(type_error(format!("Invalid signal: {}", s))), + _ => Err(type_error(format!("Invalid signal: {s}"))), } } @@ -336,7 +336,7 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> { 29 => Ok("SIGINFO"), 30 => Ok("SIGUSR1"), 31 => Ok("SIGUSR2"), - _ => Err(type_error(format!("Invalid signal: {}", s))), + _ => Err(type_error(format!("Invalid signal: {s}"))), } } From b86b279a7ccecb3f99ed060c0fb100a32d1dbe9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 28 Jan 2023 22:59:31 +0100 Subject: [PATCH 28/60] works with simple ESM express app --- cli/args/flags.rs | 7 ++++++- cli/args/mod.rs | 1 + cli/cache/mod.rs | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index f01792378e52ef..8636d09eec5727 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -508,7 +508,12 @@ impl Flags { if let Run(RunFlags { script }) = &self.subcommand { if let Ok(module_specifier) = deno_core::resolve_url_or_path(script) { if module_specifier.scheme() == "file" { - let p = module_specifier.to_file_path().unwrap(); + let p = module_specifier + .to_file_path() + .unwrap() + .parent() + .unwrap() + .to_owned(); return Some(p); } } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index cd75a5dfb26849..cec9900c63cac6 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -80,6 +80,7 @@ fn discover_package_json( return Ok(Some(cf)); } Err(e) => { + eprintln!("err {:#?}", e); if let Some(ioerr) = e.downcast_ref::() { use std::io::ErrorKind::*; match ioerr.kind() { diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index be9a8cf7e95961..bef7dd0ae80ade 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -97,16 +97,16 @@ impl Loader for FetchCacher { specifier: &ModuleSpecifier, is_dynamic: bool, ) -> LoadFuture { - if let Some(package_json_main_module) = &self.package_json_main_module { - eprintln!("returning external {} {}", specifier.as_str(), is_dynamic); - if specifier == package_json_main_module { - return Box::pin(futures::future::ready(Ok(Some( - deno_graph::source::LoadResponse::External { - specifier: specifier.clone(), - }, - )))); - } - } + // if let Some(package_json_main_module) = &self.package_json_main_module { + // eprintln!("returning external {} {}", specifier.as_str(), is_dynamic); + // if specifier == package_json_main_module { + // return Box::pin(futures::future::ready(Ok(Some( + // deno_graph::source::LoadResponse::External { + // specifier: specifier.clone(), + // }, + // )))); + // } + // } if specifier.scheme() == "npm" { return Box::pin(futures::future::ready( From c46ab646985e6cdcb2e71adb42f4fe75a883461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 30 Jan 2023 22:31:07 +0100 Subject: [PATCH 29/60] revert some changes --- cli/args/flags.rs | 2 +- cli/npm/registry.rs | 3 - package-lock.json | 711 -------------------------------------------- package.json | 8 - 4 files changed, 1 insertion(+), 723 deletions(-) delete mode 100644 package-lock.json delete mode 100644 package.json diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 8636d09eec5727..0a0a8c5a4423a8 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -508,6 +508,7 @@ impl Flags { if let Run(RunFlags { script }) = &self.subcommand { if let Ok(module_specifier) = deno_core::resolve_url_or_path(script) { if module_specifier.scheme() == "file" { + // TODO(bartlomieju): probably not safe with all these unwraps here let p = module_specifier .to_file_path() .unwrap() @@ -1548,7 +1549,6 @@ fn run_subcommand<'a>() -> Command<'a> { ) .arg(no_clear_screen_arg()) .trailing_var_arg(true) - .arg(Arg::new("node").long("node")) .arg(script_arg().required(true)) .about("Run a JavaScript or TypeScript program") .long_about( diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 891992494ca7ec..14223d0d696e67 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -335,9 +335,6 @@ impl RealNpmRegistryApiInner { maybe_package_info = self.load_file_cached_package_info(name); } - if name == "." { - panic!(); - } if maybe_package_info.is_none() { maybe_package_info = self .load_package_info_from_registry(name) diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index d985284950afc2..00000000000000 --- a/package-lock.json +++ /dev/null @@ -1,711 +0,0 @@ -{ - "name": "deno", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "dependencies": { - "cowsay": "^1.5.0" - } - }, - "node_modules/ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", - "engines": { - "node": ">=4" - } - }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", - "engines": { - "node": ">=6" - } - }, - "node_modules/cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" - } - }, - "node_modules/cliui/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/cowsay": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/cowsay/-/cowsay-1.5.0.tgz", - "integrity": "sha512-8Ipzr54Z8zROr/62C8f0PdhQcDusS05gKTS87xxdji8VbWefWly0k8BwGK7+VqamOrkv3eGsCkPtvlHzrhWsCA==", - "dependencies": { - "get-stdin": "8.0.0", - "string-width": "~2.1.1", - "strip-final-newline": "2.0.0", - "yargs": "15.4.1" - }, - "bin": { - "cowsay": "cli.js", - "cowthink": "cli.js" - }, - "engines": { - "node": ">= 4" - } - }, - "node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "node_modules/find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, - "node_modules/get-stdin": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", - "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", - "engines": { - "node": ">=4" - } - }, - "node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "engines": { - "node": ">=6" - } - }, - "node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "engines": { - "node": ">=8" - } - }, - "node_modules/require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" - }, - "node_modules/set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" - }, - "node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", - "dependencies": { - "ansi-regex": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "engines": { - "node": ">=6" - } - }, - "node_modules/which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" - }, - "node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/wrap-ansi/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "engines": { - "node": ">=8" - } - }, - "node_modules/wrap-ansi/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/wrap-ansi/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" - }, - "node_modules/yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", - "dependencies": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/yargs/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/yargs/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "engines": { - "node": ">=8" - } - }, - "node_modules/yargs/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/yargs/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - } - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==" - }, - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "requires": { - "color-convert": "^2.0.1" - } - }, - "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" - }, - "cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", - "requires": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" - }, - "dependencies": { - "ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" - }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - }, - "strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "requires": { - "ansi-regex": "^5.0.1" - } - } - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "cowsay": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/cowsay/-/cowsay-1.5.0.tgz", - "integrity": "sha512-8Ipzr54Z8zROr/62C8f0PdhQcDusS05gKTS87xxdji8VbWefWly0k8BwGK7+VqamOrkv3eGsCkPtvlHzrhWsCA==", - "requires": { - "get-stdin": "8.0.0", - "string-width": "~2.1.1", - "strip-final-newline": "2.0.0", - "yargs": "15.4.1" - } - }, - "decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==" - }, - "emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "requires": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - } - }, - "get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" - }, - "get-stdin": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", - "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==" - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==" - }, - "locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "requires": { - "p-locate": "^4.1.0" - } - }, - "p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "requires": { - "p-try": "^2.0.0" - } - }, - "p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "requires": { - "p-limit": "^2.2.0" - } - }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" - }, - "path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" - }, - "require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==" - }, - "require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" - }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", - "requires": { - "ansi-regex": "^3.0.0" - } - }, - "strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" - }, - "which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==" - }, - "wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "requires": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" - }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - }, - "strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "requires": { - "ansi-regex": "^5.0.1" - } - } - } - }, - "y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" - }, - "yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", - "requires": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" - }, - "dependencies": { - "ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" - }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - }, - "strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "requires": { - "ansi-regex": "^5.0.1" - } - } - } - }, - "yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index ea1024629a383e..00000000000000 --- a/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "foobar", - "version": "0.0.1", - "type": "module", - "dependencies": { - "cowsay": "^1.5.0" - } -} From 43e1d8aea544227e120969920dd541bfd7e9bbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 30 Jan 2023 22:35:21 +0100 Subject: [PATCH 30/60] revert some changes 2 --- cli/args/mod.rs | 1 - cli/cache/mod.rs | 14 -------------- cli/graph_util.rs | 1 - cli/npm/resolution/mod.rs | 3 --- cli/proc_state.rs | 14 +------------- cli/resolver.rs | 32 -------------------------------- cli/worker.rs | 26 -------------------------- ext/node/lib.rs | 1 - ext/node/resolution.rs | 2 +- 9 files changed, 2 insertions(+), 92 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index cec9900c63cac6..cd75a5dfb26849 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -80,7 +80,6 @@ fn discover_package_json( return Ok(Some(cf)); } Err(e) => { - eprintln!("err {:#?}", e); if let Some(ioerr) = e.downcast_ref::() { use std::io::ErrorKind::*; match ioerr.kind() { diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 2380e90f23a62a..fd90becb29fa1b 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -45,7 +45,6 @@ pub struct FetchCacher { dynamic_permissions: PermissionsContainer, file_fetcher: Arc, root_permissions: PermissionsContainer, - package_json_main_module: Option, } impl FetchCacher { @@ -54,7 +53,6 @@ impl FetchCacher { file_fetcher: FileFetcher, root_permissions: PermissionsContainer, dynamic_permissions: PermissionsContainer, - package_json_main_module: Option, ) -> Self { let file_fetcher = Arc::new(file_fetcher); @@ -63,7 +61,6 @@ impl FetchCacher { dynamic_permissions, file_fetcher, root_permissions, - package_json_main_module, } } } @@ -99,17 +96,6 @@ impl Loader for FetchCacher { specifier: &ModuleSpecifier, is_dynamic: bool, ) -> LoadFuture { - // if let Some(package_json_main_module) = &self.package_json_main_module { - // eprintln!("returning external {} {}", specifier.as_str(), is_dynamic); - // if specifier == package_json_main_module { - // return Box::pin(futures::future::ready(Ok(Some( - // deno_graph::source::LoadResponse::External { - // specifier: specifier.clone(), - // }, - // )))); - // } - // } - if specifier.scheme() == "npm" { return Box::pin(futures::future::ready( match npm::NpmPackageReference::from_specifier(specifier) { diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 00df841610f517..30b426667b7fe8 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -523,7 +523,6 @@ pub async fn create_graph_and_maybe_check( ps.file_fetcher.clone(), PermissionsContainer::allow_all(), PermissionsContainer::allow_all(), - None, ); let maybe_imports = ps.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index a108c3b1b0753d..407651ccb996b2 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -309,9 +309,6 @@ impl NpmResolution { } else { let api = self.api.clone(); let package_name = package_req.name.clone(); - if package_name == "." { - panic!(); - } unresolved_tasks.push(tokio::task::spawn(async move { // This is ok to call because api will internally cache // the package information in memory. diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 214db02a810d2d..d161a3334b8566 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -306,21 +306,11 @@ impl ProcState { self.file_fetcher.clone(), root_permissions, dynamic_permissions, - if self.options.get_maybe_package_json().is_some() { - Some(roots[0].clone()) - } else { - None - }, ); let maybe_imports = self.options.to_maybe_imports()?; - let mut maybe_resolver = + let maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); - if self.options.get_maybe_package_json().is_some() { - maybe_resolver = - Some(crate::resolver::BareSpecifierResolver.as_graph_resolver()) - } - struct ProcStateLoader<'a> { inner: &'a mut cache::FetchCacher, graph_data: Arc>, @@ -405,7 +395,6 @@ impl ProcState { ) }; - eprintln!("npm package reqs {npm_package_reqs:?}"); if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; self.prepare_node_std_graph().await?; @@ -675,7 +664,6 @@ impl ProcState { self.file_fetcher.clone(), PermissionsContainer::allow_all(), PermissionsContainer::allow_all(), - None, ) } diff --git a/cli/resolver.rs b/cli/resolver.rs index 16e3e136c869bb..817b5d3b080267 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -2,7 +2,6 @@ use deno_core::error::AnyError; use deno_core::resolve_import; -use deno_core::ModuleResolutionError; use deno_core::ModuleSpecifier; use deno_graph::source::Resolver; use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; @@ -74,34 +73,3 @@ impl Resolver for CliResolver { } } } - -#[derive(Debug)] -pub struct BareSpecifierResolver; - -impl BareSpecifierResolver { - pub fn as_graph_resolver(&self) -> &dyn Resolver { - self - } -} - -impl Resolver for BareSpecifierResolver { - fn resolve( - &self, - specifier: &str, - referrer: &ModuleSpecifier, - ) -> Result { - match resolve_import(specifier, referrer.as_str()) { - Ok(specifier) => Ok(specifier), - Err(err) => match err { - ModuleResolutionError::ImportPrefixMissing(_, _) => Ok( - resolve_import( - format!("npm:{specifier}").as_str(), - referrer.as_str(), - ) - .unwrap(), - ), - _ => Err(err.into()), - }, - } - } -} diff --git a/cli/worker.rs b/cli/worker.rs index 601c8e5a13d1ad..60663ebc034e6f 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -65,32 +65,6 @@ impl CliMainWorker { self.maybe_setup_coverage_collector().await?; log::debug!("main_module {}", self.main_module); - if let Some(package_json) = self.ps.options.get_maybe_package_json() { - self.is_main_cjs = package_json.typ != "module"; - - // TODO(bartlomieju): could be extracted into a helper function - if let Some(deps) = &package_json.dependencies { - let mut reqs = vec![]; - for (key, value) in deps { - let npm_ref = - NpmPackageReference::from_str(&format!("npm:{key}@{value}")) - .unwrap(); - reqs.push(npm_ref.req); - } - self.ps.npm_resolver.add_package_reqs(reqs).await?; - } - if let Some(deps) = &package_json.dev_dependencies { - let mut reqs = vec![]; - for (key, value) in deps { - let npm_ref = - NpmPackageReference::from_str(&format!("npm:{key}@{value}")) - .unwrap(); - reqs.push(npm_ref.req); - } - self.ps.npm_resolver.add_package_reqs(reqs).await?; - } - } - if self.is_main_cjs { self.ps.prepare_node_std_graph().await?; self.initialize_main_module_for_node().await?; diff --git a/ext/node/lib.rs b/ext/node/lib.rs index fb65fb6a0f5b8d..3c0e323086f4f3 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -23,7 +23,6 @@ mod resolution; pub use package_json::PackageJson; pub use path::PathClean; pub use resolution::get_closest_package_json; -pub use resolution::get_closest_package_json_path; pub use resolution::get_package_scope_config; pub use resolution::legacy_main_resolve; pub use resolution::package_exports_resolve; diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs index d1be2f51f608f1..ccd272741c68c1 100644 --- a/ext/node/resolution.rs +++ b/ext/node/resolution.rs @@ -831,7 +831,7 @@ pub fn get_closest_package_json( PackageJson::load(npm_resolver, permissions, package_json_path) } -pub fn get_closest_package_json_path( +fn get_closest_package_json_path( url: &ModuleSpecifier, npm_resolver: &dyn RequireNpmResolver, ) -> Result { From f87271ec6b429cd5364c3172cea1763c00677b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 30 Jan 2023 23:14:33 +0100 Subject: [PATCH 31/60] working! --- cli/args/mod.rs | 74 ++++++++++++-------------------------------- cli/graph_util.rs | 1 + cli/lsp/documents.rs | 2 +- cli/proc_state.rs | 2 ++ cli/resolver.rs | 47 ++++++++++++++++++++++++---- 5 files changed, 65 insertions(+), 61 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index cd75a5dfb26849..b10549a69e12cb 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -45,13 +45,11 @@ use deno_runtime::deno_tls::webpki_roots; use deno_runtime::inspector_server::InspectorServer; use deno_runtime::permissions::PermissionsOptions; use std::collections::BTreeMap; -use std::collections::HashSet; use std::env; use std::io::BufReader; use std::io::Cursor; use std::net::SocketAddr; use std::num::NonZeroUsize; -use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -68,59 +66,23 @@ use self::config_file::TestConfig; fn discover_package_json( flags: &Flags, ) -> Result, AnyError> { - fn discover_from( - start: &Path, - checked: &mut HashSet, - ) -> Result, AnyError> { - for ancestor in start.ancestors() { - if checked.insert(ancestor.to_path_buf()) { - let f = ancestor.join("package.json"); - match PackageJson::load_skip_read_permission(f) { - Ok(cf) => { - return Ok(Some(cf)); - } - Err(e) => { - if let Some(ioerr) = e.downcast_ref::() { - use std::io::ErrorKind::*; - match ioerr.kind() { - InvalidInput | PermissionDenied | NotFound => { - // ok keep going - } - _ => { - return Err(e); // Unknown error. Stop. - } - } - } else { - return Err(e); // Parse error or something else. Stop. - } - } - } - } - } - Ok(None) - } - - let mut checked = HashSet::new(); if let Some(package_json_arg) = flags.package_json_args() { - if let Some(pjson) = discover_from(&package_json_arg, &mut checked)? { - return Ok(Some(pjson)); - } - } - - // attempt to resolve the config file from the task subcommand's - // `--cwd` when specified - if let crate::args::DenoSubcommand::Task(TaskFlags { - cwd: Some(path), .. + let pjson_path = package_json_arg.join("package.json"); + let pjson = PackageJson::load_skip_read_permission(pjson_path)?; + return Ok(Some(pjson)); + } else if let crate::args::DenoSubcommand::Task(TaskFlags { + cwd: Some(path), + .. }) = &flags.subcommand { + // attempt to resolve the config file from the task subcommand's + // `--cwd` when specified let task_cwd = canonicalize_path(&PathBuf::from(path))?; - if let Some(path) = discover_from(&task_cwd, &mut checked)? { - return Ok(Some(path)); - } - }; - // From CWD walk up to root looking for deno.json or deno.jsonc - let cwd = std::env::current_dir()?; - discover_from(&cwd, &mut checked) + let pjson_path = task_cwd.join("package.json"); + let pjson = PackageJson::load_skip_read_permission(pjson_path)?; + return Ok(Some(pjson)); + } + Ok(None) } /// Indicates how cached source files should be handled. @@ -574,7 +536,11 @@ impl CliOptions { pub fn from_flags(flags: Flags) -> Result { let maybe_config_file = ConfigFile::discover(&flags)?; - let maybe_package_json = discover_package_json(&flags)?; + let maybe_package_json = if maybe_config_file.is_none() { + discover_package_json(&flags)? + } else { + None + }; let maybe_lock_file = lockfile::discover(&flags, maybe_config_file.as_ref())?; Ok(Self::new( @@ -779,8 +745,8 @@ impl CliOptions { &self.maybe_config_file } - pub fn get_maybe_package_json(&self) -> &Option { - &self.maybe_package_json + pub fn get_maybe_package_json(&self) -> Option { + self.maybe_package_json.clone() } pub fn resolve_fmt_options( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 30b426667b7fe8..756f632c13f912 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -528,6 +528,7 @@ pub async fn create_graph_and_maybe_check( let maybe_cli_resolver = CliResolver::maybe_new( ps.options.to_maybe_jsx_import_source_config(), ps.maybe_import_map.clone(), + ps.options.get_maybe_package_json(), ); let maybe_graph_resolver = maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 152834af6f56e8..c3313e5ba4148e 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1185,7 +1185,7 @@ impl Documents { maybe_jsx_config.as_ref(), ); self.maybe_resolver = - CliResolver::maybe_new(maybe_jsx_config, maybe_import_map); + CliResolver::maybe_new(maybe_jsx_config, maybe_import_map, None); self.imports = Arc::new( if let Some(Ok(Some(imports))) = maybe_config_file.map(|cf| cf.to_maybe_imports()) diff --git a/cli/proc_state.rs b/cli/proc_state.rs index d161a3334b8566..b128fd7d88ca4a 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -184,6 +184,7 @@ impl ProcState { let maybe_cli_resolver = CliResolver::maybe_new( cli_options.to_maybe_jsx_import_source_config(), maybe_import_map.clone(), + cli_options.get_maybe_package_json(), ); let maybe_resolver = maybe_cli_resolver.map(Arc::new); @@ -685,6 +686,7 @@ impl ProcState { let maybe_cli_resolver = CliResolver::maybe_new( self.options.to_maybe_jsx_import_source_config(), self.maybe_import_map.clone(), + self.options.get_maybe_package_json(), ); let maybe_graph_resolver = maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); diff --git a/cli/resolver.rs b/cli/resolver.rs index 817b5d3b080267..983472cfc9ec00 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -5,6 +5,7 @@ use deno_core::resolve_import; use deno_core::ModuleSpecifier; use deno_graph::source::Resolver; use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; +use deno_runtime::deno_node::PackageJson; use import_map::ImportMap; use std::sync::Arc; @@ -15,6 +16,7 @@ use crate::args::JsxImportSourceConfig; #[derive(Debug, Clone, Default)] pub struct CliResolver { maybe_import_map: Option>, + maybe_package_json: Option, maybe_default_jsx_import_source: Option, maybe_jsx_import_source_module: Option, } @@ -23,10 +25,15 @@ impl CliResolver { pub fn maybe_new( maybe_jsx_import_source_config: Option, maybe_import_map: Option>, + maybe_package_json: Option, ) -> Option { - if maybe_jsx_import_source_config.is_some() || maybe_import_map.is_some() { + if maybe_jsx_import_source_config.is_some() + || maybe_import_map.is_some() + || maybe_package_json.is_some() + { Some(Self { maybe_import_map, + maybe_package_json, maybe_default_jsx_import_source: maybe_jsx_import_source_config .as_ref() .and_then(|c| c.default_specifier.clone()), @@ -39,7 +46,7 @@ impl CliResolver { } pub fn with_import_map(import_map: Arc) -> Self { - Self::maybe_new(None, Some(import_map)).unwrap() + Self::maybe_new(None, Some(import_map), None).unwrap() } pub fn as_graph_resolver(&self) -> &dyn Resolver { @@ -65,11 +72,39 @@ impl Resolver for CliResolver { referrer: &ModuleSpecifier, ) -> Result { if let Some(import_map) = &self.maybe_import_map { - import_map + return import_map .resolve(specifier, referrer) - .map_err(|err| err.into()) - } else { - resolve_import(specifier, referrer.as_str()).map_err(|err| err.into()) + .map_err(|err| err.into()); } + + if let Some(pjson) = self.maybe_package_json.as_ref() { + let maybe_specifier_and_version = if let Some(deps) = &pjson.dependencies + { + if deps.contains_key(specifier) { + let version = deps.get(specifier).unwrap(); + Some((specifier, version)) + } else { + None + } + } else if let Some(dev_deps) = &pjson.dev_dependencies { + if dev_deps.contains_key(specifier) { + let version = dev_deps.get(specifier).unwrap(); + Some((specifier, version)) + } else { + None + } + } else { + None + }; + + if let Some((specifier, version)) = maybe_specifier_and_version { + return Ok( + ModuleSpecifier::parse(&format!("npm:{specifier}@{version}")) + .unwrap(), + ); + } + } + + resolve_import(specifier, referrer.as_str()).map_err(|err| err.into()) } } From 54beff70a225f35faa18be1caa9526203a31b948 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 31 Jan 2023 21:36:33 -0500 Subject: [PATCH 32/60] Add `NpmPackageReq::from_dependency_entry`. --- cli/npm/registry.rs | 20 +++---------------- cli/npm/resolution/mod.rs | 3 ++- cli/npm/resolution/reference.rs | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 25ecda8ec74232..1fc7cfd75a43eb 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -31,6 +31,7 @@ use crate::util::fs::atomic_write_file; use crate::util::progress_bar::ProgressBar; use super::cache::NpmCache; +use super::resolution::parse_dep_entry_name_and_version; // npm registry docs: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md @@ -116,26 +117,11 @@ impl NpmPackageVersionInfo { entry: (&String, &String), kind: NpmDependencyEntryKind, ) -> Result { - let bare_specifier = entry.0.clone(); let (name, version_req) = - if let Some(package_and_version) = entry.1.strip_prefix("npm:") { - if let Some((name, version)) = package_and_version.rsplit_once('@') { - (name.to_string(), version.to_string()) - } else { - bail!("could not find @ symbol in npm url '{}'", entry.1); - } - } else { - (entry.0.clone(), entry.1.clone()) - }; - let version_req = - VersionReq::parse_from_npm(&version_req).with_context(|| { - format!( - "error parsing version requirement for dependency: {bare_specifier}@{version_req}" - ) - })?; + parse_dep_entry_name_and_version(entry.0.as_str(), entry.1.as_str())?; Ok(NpmDependencyEntry { kind, - bare_specifier, + bare_specifier: entry.0.to_string(), name, version_req, peer_dep_version_req: None, diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index 990ad8d0652220..d1b83db194fabb 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -13,6 +13,7 @@ use serde::Serialize; use crate::args::Lockfile; use crate::semver::Version; +use self::graph::Graph; use self::graph::GraphDependencyResolver; use self::snapshot::NpmPackagesPartitioned; @@ -27,7 +28,7 @@ mod reference; mod snapshot; mod specifier; -use graph::Graph; +pub use reference::parse_dep_entry_name_and_version; pub use reference::NpmPackageReference; pub use reference::NpmPackageReq; pub use snapshot::NpmResolutionSnapshot; diff --git a/cli/npm/resolution/reference.rs b/cli/npm/resolution/reference.rs index 2d34bcc34d668d..62e328ea882630 100644 --- a/cli/npm/resolution/reference.rs +++ b/cli/npm/resolution/reference.rs @@ -118,6 +118,17 @@ impl NpmPackageReq { } } + pub fn from_dependency_entry( + key: &str, + value: &str, + ) -> Result { + let (name, version_req) = parse_dep_entry_name_and_version(key, value)?; + Ok(NpmPackageReq { + name, + version_req: Some(version_req), + }) + } + fn parse_from_parts(name_parts: &[&str]) -> Result { assert!(!name_parts.is_empty()); // this should be provided the result of a string split let last_name_part = &name_parts[name_parts.len() - 1]; @@ -143,6 +154,29 @@ impl NpmPackageReq { } } +pub fn parse_dep_entry_name_and_version( + key: &str, + value: &str, +) -> Result<(String, VersionReq), AnyError> { + let (name, version_req) = + if let Some(package_and_version) = value.strip_prefix("npm:") { + if let Some((name, version)) = package_and_version.rsplit_once('@') { + (name, version) + } else { + bail!("could not find @ symbol in npm url '{}'", value); + } + } else { + (key, value) + }; + let version_req = + VersionReq::parse_from_npm(&version_req).with_context(|| { + format!( + "error parsing version requirement for dependency: {key}@{version_req}" + ) + })?; + Ok((name.to_string(), version_req)) +} + #[cfg(test)] mod tests { use pretty_assertions::assert_eq; From c32042dd5c232e3f78e2ccfcf0c5b0d123785a20 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 1 Feb 2023 11:50:29 -0500 Subject: [PATCH 33/60] Updates --- cli/args/mod.rs | 21 +++++-- cli/args/package_json.rs | 80 +++++++++++++++++++++++++ cli/graph_util.rs | 3 +- cli/npm/registry.rs | 14 +++-- cli/npm/resolution/mod.rs | 1 - cli/npm/resolution/reference.rs | 103 ++++++++++++++++++++++---------- cli/npm/resolution/specifier.rs | 69 +-------------------- cli/proc_state.rs | 20 ++++--- cli/resolver.rs | 39 +++--------- cli/tools/vendor/mod.rs | 2 +- 10 files changed, 203 insertions(+), 149 deletions(-) create mode 100644 cli/args/package_json.rs diff --git a/cli/args/mod.rs b/cli/args/mod.rs index b10549a69e12cb..cea89d13a4230a 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -5,10 +5,12 @@ mod flags; mod flags_allow_net; mod import_map; mod lockfile; +pub mod package_json; pub use self::import_map::resolve_import_map_from_specifier; use ::import_map::ImportMap; +use crate::npm::NpmPackageReq; use crate::util::fs::canonicalize_path; pub use config_file::BenchConfig; pub use config_file::CompilerOptions; @@ -45,6 +47,7 @@ use deno_runtime::deno_tls::webpki_roots; use deno_runtime::inspector_server::InspectorServer; use deno_runtime::permissions::PermissionsOptions; use std::collections::BTreeMap; +use std::collections::HashMap; use std::env; use std::io::BufReader; use std::io::Cursor; @@ -612,7 +615,7 @@ impl CliOptions { }; resolve_import_map_from_specifier( &import_map_specifier, - self.get_maybe_config_file().as_ref(), + self.maybe_config_file().as_ref(), file_fetcher, ) .await @@ -741,12 +744,22 @@ impl CliOptions { } } - pub fn get_maybe_config_file(&self) -> &Option { + pub fn maybe_config_file(&self) -> &Option { &self.maybe_config_file } - pub fn get_maybe_package_json(&self) -> Option { - self.maybe_package_json.clone() + pub fn maybe_package_json(&self) -> &Option { + &self.maybe_package_json + } + + pub fn maybe_package_json_deps( + &self, + ) -> Result>, AnyError> { + if let Some(package_json) = self.maybe_package_json() { + package_json::get_local_package_json_version_reqs(package_json).map(Some) + } else { + Ok(None) + } } pub fn resolve_fmt_options( diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs new file mode 100644 index 00000000000000..94905123aa0d37 --- /dev/null +++ b/cli/args/package_json.rs @@ -0,0 +1,80 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use std::collections::HashMap; + +use deno_core::anyhow::bail; +use deno_core::anyhow::Context; +use deno_core::error::AnyError; +use deno_runtime::deno_node::PackageJson; + +use crate::npm::NpmPackageReq; +use crate::semver::VersionReq; + +/// Gets the name and raw version constraint taking into account npm +/// package aliases. +pub fn parse_dep_entry_name_and_raw_version<'a>( + key: &'a str, + value: &'a str, +) -> Result<(&'a str, &'a str), AnyError> { + if let Some(package_and_version) = value.strip_prefix("npm:") { + if let Some((name, version)) = package_and_version.rsplit_once('@') { + Ok((name, version)) + } else { + bail!("could not find @ symbol in npm url '{}'", value); + } + } else { + Ok((key, value)) + } +} + +/// Gets an application level package.json's npm package requirements. +/// +/// Note that this function is not general purpose. It is specifically for +/// parsing the application level package.json that the user has control +/// over. This is a design limitation to allow mapping these dependency +/// entries to npm specifiers which can then be used in the resolver. +pub fn get_local_package_json_version_reqs( + package_json: &PackageJson, +) -> Result, AnyError> { + fn insert_deps( + deps: Option<&HashMap>, + result: &mut HashMap, + ) -> Result<(), AnyError> { + if let Some(deps) = deps { + for (key, value) in deps { + let (name, version_req) = + parse_dep_entry_name_and_raw_version(key, value)?; + let version_req = VersionReq::parse_from_specifier(version_req) + .with_context(|| { + format!("Parsing version constraints in the application-level package.json is more strict at the moment.") + })?; + result.insert( + key.to_string(), + NpmPackageReq { + name: name.to_string(), + version_req: Some(version_req), + }, + ); + } + } + Ok(()) + } + + let deps = package_json.dependencies.as_ref(); + let dev_deps = package_json.dev_dependencies.as_ref(); + let mut result = HashMap::with_capacity( + deps.map(|d| d.len()).unwrap_or(0) + dev_deps.map(|d| d.len()).unwrap_or(0), + ); + + // insert the dev dependencies first so the dependencies will + // take priority and overwrite any collisions + insert_deps(dev_deps, &mut result)?; + insert_deps(deps, &mut result)?; + + Ok(result) +} + +#[cfg(test)] +mod test { + // todo: Tests +} diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 756f632c13f912..7de6f1132b8281 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -525,10 +525,11 @@ pub async fn create_graph_and_maybe_check( PermissionsContainer::allow_all(), ); let maybe_imports = ps.options.to_maybe_imports()?; + let maybe_package_json_deps = ps.options.maybe_package_json_deps()?; let maybe_cli_resolver = CliResolver::maybe_new( ps.options.to_maybe_jsx_import_source_config(), ps.maybe_import_map.clone(), - ps.options.get_maybe_package_json(), + maybe_package_json_deps, ); let maybe_graph_resolver = maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 1fc7cfd75a43eb..bd2b8e9706c945 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -22,6 +22,7 @@ use deno_core::url::Url; use deno_runtime::colors; use serde::Serialize; +use crate::args::package_json::parse_dep_entry_name_and_raw_version; use crate::args::CacheSetting; use crate::cache::CACHE_PERM; use crate::http_util::HttpClient; @@ -31,7 +32,6 @@ use crate::util::fs::atomic_write_file; use crate::util::progress_bar::ProgressBar; use super::cache::NpmCache; -use super::resolution::parse_dep_entry_name_and_version; // npm registry docs: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md @@ -114,15 +114,19 @@ impl NpmPackageVersionInfo { &self, ) -> Result, AnyError> { fn parse_dep_entry( - entry: (&String, &String), + (key, value): (&String, &String), kind: NpmDependencyEntryKind, ) -> Result { let (name, version_req) = - parse_dep_entry_name_and_version(entry.0.as_str(), entry.1.as_str())?; + parse_dep_entry_name_and_raw_version(key, value)?; + let version_req = + VersionReq::parse_from_npm(&version_req).with_context(|| { + format!("error parsing version requirement for dependency: {key}@{version_req}") + })?; Ok(NpmDependencyEntry { kind, - bare_specifier: entry.0.to_string(), - name, + bare_specifier: key.to_string(), + name: name.to_string(), version_req, peer_dep_version_req: None, }) diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index d1b83db194fabb..e8d4a6c7c22762 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -28,7 +28,6 @@ mod reference; mod snapshot; mod specifier; -pub use reference::parse_dep_entry_name_and_version; pub use reference::NpmPackageReference; pub use reference::NpmPackageReq; pub use snapshot::NpmResolutionSnapshot; diff --git a/cli/npm/resolution/reference.rs b/cli/npm/resolution/reference.rs index 62e328ea882630..bce1967ea05201 100644 --- a/cli/npm/resolution/reference.rs +++ b/cli/npm/resolution/reference.rs @@ -1,5 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::cmp::Ordering; + use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; use deno_core::anyhow::Context; @@ -118,17 +120,6 @@ impl NpmPackageReq { } } - pub fn from_dependency_entry( - key: &str, - value: &str, - ) -> Result { - let (name, version_req) = parse_dep_entry_name_and_version(key, value)?; - Ok(NpmPackageReq { - name, - version_req: Some(version_req), - }) - } - fn parse_from_parts(name_parts: &[&str]) -> Result { assert!(!name_parts.is_empty()); // this should be provided the result of a string split let last_name_part = &name_parts[name_parts.len() - 1]; @@ -154,27 +145,52 @@ impl NpmPackageReq { } } -pub fn parse_dep_entry_name_and_version( - key: &str, - value: &str, -) -> Result<(String, VersionReq), AnyError> { - let (name, version_req) = - if let Some(package_and_version) = value.strip_prefix("npm:") { - if let Some((name, version)) = package_and_version.rsplit_once('@') { - (name, version) - } else { - bail!("could not find @ symbol in npm url '{}'", value); +impl PartialOrd for NpmPackageReq { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +// Sort the package requirements alphabetically then the version +// requirement in a way that will lead to the least number of +// duplicate packages (so sort None last since it's `*`), but +// mostly to create some determinism around how these are resolved. +impl Ord for NpmPackageReq { + fn cmp(&self, other: &Self) -> Ordering { + fn cmp_specifier_version_req(a: &VersionReq, b: &VersionReq) -> Ordering { + match a.tag() { + Some(a_tag) => match b.tag() { + Some(b_tag) => b_tag.cmp(a_tag), // sort descending + None => Ordering::Less, // prefer a since tag + }, + None => { + match b.tag() { + Some(_) => Ordering::Greater, // prefer b since tag + None => { + // At this point, just sort by text descending. + // We could maybe be a bit smarter here in the future. + b.to_string().cmp(&a.to_string()) + } + } + } } - } else { - (key, value) - }; - let version_req = - VersionReq::parse_from_npm(&version_req).with_context(|| { - format!( - "error parsing version requirement for dependency: {key}@{version_req}" - ) - })?; - Ok((name.to_string(), version_req)) + } + + match self.name.cmp(&other.name) { + Ordering::Equal => { + match &other.version_req { + Some(b_req) => { + match &self.version_req { + Some(a_req) => cmp_specifier_version_req(a_req, b_req), + None => Ordering::Greater, // prefer b, since a is * + } + } + None => Ordering::Less, // prefer a, since b is * + } + } + ordering => ordering, + } + } } #[cfg(test)] @@ -329,4 +345,29 @@ mod tests { "Invalid npm specifier 'npm://test'. Did not contain a package name." ); } + + #[test] + fn sorting_package_reqs() { + fn cmp_req(a: &str, b: &str) -> Ordering { + let a = NpmPackageReq::from_str(a).unwrap(); + let b = NpmPackageReq::from_str(b).unwrap(); + a.cmp(&b) + } + + // sort by name + assert_eq!(cmp_req("a", "b@1"), Ordering::Less); + assert_eq!(cmp_req("b@1", "a"), Ordering::Greater); + // prefer non-wildcard + assert_eq!(cmp_req("a", "a@1"), Ordering::Greater); + assert_eq!(cmp_req("a@1", "a"), Ordering::Less); + // prefer tag + assert_eq!(cmp_req("a@tag", "a"), Ordering::Less); + assert_eq!(cmp_req("a", "a@tag"), Ordering::Greater); + // sort tag descending + assert_eq!(cmp_req("a@latest-v1", "a@latest-v2"), Ordering::Greater); + assert_eq!(cmp_req("a@latest-v2", "a@latest-v1"), Ordering::Less); + // sort version req descending + assert_eq!(cmp_req("a@1", "a@2"), Ordering::Greater); + assert_eq!(cmp_req("a@2", "a@1"), Ordering::Less); + } } diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 78d313412b4c22..9321b58440cc07 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -9,8 +9,6 @@ use deno_ast::ModuleSpecifier; use deno_graph::ModuleGraph; use deno_graph::Resolved; -use crate::semver::VersionReq; - use super::NpmPackageReference; use super::NpmPackageReq; @@ -182,7 +180,7 @@ pub fn resolve_graph_npm_info(graph: &ModuleGraph) -> GraphNpmInfo { let reqs = std::mem::take(&mut leaf.reqs); let mut reqs = reqs.into_iter().collect::>(); - reqs.sort_by(cmp_package_req); + reqs.sort(); result.extend(reqs); let mut deps = std::mem::take(&mut leaf.dependencies) @@ -380,46 +378,6 @@ fn cmp_folder_specifiers(a: &ModuleSpecifier, b: &ModuleSpecifier) -> Ordering { } } -// Sort the package requirements alphabetically then the version -// requirement in a way that will lead to the least number of -// duplicate packages (so sort None last since it's `*`), but -// mostly to create some determinism around how these are resolved. -fn cmp_package_req(a: &NpmPackageReq, b: &NpmPackageReq) -> Ordering { - fn cmp_specifier_version_req(a: &VersionReq, b: &VersionReq) -> Ordering { - match a.tag() { - Some(a_tag) => match b.tag() { - Some(b_tag) => b_tag.cmp(a_tag), // sort descending - None => Ordering::Less, // prefer a since tag - }, - None => { - match b.tag() { - Some(_) => Ordering::Greater, // prefer b since tag - None => { - // At this point, just sort by text descending. - // We could maybe be a bit smarter here in the future. - b.to_string().cmp(&a.to_string()) - } - } - } - } - } - - match a.name.cmp(&b.name) { - Ordering::Equal => { - match &b.version_req { - Some(b_req) => { - match &a.version_req { - Some(a_req) => cmp_specifier_version_req(a_req, b_req), - None => Ordering::Greater, // prefer b, since a is * - } - } - None => Ordering::Less, // prefer a, since b is * - } - } - ordering => ordering, - } -} - #[cfg(test)] mod tests { use pretty_assertions::assert_eq; @@ -484,31 +442,6 @@ mod tests { ); } - #[test] - fn sorting_package_reqs() { - fn cmp_req(a: &str, b: &str) -> Ordering { - let a = NpmPackageReq::from_str(a).unwrap(); - let b = NpmPackageReq::from_str(b).unwrap(); - cmp_package_req(&a, &b) - } - - // sort by name - assert_eq!(cmp_req("a", "b@1"), Ordering::Less); - assert_eq!(cmp_req("b@1", "a"), Ordering::Greater); - // prefer non-wildcard - assert_eq!(cmp_req("a", "a@1"), Ordering::Greater); - assert_eq!(cmp_req("a@1", "a"), Ordering::Less); - // prefer tag - assert_eq!(cmp_req("a@tag", "a"), Ordering::Less); - assert_eq!(cmp_req("a", "a@tag"), Ordering::Greater); - // sort tag descending - assert_eq!(cmp_req("a@latest-v1", "a@latest-v2"), Ordering::Greater); - assert_eq!(cmp_req("a@latest-v2", "a@latest-v1"), Ordering::Less); - // sort version req descending - assert_eq!(cmp_req("a@1", "a@2"), Ordering::Greater); - assert_eq!(cmp_req("a@2", "a@1"), Ordering::Less); - } - #[test] fn test_get_folder_path_specifier() { fn get(a: &str) -> String { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index b128fd7d88ca4a..203005daf95ed0 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -181,10 +181,19 @@ impl ProcState { let maybe_inspector_server = cli_options.resolve_inspector_server().map(Arc::new); + let maybe_package_json_deps = cli_options.maybe_package_json_deps()?; + let package_json_reqs = if let Some(deps) = &maybe_package_json_deps { + let mut package_reqs = deps.values().cloned().collect::>(); + package_reqs.sort(); // deterministic resolution + package_reqs + } else { + Vec::new() + }; + let maybe_cli_resolver = CliResolver::maybe_new( cli_options.to_maybe_jsx_import_source_config(), maybe_import_map.clone(), - cli_options.get_maybe_package_json(), + maybe_package_json_deps, ); let maybe_resolver = maybe_cli_resolver.map(Arc::new); @@ -225,6 +234,7 @@ impl ProcState { lockfile.as_ref().cloned(), ) .await?; + npm_resolver.add_package_reqs(package_json_reqs).await?; let node_analysis_cache = NodeAnalysisCache::new(Some(dir.node_analysis_db_file_path())); @@ -682,14 +692,8 @@ impl ProcState { loader: &mut dyn Loader, ) -> Result { let maybe_imports = self.options.to_maybe_imports()?; - - let maybe_cli_resolver = CliResolver::maybe_new( - self.options.to_maybe_jsx_import_source_config(), - self.maybe_import_map.clone(), - self.options.get_maybe_package_json(), - ); let maybe_graph_resolver = - maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); + self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); let analyzer = self.parsed_source_cache.as_analyzer(); let graph = create_graph( diff --git a/cli/resolver.rs b/cli/resolver.rs index 983472cfc9ec00..a79380262afb73 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -5,18 +5,19 @@ use deno_core::resolve_import; use deno_core::ModuleSpecifier; use deno_graph::source::Resolver; use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; -use deno_runtime::deno_node::PackageJson; use import_map::ImportMap; +use std::collections::HashMap; use std::sync::Arc; use crate::args::JsxImportSourceConfig; +use crate::npm::NpmPackageReq; /// A resolver that takes care of resolution, taking into account loaded /// import map, JSX settings. #[derive(Debug, Clone, Default)] pub struct CliResolver { maybe_import_map: Option>, - maybe_package_json: Option, + maybe_package_json_deps: Option>, maybe_default_jsx_import_source: Option, maybe_jsx_import_source_module: Option, } @@ -25,15 +26,15 @@ impl CliResolver { pub fn maybe_new( maybe_jsx_import_source_config: Option, maybe_import_map: Option>, - maybe_package_json: Option, + maybe_package_json_deps: Option>, ) -> Option { if maybe_jsx_import_source_config.is_some() || maybe_import_map.is_some() - || maybe_package_json.is_some() + || maybe_package_json_deps.is_some() { Some(Self { maybe_import_map, - maybe_package_json, + maybe_package_json_deps, maybe_default_jsx_import_source: maybe_jsx_import_source_config .as_ref() .and_then(|c| c.default_specifier.clone()), @@ -77,31 +78,9 @@ impl Resolver for CliResolver { .map_err(|err| err.into()); } - if let Some(pjson) = self.maybe_package_json.as_ref() { - let maybe_specifier_and_version = if let Some(deps) = &pjson.dependencies - { - if deps.contains_key(specifier) { - let version = deps.get(specifier).unwrap(); - Some((specifier, version)) - } else { - None - } - } else if let Some(dev_deps) = &pjson.dev_dependencies { - if dev_deps.contains_key(specifier) { - let version = dev_deps.get(specifier).unwrap(); - Some((specifier, version)) - } else { - None - } - } else { - None - }; - - if let Some((specifier, version)) = maybe_specifier_and_version { - return Ok( - ModuleSpecifier::parse(&format!("npm:{specifier}@{version}")) - .unwrap(), - ); + if let Some(deps) = self.maybe_package_json_deps.as_ref() { + if let Some(req) = deps.get(specifier) { + return Ok(ModuleSpecifier::parse(&format!("npm:{req}")).unwrap()); } } diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index 209eb30b774912..e3536a00d76891 100644 --- a/cli/tools/vendor/mod.rs +++ b/cli/tools/vendor/mod.rs @@ -156,7 +156,7 @@ fn maybe_update_config_file(output_dir: &Path, ps: &ProcState) -> bool { let fmt_config = ps .options - .get_maybe_config_file() + .maybe_config_file() .as_ref() .and_then(|config| config.to_fmt_config().ok()) .unwrap_or_default() From b1ac2f72dfc9e058605046b14874efac0fdfb740 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 1 Feb 2023 12:10:34 -0500 Subject: [PATCH 34/60] Fix test. --- cli/tests/testdata/npm/cached_only/main.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tests/testdata/npm/cached_only/main.out b/cli/tests/testdata/npm/cached_only/main.out index e902bff4974777..1a9289431d696f 100644 --- a/cli/tests/testdata/npm/cached_only/main.out +++ b/cli/tests/testdata/npm/cached_only/main.out @@ -1,4 +1,4 @@ -error: Error getting response at http://localhost:4545/npm/registry/chalk +error: Error getting response at http://localhost:4545/npm/registry/chalk for package chalk Caused by: An npm specifier not found in cache: "chalk", --cached-only is specified. From 92b05cd9fadffc1ad86d7f89955ce9a0533ff227 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 1 Feb 2023 12:56:31 -0500 Subject: [PATCH 35/60] Make `--node-modules-dir` true when a package.json is autodiscovered --- cli/args/flags.rs | 32 ++++++++++++++++++++++++++------ cli/args/mod.rs | 7 +++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 0a0a8c5a4423a8..183f98e2c8d864 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -326,7 +326,7 @@ pub struct Flags { pub cached_only: bool, pub type_check_mode: TypeCheckMode, pub config_flag: ConfigFlag, - pub node_modules_dir: bool, + pub node_modules_dir: Option, pub coverage_dir: Option, pub enable_testing_features: bool, pub ignore: Vec, @@ -2318,7 +2318,12 @@ fn no_npm_arg<'a>() -> Arg<'a> { fn local_npm_arg<'a>() -> Arg<'a> { Arg::new("node-modules-dir") .long("node-modules-dir") - .help("Creates a local node_modules folder") + .min_values(0) + .max_values(1) + .takes_value(true) + .require_equals(true) + .possible_values(["true", "false"]) + .help("Creates a local node_modules folder. This option is implicitly true when a package.json is auto-discovered.") } fn unsafely_ignore_certificate_errors_arg<'a>() -> Arg<'a> { @@ -3261,9 +3266,7 @@ fn no_npm_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) { } fn local_npm_args_parse(flags: &mut Flags, matches: &ArgMatches) { - if matches.is_present("node-modules-dir") { - flags.node_modules_dir = true; - } + flags.node_modules_dir = optional_bool_parse(matches, "node-modules-dir"); } fn inspect_arg_validate(val: &str) -> Result<(), String> { @@ -5462,7 +5465,24 @@ mod tests { subcommand: DenoSubcommand::Run(RunFlags { script: "script.ts".to_string(), }), - node_modules_dir: true, + node_modules_dir: Some(true), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec![ + "deno", + "run", + "--node-modules-dir=false", + "script.ts" + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Run(RunFlags { + script: "script.ts".to_string(), + }), + node_modules_dir: Some(false), ..Flags::default() } ); diff --git a/cli/args/mod.rs b/cli/args/mod.rs index cea89d13a4230a..65d0c806608109 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -631,14 +631,17 @@ impl CliOptions { } pub fn node_modules_dir(&self) -> bool { - self.flags.node_modules_dir + match self.flags.node_modules_dir { + Some(value) => value, + None => self.maybe_package_json.is_some(), + } } /// Resolves the path to use for a local node_modules folder. pub fn resolve_local_node_modules_folder( &self, ) -> Result, AnyError> { - let path = if !self.flags.node_modules_dir { + let path = if !self.node_modules_dir() { return Ok(None); } else if let Some(config_path) = self .maybe_config_file From 06b8698159e1af81d888d15dfe31dd4927ab532a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 2 Feb 2023 00:53:33 +0100 Subject: [PATCH 36/60] update discovery algorithm --- cli/args/flags.rs | 7 ++- cli/args/mod.rs | 112 ++++++++++++++++++++++++++++++--------- cli/args/package_json.rs | 6 +-- cli/npm/registry.rs | 2 +- ext/node/package_json.rs | 7 +++ 5 files changed, 103 insertions(+), 31 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 183f98e2c8d864..b022134b48052e 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -502,7 +502,12 @@ impl Flags { } } - pub fn package_json_args(&self) -> Option { + /// Extract path argument for `package.json` search paths. + /// If it returns Some(path), the `package.json` should be discovered + /// from the `path` dir. + /// If it returns None, the `package.json` file shouldn't be discovered at + /// all. + pub fn package_json_arg(&self) -> Option { use DenoSubcommand::*; if let Run(RunFlags { script }) = &self.subcommand { diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 65d0c806608109..8c93d33226a7e5 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -48,11 +48,13 @@ use deno_runtime::inspector_server::InspectorServer; use deno_runtime::permissions::PermissionsOptions; use std::collections::BTreeMap; use std::collections::HashMap; +use std::collections::HashSet; use std::env; use std::io::BufReader; use std::io::Cursor; use std::net::SocketAddr; use std::num::NonZeroUsize; +use std::path::Path; use std::path::PathBuf; use std::sync::Arc; @@ -66,28 +68,6 @@ use self::config_file::LintConfig; use self::config_file::MaybeImportsResult; use self::config_file::TestConfig; -fn discover_package_json( - flags: &Flags, -) -> Result, AnyError> { - if let Some(package_json_arg) = flags.package_json_args() { - let pjson_path = package_json_arg.join("package.json"); - let pjson = PackageJson::load_skip_read_permission(pjson_path)?; - return Ok(Some(pjson)); - } else if let crate::args::DenoSubcommand::Task(TaskFlags { - cwd: Some(path), - .. - }) = &flags.subcommand - { - // attempt to resolve the config file from the task subcommand's - // `--cwd` when specified - let task_cwd = canonicalize_path(&PathBuf::from(path))?; - let pjson_path = task_cwd.join("package.json"); - let pjson = PackageJson::load_skip_read_permission(pjson_path)?; - return Ok(Some(pjson)); - } - Ok(None) -} - /// Indicates how cached source files should be handled. #[derive(Debug, Clone, Eq, PartialEq)] pub enum CacheSetting { @@ -401,6 +381,70 @@ fn resolve_lint_rules_options( } } +/// Discover `package.json` file. If `maybe_stop_at` is provided, we will stop +/// crawling up the directory tree at that path. +fn discover_package_json( + flags: &Flags, + maybe_stop_at: Option, +) -> Result, AnyError> { + pub fn discover_from( + start: &Path, + checked: &mut HashSet, + maybe_stop_at: Option, + ) -> Result, AnyError> { + const PACKAGE_JSON_NAME: &str = "package.json"; + + for ancestor in start.ancestors() { + if checked.insert(ancestor.to_path_buf()) { + let path = ancestor.join(PACKAGE_JSON_NAME); + + let source = match std::fs::read_to_string(&path) { + Ok(source) => source, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + if let Some(stop_at) = maybe_stop_at.as_ref() { + if ancestor == stop_at { + break; + } + } + continue; + } + Err(err) => bail!( + "Error loading package.json at {}. {:#}", + path.display(), + err + ), + }; + + let package_json = PackageJson::load_from_string(path, source)?; + return Ok(Some(package_json)); + } + } + // No config file found. + Ok(None) + } + + // TODO(bartlomieju): discover for all subcommands, but print warnings that + // `package.json` is ignored in bundle/compile/etc. + + if let Some(package_json_arg) = flags.package_json_arg() { + return discover_from( + &package_json_arg, + &mut HashSet::new(), + maybe_stop_at, + ); + } else if let crate::args::DenoSubcommand::Task(TaskFlags { + cwd: Some(path), + .. + }) = &flags.subcommand + { + // attempt to resolve the config file from the task subcommand's + // `--cwd` when specified + let task_cwd = canonicalize_path(&PathBuf::from(path))?; + return discover_from(&task_cwd, &mut HashSet::new(), None); + } + Ok(None) +} + /// Create and populate a root cert store based on the passed options and /// environment. pub fn get_root_cert_store( @@ -539,11 +583,27 @@ impl CliOptions { pub fn from_flags(flags: Flags) -> Result { let maybe_config_file = ConfigFile::discover(&flags)?; - let maybe_package_json = if maybe_config_file.is_none() { - discover_package_json(&flags)? + + let mut maybe_package_json = None; + if let Some(config_file) = &maybe_config_file { + let specifier = config_file.specifier.clone(); + if specifier.scheme() == "file" { + maybe_package_json = discover_package_json( + &flags, + Some( + specifier + .to_file_path() + .unwrap() + .parent() + .unwrap() + .to_path_buf(), + ), + )?; + } } else { - None - }; + maybe_package_json = discover_package_json(&flags, None)?; + } + let maybe_lock_file = lockfile::discover(&flags, maybe_config_file.as_ref())?; Ok(Self::new( diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index 94905123aa0d37..00240353c1474c 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -45,9 +45,9 @@ pub fn get_local_package_json_version_reqs( let (name, version_req) = parse_dep_entry_name_and_raw_version(key, value)?; let version_req = VersionReq::parse_from_specifier(version_req) - .with_context(|| { - format!("Parsing version constraints in the application-level package.json is more strict at the moment.") - })?; + .context( + "Parsing version constraints in the application-level package.json is more strict at the moment." + )?; result.insert( key.to_string(), NpmPackageReq { diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index bd2b8e9706c945..242d289e3e80f8 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -120,7 +120,7 @@ impl NpmPackageVersionInfo { let (name, version_req) = parse_dep_entry_name_and_raw_version(key, value)?; let version_req = - VersionReq::parse_from_npm(&version_req).with_context(|| { + VersionReq::parse_from_npm(version_req).with_context(|| { format!("error parsing version requirement for dependency: {key}@{version_req}") })?; Ok(NpmDependencyEntry { diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs index debbe0cb6d2969..74f8126ce66936 100644 --- a/ext/node/package_json.rs +++ b/ext/node/package_json.rs @@ -79,6 +79,13 @@ impl PackageJson { return Ok(PackageJson::empty(path)); } + Self::load_from_string(path, source) + } + + pub fn load_from_string( + path: PathBuf, + source: String, + ) -> Result { let package_json: Value = serde_json::from_str(&source) .map_err(|err| anyhow::anyhow!("malformed package.json {}", err))?; From 2d130283f9f3529eb1d1a219ceaf7935c2840601 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 2 Feb 2023 12:46:52 -0500 Subject: [PATCH 37/60] Add tests. --- cli/args/package_json.rs | 87 ++++++++++++++++++++++++++++++++++++++-- cli/semver/specifier.rs | 2 +- 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index 00240353c1474c..a3446efd64f5a9 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -45,9 +45,10 @@ pub fn get_local_package_json_version_reqs( let (name, version_req) = parse_dep_entry_name_and_raw_version(key, value)?; let version_req = VersionReq::parse_from_specifier(version_req) - .context( - "Parsing version constraints in the application-level package.json is more strict at the moment." - )?; + .context(concat!( + "Parsing version constraints in the application-level ", + "package.json is more strict at the moment" + ))?; result.insert( key.to_string(), NpmPackageReq { @@ -76,5 +77,83 @@ pub fn get_local_package_json_version_reqs( #[cfg(test)] mod test { - // todo: Tests + use pretty_assertions::assert_eq; + use std::path::PathBuf; + + use super::*; + + #[test] + fn test_parse_dep_entry_name_and_raw_version() { + let cases = [ + ("test", "^1.2", Ok(("test", "^1.2"))), + ("test", "1.x - 2.6", Ok(("test", "1.x - 2.6"))), + ("test", "npm:package@^1.2", Ok(("package", "^1.2"))), + ( + "test", + "npm:package", + Err("could not find @ symbol in npm url 'npm:package'"), + ), + ]; + for (key, value, expected_result) in cases { + let result = parse_dep_entry_name_and_raw_version(key, value); + match result { + Ok(result) => assert_eq!(result, expected_result.unwrap()), + Err(err) => assert_eq!(err.to_string(), expected_result.err().unwrap()), + } + } + } + + #[test] + fn test_get_local_package_json_version_reqs() { + let mut package_json = PackageJson::empty(PathBuf::from("/package.json")); + package_json.dependencies = Some(HashMap::from([ + ("test".to_string(), "^1.2".to_string()), + ("other".to_string(), "npm:package@~1.3".to_string()), + ])); + package_json.dev_dependencies = Some(HashMap::from([ + ("package_b".to_string(), "~2.2".to_string()), + // should be ignored + ("other".to_string(), "^3.2".to_string()), + ])); + let result = get_local_package_json_version_reqs(&package_json).unwrap(); + assert_eq!( + result, + HashMap::from([ + ( + "test".to_string(), + NpmPackageReq::from_str("test@^1.2").unwrap() + ), + ( + "other".to_string(), + NpmPackageReq::from_str("package@~1.3").unwrap() + ), + ( + "package_b".to_string(), + NpmPackageReq::from_str("package_b@~2.2").unwrap() + ) + ]) + ); + } + + #[test] + fn test_get_local_package_json_version_reqs_errors_non_npm_specifier() { + let mut package_json = PackageJson::empty(PathBuf::from("/package.json")); + package_json.dependencies = Some(HashMap::from([( + "test".to_string(), + "1.x - 1.3".to_string(), + )])); + let err = get_local_package_json_version_reqs(&package_json) + .err() + .unwrap(); + assert_eq!( + format!("{err:#}"), + concat!( + "Parsing version constraints in the application-level ", + "package.json is more strict at the moment: Invalid npm specifier ", + "version requirement '1.x - 1.3': Unexpected character.\n", + " - 1.3\n", + " ~" // the unexpected character is the space + ) + ); + } } diff --git a/cli/semver/specifier.rs b/cli/semver/specifier.rs index 8edb4cddd25e1d..0f667dea9f425c 100644 --- a/cli/semver/specifier.rs +++ b/cli/semver/specifier.rs @@ -42,7 +42,7 @@ pub fn parse_version_req_from_specifier( })(input) })(text) .with_context(|| { - format!("Invalid npm specifier version requirement '{text}'.") + format!("Invalid npm specifier version requirement '{text}'") }) } From c83f24c923783c013ca78fd3c4c11b3ba9fb6363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 2 Feb 2023 21:51:03 +0100 Subject: [PATCH 38/60] log discovered package.json in preparation for tests --- cli/args/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 8c93d33226a7e5..f663e88a7b9165 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -416,6 +416,7 @@ fn discover_package_json( }; let package_json = PackageJson::load_from_string(path, source)?; + log::debug!("package.json file found at '{}'", path.display()); return Ok(Some(package_json)); } } From 1ba68ec11573208f0c434bf245e292c0450c565f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 13 Feb 2023 02:54:19 +0100 Subject: [PATCH 39/60] make progress debugging vite project --- Cargo.lock | 4 ++-- Cargo.toml | 3 +++ cli/args/flags.rs | 3 +++ cli/args/mod.rs | 6 ++++-- cli/graph_util.rs | 2 ++ cli/proc_state.rs | 4 ++++ cli/resolver.rs | 17 +++++++++++++++++ 7 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93ba0c55e7d6f0..7a45640ed18fbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1091,18 +1091,18 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.43.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f71bb48b14950d62552aee1d05d0b90c203319b293b36358021ec77e05eaf9a4" dependencies = [ "anyhow", "data-url", "deno_ast", "futures", + "monch", "once_cell", "parking_lot 0.12.1", "regex", "serde", "serde_json", + "thiserror", "url", ] diff --git a/Cargo.toml b/Cargo.toml index f2e61205ee3633..95731ad9981d27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -300,3 +300,6 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 + +[patch.crates-io] +deno_graph = { path = "../deno_graph" } diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 0a13ba92553c7f..6ee7d315827b22 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -522,6 +522,9 @@ impl Flags { .unwrap() .to_owned(); return Some(p); + } else if module_specifier.scheme() == "npm" { + let p = std::env::current_dir().unwrap(); + return Some(p); } } } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index a782a619c78e1b..b8e6173611575b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -417,7 +417,7 @@ fn discover_package_json( ), }; - let package_json = PackageJson::load_from_string(path, source)?; + let package_json = PackageJson::load_from_string(path.clone(), source)?; log::debug!("package.json file found at '{}'", path.display()); return Ok(Some(package_json)); } @@ -589,6 +589,7 @@ impl CliOptions { let mut maybe_package_json = None; if let Some(config_file) = &maybe_config_file { + eprintln!("maybe_package_json Some"); let specifier = config_file.specifier.clone(); if specifier.scheme() == "file" { maybe_package_json = discover_package_json( @@ -604,9 +605,10 @@ impl CliOptions { )?; } } else { + eprintln!("maybe_package_json None"); maybe_package_json = discover_package_json(&flags, None)?; } - + eprintln!("maybe_package_json: {:?}", maybe_package_json); let maybe_lock_file = lockfile::discover(&flags, maybe_config_file.as_ref())?; Ok(Self::new( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 6d0d296fb32a43..80e4e8d4d5d16f 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -57,6 +57,7 @@ pub fn graph_valid( walk_options: deno_graph::WalkOptions, ) -> Result<(), AnyError> { graph.walk(roots, walk_options).validate().map_err(|error| { + eprintln!("graph is not valid: {error}"); let is_root = match &error { ModuleGraphError::ResolutionError(_) => false, _ => roots.contains(error.specifier()), @@ -119,6 +120,7 @@ pub async fn create_graph_and_maybe_check( maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); let analyzer = ps.parsed_source_cache.as_analyzer(); let mut graph = ModuleGraph::default(); + eprintln!("create graph and maybe check"); graph .build( vec![root], diff --git a/cli/proc_state.rs b/cli/proc_state.rs index c6f0609721a2c3..36b06a9db9edc0 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -228,6 +228,7 @@ impl ProcState { Vec::new() }; + eprintln!("maybe package_json deps {:#?}", maybe_package_json_deps); let maybe_cli_resolver = CliResolver::maybe_new( cli_options.to_maybe_jsx_import_source_config(), maybe_import_map.clone(), @@ -322,6 +323,7 @@ impl ProcState { dynamic_permissions: PermissionsContainer, ) -> Result<(), AnyError> { log::debug!("Preparing module load."); + eprintln!("prepare_module_load {:?} {}", roots, is_dynamic); let _pb_clear_guard = self.progress_bar.clear_guard(); let mut cache = cache::FetchCacher::new( @@ -369,6 +371,7 @@ impl ProcState { graph_lock_or_exit(&graph, &mut lockfile.lock()); } + eprintln!("check if graph is valid"); let (npm_package_reqs, has_node_builtin_specifier) = { graph_valid_with_cli_options(&graph, &roots, &self.options)?; let mut graph_data = self.graph_data.write(); @@ -378,6 +381,7 @@ impl ProcState { graph_data.has_node_builtin_specifier, ) }; + eprintln!("graph is valid"); if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; diff --git a/cli/resolver.rs b/cli/resolver.rs index a79380262afb73..63115f7c51e150 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -10,6 +10,7 @@ use std::collections::HashMap; use std::sync::Arc; use crate::args::JsxImportSourceConfig; +use crate::node::resolve_builtin_node_module; use crate::npm::NpmPackageReq; /// A resolver that takes care of resolution, taking into account loaded @@ -28,6 +29,7 @@ impl CliResolver { maybe_import_map: Option>, maybe_package_json_deps: Option>, ) -> Option { + eprintln!("maybe new"); if maybe_jsx_import_source_config.is_some() || maybe_import_map.is_some() || maybe_package_json_deps.is_some() @@ -72,6 +74,11 @@ impl Resolver for CliResolver { specifier: &str, referrer: &ModuleSpecifier, ) -> Result { + eprintln!( + "maybe resolver, resolving {} {}", + specifier, + referrer.as_str() + ); if let Some(import_map) = &self.maybe_import_map { return import_map .resolve(specifier, referrer) @@ -84,6 +91,16 @@ impl Resolver for CliResolver { } } + if let Ok(node_builtin_module) = resolve_builtin_node_module(specifier) { + eprintln!("resolve built-in: {}", node_builtin_module); + return Ok(node_builtin_module); + } + + // FIXME(bartlomieju): check using `npm_resolver.in_npm_package()` + if referrer.as_str().contains("node_modules") { + return Ok(ModuleSpecifier::parse(&format!("npm:{specifier}")).unwrap()); + } + resolve_import(specifier, referrer.as_str()).map_err(|err| err.into()) } } From 92cc13cc27b0340efcfb83217803c03ae4194fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 13 Feb 2023 21:15:26 +0100 Subject: [PATCH 40/60] more debug output, plus something is actually getting resolved --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- cli/cache/mod.rs | 10 +++++++++- cli/npm/registry.rs | 3 +++ cli/npm/resolution/mod.rs | 7 +++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a45640ed18fbb..93ba0c55e7d6f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1091,18 +1091,18 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71bb48b14950d62552aee1d05d0b90c203319b293b36358021ec77e05eaf9a4" dependencies = [ "anyhow", "data-url", "deno_ast", "futures", - "monch", "once_cell", "parking_lot 0.12.1", "regex", "serde", "serde_json", - "thiserror", "url", ] diff --git a/Cargo.toml b/Cargo.toml index 95731ad9981d27..406d122bfe5b99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -301,5 +301,5 @@ opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 -[patch.crates-io] -deno_graph = { path = "../deno_graph" } +# [patch.crates-io] +# deno_graph = { path = "../deno_graph" } diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 80a9f7d2b15287..7b56a0d9cac9a3 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -77,7 +77,7 @@ impl Loader for FetchCacher { return None; } - if matches!(specifier.scheme(), "npm" | "node") { + if matches!(specifier.scheme(), "npm" | "node" | "internal") { return None; } @@ -117,6 +117,14 @@ impl Loader for FetchCacher { )); } + if specifier.as_str().starts_with("internal:") { + return Box::pin(futures::future::ready(Ok(Some( + deno_graph::source::LoadResponse::External { + specifier: specifier.clone(), + }, + )))); + } + let specifier = if let Some(module_name) = specifier.as_str().strip_prefix("node:") { if module_name == "module" { diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 242d289e3e80f8..62809bba5bfa5f 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -288,6 +288,9 @@ impl NpmRegistryApi for RealNpmRegistryApi { ) -> BoxFuture<'static, Result>, AnyError>> { let api = self.clone(); let name = name.to_string(); + if name == "." { + panic!(); + } async move { api.0.maybe_package_info(&name).await }.boxed() } diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index e8d4a6c7c22762..db2dcb69d6ef5a 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -276,6 +276,13 @@ impl NpmResolution { package_reqs: Vec, snapshot: NpmResolutionSnapshot, ) -> Result { + eprintln!("add package reqs {:#?}", package_reqs); + + if package_reqs.iter().any(|req| req.name == ".") { + eprintln!("got empty name"); + panic!(); + } + // convert the snapshot to a traversable graph let mut graph = Graph::from_snapshot(snapshot); From f178a811b41413646a52502f482fe988a69212ba Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 13 Feb 2023 15:28:57 -0500 Subject: [PATCH 41/60] Remove unused code. --- cli/cache/mod.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 7b56a0d9cac9a3..ed890a264092c5 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -81,10 +81,6 @@ impl Loader for FetchCacher { return None; } - if specifier.scheme() == "node" { - return None; - } - let local = self.file_fetcher.get_local_path(specifier)?; if local.is_file() { let emit = self From 50ba72866a8c35cb5da90bf02b811552478d8bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 16 Feb 2023 23:43:17 +0100 Subject: [PATCH 42/60] fix package json error --- cli/args/package_json.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index 6132e5ff4aef28..56a7b0fb3a0d6c 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -149,9 +149,11 @@ mod test { concat!( "Parsing version constraints in the application-level ", "package.json is more strict at the moment: Invalid npm specifier ", - "version requirement '1.x - 1.3': Unexpected character.\n", + "version requirement. Unexpected character.\n", " - 1.3\n", - " ~" // the unexpected character is the space + " ~: Unexpected character.\n", + " - 1.3\n", + " ~" ) ); } From 18de1195c633a94857ea31825e471e7c00f2e115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 16 Feb 2023 23:57:39 +0100 Subject: [PATCH 43/60] revert Cargo.toml --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67371f5069a551..20699ef740d3c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -299,6 +299,3 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 - -# [patch.crates-io] -# deno_graph = { path = "../deno_graph" } From ff27653a287f20969458a9bf8759b76bb6a6e882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 17 Feb 2023 00:18:27 +0100 Subject: [PATCH 44/60] remove debug logs --- cli/args/mod.rs | 3 --- cli/graph_util.rs | 1 - cli/npm/resolution/mod.rs | 2 -- cli/proc_state.rs | 3 --- cli/resolver.rs | 5 ----- 5 files changed, 14 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index abf206ff798dc1..4bb8c837ac6b84 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -589,7 +589,6 @@ impl CliOptions { let mut maybe_package_json = None; if let Some(config_file) = &maybe_config_file { - eprintln!("maybe_package_json Some"); let specifier = config_file.specifier.clone(); if specifier.scheme() == "file" { maybe_package_json = discover_package_json( @@ -605,10 +604,8 @@ impl CliOptions { )?; } } else { - eprintln!("maybe_package_json None"); maybe_package_json = discover_package_json(&flags, None)?; } - eprintln!("maybe_package_json: {maybe_package_json:?}"); let maybe_lock_file = lockfile::discover(&flags, maybe_config_file.as_ref())?; Ok(Self::new( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 4d3c4f62812054..77dc3011c7f440 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -159,7 +159,6 @@ pub async fn create_graph_and_maybe_check( let graph_resolver = cli_resolver.as_graph_resolver(); let analyzer = ps.parsed_source_cache.as_analyzer(); let mut graph = ModuleGraph::default(); - eprintln!("create graph and maybe check"); graph .build( vec![root], diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index 2030ca3f13e106..99103a0ec7309f 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -132,8 +132,6 @@ impl NpmResolution { package_reqs: Vec, snapshot: NpmResolutionSnapshot, ) -> Result { - eprintln!("add package reqs {package_reqs:#?}"); - if package_reqs.iter().any(|req| req.name == ".") { eprintln!("got empty name"); panic!(); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 9e4ec3ff6224d1..d5407de7ee6518 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -316,7 +316,6 @@ impl ProcState { dynamic_permissions: PermissionsContainer, ) -> Result<(), AnyError> { log::debug!("Preparing module load."); - eprintln!("prepare_module_load {roots:?} {is_dynamic}"); let _pb_clear_guard = self.progress_bar.clear_guard(); let mut cache = cache::FetchCacher::new( @@ -363,7 +362,6 @@ impl ProcState { graph_lock_or_exit(&graph, &mut lockfile.lock()); } - eprintln!("check if graph is valid"); let (npm_package_reqs, has_node_builtin_specifier) = { graph_valid_with_cli_options(&graph, &roots, &self.options)?; let mut graph_data = self.graph_data.write(); @@ -373,7 +371,6 @@ impl ProcState { graph_data.has_node_builtin_specifier, ) }; - eprintln!("graph is valid"); if !npm_package_reqs.is_empty() { self.npm_resolver.add_package_reqs(npm_package_reqs).await?; diff --git a/cli/resolver.rs b/cli/resolver.rs index 17579c01b99ad1..4af2a92ca14846 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -61,11 +61,6 @@ impl Resolver for CliGraphResolver { specifier: &str, referrer: &ModuleSpecifier, ) -> Result { - eprintln!( - "maybe resolver, resolving {} {}", - specifier, - referrer.as_str() - ); if let Some(import_map) = &self.maybe_import_map { return import_map .resolve(specifier, referrer) From babe74d049789c827b035a85cd89da44041832f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 17 Feb 2023 14:35:11 +0100 Subject: [PATCH 45/60] fix some tests --- cli/cache/mod.rs | 10 +--------- cli/resolver.rs | 7 +++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 296f9876f25c47..ca03ca94083f1d 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -76,7 +76,7 @@ impl Loader for FetchCacher { return None; } - if matches!(specifier.scheme(), "npm" | "node" | "internal") { + if matches!(specifier.scheme(), "npm" | "node") { return None; } @@ -112,14 +112,6 @@ impl Loader for FetchCacher { )); } - if specifier.as_str().starts_with("internal:") { - return Box::pin(futures::future::ready(Ok(Some( - deno_graph::source::LoadResponse::External { - specifier: specifier.clone(), - }, - )))); - } - let specifier = if let Some(module_name) = specifier.as_str().strip_prefix("node:") { // Built-in Node modules are embedded in the Deno binary (in V8 snapshot) diff --git a/cli/resolver.rs b/cli/resolver.rs index 4af2a92ca14846..2ede6225f77801 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -74,14 +74,13 @@ impl Resolver for CliGraphResolver { } if let Ok(node_builtin_module) = resolve_builtin_node_module(specifier) { - eprintln!("resolve built-in: {node_builtin_module}"); return Ok(node_builtin_module); } // FIXME(bartlomieju): check using `npm_resolver.in_npm_package()` - if referrer.as_str().contains("node_modules") { - return Ok(ModuleSpecifier::parse(&format!("npm:{specifier}")).unwrap()); - } + // if referrer.as_str().contains("node_modules") { + // return Ok(ModuleSpecifier::parse(&format!("npm:{specifier}")).unwrap()); + // } deno_graph::resolve_import(specifier, referrer).map_err(|err| err.into()) } From fb79ae9699d0524806c07c2b0412c463dace1324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 17 Feb 2023 16:43:04 +0100 Subject: [PATCH 46/60] don't use package.json deps for now --- cli/npm/registry.rs | 2 +- cli/npm/resolution/mod.rs | 5 ---- cli/proc_state.rs | 1 + cli/resolver.rs | 29 +++++++-------------- cli/tests/testdata/npm/cached_only/main.out | 2 +- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 87d0b8d157e069..1e83a64341a2b8 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -333,7 +333,7 @@ impl RealNpmRegistryApiInner { .await .with_context(|| { format!( - "Error getting response at {} for package {}", + "Error getting response at {} for package \"{}\"", self.get_package_url(name), name ) diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index 3383938e0870ac..ec6ee0dda00d05 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -289,11 +289,6 @@ impl NpmResolution { package_reqs: Vec, snapshot: NpmResolutionSnapshot, ) -> Result { - if package_reqs.iter().any(|req| req.name == ".") { - eprintln!("got empty name"); - panic!(); - } - // convert the snapshot to a traversable graph let mut graph = Graph::from_snapshot(snapshot); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index d5407de7ee6518..9462cc429eed67 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -647,6 +647,7 @@ impl ProcState { let cli_resolver = CliGraphResolver::new( self.options.to_maybe_jsx_import_source_config(), self.maybe_import_map.clone(), + // TODO(bartlomieju): this should use dependencies from `package.json`? None, ); let graph_resolver = cli_resolver.as_graph_resolver(); diff --git a/cli/resolver.rs b/cli/resolver.rs index 2ede6225f77801..aa58549a79cc4a 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -9,7 +9,6 @@ use std::collections::HashMap; use std::sync::Arc; use crate::args::JsxImportSourceConfig; -use crate::node::resolve_builtin_node_module; use deno_graph::npm::NpmPackageReq; /// A resolver that takes care of resolution, taking into account loaded @@ -17,6 +16,9 @@ use deno_graph::npm::NpmPackageReq; #[derive(Debug, Clone, Default)] pub struct CliGraphResolver { maybe_import_map: Option>, + // TODO(bartlomieju): actually use in `resolver`, once + // deno_graph refactors and upgrades land. + #[allow(dead_code)] maybe_package_json_deps: Option>, maybe_default_jsx_import_source: Option, maybe_jsx_import_source_module: Option, @@ -61,27 +63,14 @@ impl Resolver for CliGraphResolver { specifier: &str, referrer: &ModuleSpecifier, ) -> Result { + // TODO(bartlomieju): actually use `maybe_package_json_deps` here, once + // deno_graph refactors and upgrades land. if let Some(import_map) = &self.maybe_import_map { - return import_map + import_map .resolve(specifier, referrer) - .map_err(|err| err.into()); + .map_err(|err| err.into()) + } else { + deno_graph::resolve_import(specifier, referrer).map_err(|err| err.into()) } - - if let Some(deps) = self.maybe_package_json_deps.as_ref() { - if let Some(req) = deps.get(specifier) { - return Ok(ModuleSpecifier::parse(&format!("npm:{req}")).unwrap()); - } - } - - if let Ok(node_builtin_module) = resolve_builtin_node_module(specifier) { - return Ok(node_builtin_module); - } - - // FIXME(bartlomieju): check using `npm_resolver.in_npm_package()` - // if referrer.as_str().contains("node_modules") { - // return Ok(ModuleSpecifier::parse(&format!("npm:{specifier}")).unwrap()); - // } - - deno_graph::resolve_import(specifier, referrer).map_err(|err| err.into()) } } diff --git a/cli/tests/testdata/npm/cached_only/main.out b/cli/tests/testdata/npm/cached_only/main.out index 1a9289431d696f..f49494839e2651 100644 --- a/cli/tests/testdata/npm/cached_only/main.out +++ b/cli/tests/testdata/npm/cached_only/main.out @@ -1,4 +1,4 @@ -error: Error getting response at http://localhost:4545/npm/registry/chalk for package chalk +error: Error getting response at http://localhost:4545/npm/registry/chalk for package "chalk" Caused by: An npm specifier not found in cache: "chalk", --cached-only is specified. From f24eab745722d30b6d3a775933f60f7f0cf70a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 17 Feb 2023 16:46:11 +0100 Subject: [PATCH 47/60] address some todos --- cli/args/flags.rs | 4 +--- cli/args/mod.rs | 18 +++++++----------- cli/lsp/documents.rs | 2 +- cli/lsp/language_server.rs | 2 +- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 614f8e2d836491..2c9f4c09dd44ad 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -514,12 +514,10 @@ impl Flags { if let Run(RunFlags { script }) = &self.subcommand { if let Ok(module_specifier) = deno_core::resolve_url_or_path(script) { if module_specifier.scheme() == "file" { - // TODO(bartlomieju): probably not safe with all these unwraps here let p = module_specifier .to_file_path() .unwrap() - .parent() - .unwrap() + .parent()? .to_owned(); return Some(p); } else if module_specifier.scheme() == "npm" { diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 4bb8c837ac6b84..99d8534bac43f8 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -591,17 +591,13 @@ impl CliOptions { if let Some(config_file) = &maybe_config_file { let specifier = config_file.specifier.clone(); if specifier.scheme() == "file" { - maybe_package_json = discover_package_json( - &flags, - Some( - specifier - .to_file_path() - .unwrap() - .parent() - .unwrap() - .to_path_buf(), - ), - )?; + let maybe_stop_at = specifier + .to_file_path() + .unwrap() + .parent() + .map(|p| p.to_path_buf()); + + maybe_package_json = discover_package_json(&flags, maybe_stop_at)?; } } else { maybe_package_json = discover_package_json(&flags, None)?; diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 7e82d33d46b910..faabb6a2f367c5 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1181,7 +1181,7 @@ impl Documents { maybe_import_map.as_deref(), maybe_jsx_config.as_ref(), ); - // TODO(bartlomieju): handle package.json dependencies here? + // TODO(bartlomieju): handle package.json dependencies here self.resolver = CliGraphResolver::new(maybe_jsx_config, maybe_import_map, None); self.imports = Arc::new( diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 8efa5fd2fa688f..abb2af95c27ece 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -3018,7 +3018,7 @@ impl Inner { self.maybe_config_file.clone(), // TODO(#16510): add support for lockfile None, - // TODO(bartlomieju): + // TODO(bartlomieju): handle package.json dependencies here None, ); cli_options.set_import_map_specifier(self.maybe_import_map_uri.clone()); From 70617aa83a1ba58c305f86ffbac3015aa1bbf217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 17 Feb 2023 16:46:40 +0100 Subject: [PATCH 48/60] remove a panic --- cli/npm/registry.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 1e83a64341a2b8..a758ae7be28579 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -288,9 +288,6 @@ impl NpmRegistryApi for RealNpmRegistryApi { ) -> BoxFuture<'static, Result>, AnyError>> { let api = self.clone(); let name = name.to_string(); - if name == "." { - panic!(); - } async move { api.0.maybe_package_info(&name).await }.boxed() } From 2e28368279ebea9ab945d109b8589122db6fad80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 18 Feb 2023 00:21:07 +0100 Subject: [PATCH 49/60] wip basic test --- cli/tests/integration/run_tests.rs | 5 +++++ cli/tests/testdata/run/with_package_json/main.out | 1 + cli/tests/testdata/run/with_package_json/main.ts | 3 +++ cli/tests/testdata/run/with_package_json/package.json | 8 ++++++++ 4 files changed, 17 insertions(+) create mode 100644 cli/tests/testdata/run/with_package_json/main.out create mode 100644 cli/tests/testdata/run/with_package_json/main.ts create mode 100644 cli/tests/testdata/run/with_package_json/package.json diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 02fa5c2a03abd7..e8777f45351472 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2693,6 +2693,11 @@ itest!(config_not_auto_discovered_for_remote_script { http_server: true, }); +itest!(package_json_auto_discovered_for_local_script_log { + args: "run -L debug run/with_package_json/main.ts", + output: "run/with_package_json/main.out", +}); + itest!(wasm_streaming_panic_test { args: "run run/wasm_streaming_panic_test.js", output: "run/wasm_streaming_panic_test.js.out", diff --git a/cli/tests/testdata/run/with_package_json/main.out b/cli/tests/testdata/run/with_package_json/main.out new file mode 100644 index 00000000000000..5cc235228495b6 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/main.out @@ -0,0 +1 @@ +[WILDCARD]package.json file found at [WILDCARD]with_package_json[WILDCARD]package.json \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/main.ts b/cli/tests/testdata/run/with_package_json/main.ts new file mode 100644 index 00000000000000..964148627ad868 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/main.ts @@ -0,0 +1,3 @@ +import express from "express"; + +console.log(express); diff --git a/cli/tests/testdata/run/with_package_json/package.json b/cli/tests/testdata/run/with_package_json/package.json new file mode 100644 index 00000000000000..566538964332cc --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "express": "4.17.1" + }, + "devDependencies": { + "chalk": "4.1.2" + } +} From e86421c1b55b17d9358d660a41b38c91e41b476e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 18 Feb 2023 15:58:42 +0100 Subject: [PATCH 50/60] improve tests --- cli/args/mod.rs | 3 +++ cli/tests/integration/run_tests.rs | 27 +++++++++++++++++-- .../testdata/run/with_package_json/main.out | 1 - .../testdata/run/with_package_json/main.ts | 3 --- .../with_package_json/no_deno_json/main.out | 3 +++ .../with_package_json/no_deno_json/main.ts | 6 +++++ .../no_deno_json/package.json | 8 ++++++ .../@denotest+check-error@1.0.0/.initialized | 0 .../@denotest/check-error/index.d.ts | 10 +++++++ .../@denotest/check-error/index.js | 6 +++++ .../@denotest/check-error/other_dir.d.ts | 1 + .../@denotest/check-error/other_dir/index.js | 1 + .../@denotest/check-error/package.json | 5 ++++ .../@denotest/check-error/sub_dir/index.d.ts | 1 + .../@denotest/check-error/sub_dir/index.js | 1 + .../@denotest/check-error/sub_dir/lib.d.ts | 1 + .../.initialized | 0 .../@denotest/cjs-default-export/index.d.ts | 6 +++++ .../@denotest/cjs-default-export/index.js | 17 ++++++++++++ .../@denotest/cjs-default-export/package.json | 5 ++++ .../node_modules/@denotest/check-error | 1 + .../node_modules/@denotest/cjs-default-export | 1 + .../run/with_package_json/npm_binary/main.out | 6 +++++ .../.deno/@denotest+bin@1.0.0/.initialized | 0 .../node_modules/@denotest/bin/cli-cjs.js | 5 ++++ .../node_modules/@denotest/bin/cli-no-ext | 5 ++++ .../node_modules/@denotest/bin/cli.mjs | 5 ++++ .../node_modules/@denotest/bin/package.json | 9 +++++++ .../@denotest+check-error@1.0.0/.initialized | 0 .../@denotest/check-error/index.d.ts | 10 +++++++ .../@denotest/check-error/index.js | 6 +++++ .../@denotest/check-error/other_dir.d.ts | 1 + .../@denotest/check-error/other_dir/index.js | 1 + .../@denotest/check-error/package.json | 5 ++++ .../@denotest/check-error/sub_dir/index.d.ts | 1 + .../@denotest/check-error/sub_dir/index.js | 1 + .../@denotest/check-error/sub_dir/lib.d.ts | 1 + .../.initialized | 0 .../@denotest/cjs-default-export/index.d.ts | 6 +++++ .../@denotest/cjs-default-export/index.js | 17 ++++++++++++ .../@denotest/cjs-default-export/package.json | 5 ++++ .../npm_binary/node_modules/@denotest/bin | 1 + .../node_modules/@denotest/check-error | 1 + .../node_modules/@denotest/cjs-default-export | 1 + .../with_package_json/npm_binary/package.json | 8 ++++++ .../run/with_package_json/package.json | 8 ------ .../run/with_package_json/with_stop/main.out | 4 +++ .../with_package_json/with_stop/package.json | 8 ++++++ .../with_stop/some/nested/deno.json | 5 ++++ .../with_stop/some/nested/dir/main.ts | 6 +++++ test_util/src/lib.rs | 8 ++++-- 51 files changed, 225 insertions(+), 16 deletions(-) delete mode 100644 cli/tests/testdata/run/with_package_json/main.out delete mode 100644 cli/tests/testdata/run/with_package_json/main.ts create mode 100644 cli/tests/testdata/run/with_package_json/no_deno_json/main.out create mode 100644 cli/tests/testdata/run/with_package_json/no_deno_json/main.ts create mode 100644 cli/tests/testdata/run/with_package_json/no_deno_json/package.json create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js create mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json create mode 120000 cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error create mode 120000 cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/main.out create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json create mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin create mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error create mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export create mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/package.json delete mode 100644 cli/tests/testdata/run/with_package_json/package.json create mode 100644 cli/tests/testdata/run/with_package_json/with_stop/main.out create mode 100644 cli/tests/testdata/run/with_package_json/with_stop/package.json create mode 100644 cli/tests/testdata/run/with_package_json/with_stop/some/nested/deno.json create mode 100644 cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 99d8534bac43f8..dac012effadeb0 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -423,6 +423,7 @@ fn discover_package_json( } } // No config file found. + log::debug!("No package.json file found"); Ok(None) } @@ -445,6 +446,8 @@ fn discover_package_json( let task_cwd = canonicalize_path(&PathBuf::from(path))?; return discover_from(&task_cwd, &mut HashSet::new(), None); } + + log::debug!("No package.json file found"); Ok(None) } diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index e8777f45351472..6a436c318cc358 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2694,8 +2694,31 @@ itest!(config_not_auto_discovered_for_remote_script { }); itest!(package_json_auto_discovered_for_local_script_log { - args: "run -L debug run/with_package_json/main.ts", - output: "run/with_package_json/main.out", + args: "run -L debug no_deno_json/main.ts", + output: "run/with_package_json/no_deno_json/main.out", + maybe_cwd: Some("run/with_package_json/"), + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, +}); + +// In this case we shouldn't discover `package.json` file, because it's in a +// directory that is above the directory containing `deno.json` file. +itest!( + package_json_auto_discovered_for_local_script_log_with_stop { + args: "run -L debug with_stop/some/nested/dir/main.ts", + output: "run/with_package_json/with_stop/main.out", + maybe_cwd: Some("run/with_package_json/"), + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, + } +); + +itest!(package_json_auto_discovered_for_npm_binary { + args: "run -L debug -A npm:@denotest/bin/cli-esm this is a test", + output: "run/with_package_json/npm_binary/main.out", + maybe_cwd: Some("run/with_package_json/npm_binary/"), + envs: env_vars_for_npm_tests_no_sync_download(), + http_server: true, }); itest!(wasm_streaming_panic_test { diff --git a/cli/tests/testdata/run/with_package_json/main.out b/cli/tests/testdata/run/with_package_json/main.out deleted file mode 100644 index 5cc235228495b6..00000000000000 --- a/cli/tests/testdata/run/with_package_json/main.out +++ /dev/null @@ -1 +0,0 @@ -[WILDCARD]package.json file found at [WILDCARD]with_package_json[WILDCARD]package.json \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/main.ts b/cli/tests/testdata/run/with_package_json/main.ts deleted file mode 100644 index 964148627ad868..00000000000000 --- a/cli/tests/testdata/run/with_package_json/main.ts +++ /dev/null @@ -1,3 +0,0 @@ -import express from "express"; - -console.log(express); diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/main.out b/cli/tests/testdata/run/with_package_json/no_deno_json/main.out new file mode 100644 index 00000000000000..c0dab77d061ca4 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/no_deno_json/main.out @@ -0,0 +1,3 @@ +[WILDCARD]package.json file found at '[WILDCARD]with_package_json[WILDCARD]package.json' +[WILDCARD] +ok diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts b/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts new file mode 100644 index 00000000000000..daefa8f60931f1 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts @@ -0,0 +1,6 @@ +// TODO(bartlomieju): currently we don't support actual bare specifier +// imports; this will be done in a follow up PR. +// import express from "express"; + +// console.log(express); +console.log("ok"); diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/package.json b/cli/tests/testdata/run/with_package_json/no_deno_json/package.json new file mode 100644 index 00000000000000..9ee3f39a8636e0 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/no_deno_json/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@denotest/check-error": "1.0.0" + }, + "devDependencies": { + "@denotest/cjs-default-export": "1.0.0" + } +} diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts new file mode 100644 index 00000000000000..bfb0483c286745 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts @@ -0,0 +1,10 @@ +// intentional type checking errors +export class Class1 extends Class2 { +} + +export class Class2 extends Class1 { +} + +// these should be fine though +export { subDir } from "./sub_dir"; +export { otherDir } from "./other_dir"; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js new file mode 100644 index 00000000000000..7eb6b784d59259 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js @@ -0,0 +1,6 @@ +module.exports = { + Class1: class { + }, + Class2: class { + }, +}; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts new file mode 100644 index 00000000000000..e7254c16c29e1c --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts @@ -0,0 +1 @@ +export const otherDir: 2; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js new file mode 100644 index 00000000000000..56259f22d25a7b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js @@ -0,0 +1 @@ +module.exports.otherDir = 2; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json new file mode 100644 index 00000000000000..295920a8f7acee --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/check-error", + "version": "1.0.0", + "types": "./index.d.ts" +} diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts new file mode 100644 index 00000000000000..f41a696fd204db --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts @@ -0,0 +1 @@ +export * from './lib'; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js new file mode 100644 index 00000000000000..3dfac4c23520f8 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js @@ -0,0 +1 @@ +module.exports.subDir = 1; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts new file mode 100644 index 00000000000000..e5834b52bb83c2 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts @@ -0,0 +1 @@ +export const subDir: 1; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts new file mode 100644 index 00000000000000..90fdfe5f673998 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts @@ -0,0 +1,6 @@ +export default function (): number; +export declare function named(): number; +declare class MyClass { + static someStaticMethod(): string; +} +export { MyClass }; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js new file mode 100644 index 00000000000000..ec4ece6b339528 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js @@ -0,0 +1,17 @@ +Object.defineProperty(module.exports, "__esModule", { + value: true +}); +module.exports["default"] = function() { + return 1; +}; +module.exports["named"] = function() { + return 2; +}; + +class MyClass { + static someStaticMethod() { + return "static method"; + } +} + +module.exports.MyClass = MyClass; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json new file mode 100644 index 00000000000000..8da28b91925c6e --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/cjs-default-export", + "version": "1.0.0", + "types": "./index.d.ts" +} diff --git a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error new file mode 120000 index 00000000000000..caf3255f1bb934 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error @@ -0,0 +1 @@ +/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export new file mode 120000 index 00000000000000..93cb537e4ddecf --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export @@ -0,0 +1 @@ +/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/main.out b/cli/tests/testdata/run/with_package_json/npm_binary/main.out new file mode 100644 index 00000000000000..56cdae6f94d11e --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/main.out @@ -0,0 +1,6 @@ +[WILDCARD]package.json file found at '[WILDCARD]with_package_json[WILDCARD]npm_binary[WILDCARD]package.json' +[WILDCARD] +this +is +a +test diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js new file mode 100644 index 00000000000000..7b6ba272416a0b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js @@ -0,0 +1,5 @@ +const process = require("process"); + +for (const arg of process.argv.slice(2)) { + console.log(arg); +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext new file mode 100644 index 00000000000000..7b6ba272416a0b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext @@ -0,0 +1,5 @@ +const process = require("process"); + +for (const arg of process.argv.slice(2)) { + console.log(arg); +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs new file mode 100644 index 00000000000000..0ae8e919033045 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs @@ -0,0 +1,5 @@ +import process from "node:process"; + +for (const arg of process.argv.slice(2)) { + console.log(arg); +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json new file mode 100644 index 00000000000000..78a1abff2f97f8 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json @@ -0,0 +1,9 @@ +{ + "name": "@deno/bin", + "version": "1.0.0", + "bin": { + "cli-esm": "./cli.mjs", + "cli-no-ext": "./cli-no-ext", + "cli-cjs": "./cli-cjs.js" + } +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts new file mode 100644 index 00000000000000..bfb0483c286745 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts @@ -0,0 +1,10 @@ +// intentional type checking errors +export class Class1 extends Class2 { +} + +export class Class2 extends Class1 { +} + +// these should be fine though +export { subDir } from "./sub_dir"; +export { otherDir } from "./other_dir"; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js new file mode 100644 index 00000000000000..7eb6b784d59259 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js @@ -0,0 +1,6 @@ +module.exports = { + Class1: class { + }, + Class2: class { + }, +}; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts new file mode 100644 index 00000000000000..e7254c16c29e1c --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts @@ -0,0 +1 @@ +export const otherDir: 2; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js new file mode 100644 index 00000000000000..56259f22d25a7b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js @@ -0,0 +1 @@ +module.exports.otherDir = 2; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json new file mode 100644 index 00000000000000..295920a8f7acee --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/check-error", + "version": "1.0.0", + "types": "./index.d.ts" +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts new file mode 100644 index 00000000000000..f41a696fd204db --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts @@ -0,0 +1 @@ +export * from './lib'; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js new file mode 100644 index 00000000000000..3dfac4c23520f8 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js @@ -0,0 +1 @@ +module.exports.subDir = 1; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts new file mode 100644 index 00000000000000..e5834b52bb83c2 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts @@ -0,0 +1 @@ +export const subDir: 1; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts new file mode 100644 index 00000000000000..90fdfe5f673998 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts @@ -0,0 +1,6 @@ +export default function (): number; +export declare function named(): number; +declare class MyClass { + static someStaticMethod(): string; +} +export { MyClass }; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js new file mode 100644 index 00000000000000..ec4ece6b339528 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js @@ -0,0 +1,17 @@ +Object.defineProperty(module.exports, "__esModule", { + value: true +}); +module.exports["default"] = function() { + return 1; +}; +module.exports["named"] = function() { + return 2; +}; + +class MyClass { + static someStaticMethod() { + return "static method"; + } +} + +module.exports.MyClass = MyClass; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json new file mode 100644 index 00000000000000..8da28b91925c6e --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/cjs-default-export", + "version": "1.0.0", + "types": "./index.d.ts" +} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin new file mode 120000 index 00000000000000..9df6b2918503e5 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin @@ -0,0 +1 @@ +/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error new file mode 120000 index 00000000000000..3fef96e9ece255 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error @@ -0,0 +1 @@ +/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export new file mode 120000 index 00000000000000..ff3d11314cd58b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export @@ -0,0 +1 @@ +/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/package.json new file mode 100644 index 00000000000000..9ee3f39a8636e0 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/npm_binary/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@denotest/check-error": "1.0.0" + }, + "devDependencies": { + "@denotest/cjs-default-export": "1.0.0" + } +} diff --git a/cli/tests/testdata/run/with_package_json/package.json b/cli/tests/testdata/run/with_package_json/package.json deleted file mode 100644 index 566538964332cc..00000000000000 --- a/cli/tests/testdata/run/with_package_json/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "express": "4.17.1" - }, - "devDependencies": { - "chalk": "4.1.2" - } -} diff --git a/cli/tests/testdata/run/with_package_json/with_stop/main.out b/cli/tests/testdata/run/with_package_json/with_stop/main.out new file mode 100644 index 00000000000000..e7ef053e4b423b --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/with_stop/main.out @@ -0,0 +1,4 @@ +[WILDCARD]Config file found at '[WILDCARD]with_package_json[WILDCARD]with_stop[WILDCARD]some[WILDCARD]nested[WILDCARD]deno.json' +[WILDCARD]No package.json file found +[WILDCARD] +ok diff --git a/cli/tests/testdata/run/with_package_json/with_stop/package.json b/cli/tests/testdata/run/with_package_json/with_stop/package.json new file mode 100644 index 00000000000000..9ee3f39a8636e0 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/with_stop/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@denotest/check-error": "1.0.0" + }, + "devDependencies": { + "@denotest/cjs-default-export": "1.0.0" + } +} diff --git a/cli/tests/testdata/run/with_package_json/with_stop/some/nested/deno.json b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/deno.json new file mode 100644 index 00000000000000..36e1765d1aface --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "dev": "deno run main.ts" + } +} diff --git a/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts new file mode 100644 index 00000000000000..daefa8f60931f1 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts @@ -0,0 +1,6 @@ +// TODO(bartlomieju): currently we don't support actual bare specifier +// imports; this will be done in a follow up PR. +// import express from "express"; + +// console.log(express); +console.log("ok"); diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 5aac13855466d0..555c26ffefae97 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1923,6 +1923,8 @@ pub struct CheckOutputIntegrationTest<'a> { pub envs: Vec<(String, String)>, pub env_clear: bool, pub temp_cwd: bool, + // Relative to "testdata" directory + pub maybe_cwd: Option<&'a str>, } impl<'a> CheckOutputIntegrationTest<'a> { @@ -1954,9 +1956,11 @@ impl<'a> CheckOutputIntegrationTest<'a> { let deno_dir = new_deno_dir(); // keep this alive for the test let mut command = deno_cmd_with_deno_dir(&deno_dir); let cwd = if self.temp_cwd { - deno_dir.path() + deno_dir.path().to_owned() + } else if let Some(cwd_) = &self.maybe_cwd { + testdata_dir.join(cwd_) } else { - testdata_dir.as_path() + testdata_dir.clone() }; println!("deno_exe args {}", args.join(" ")); println!("deno_exe cwd {:?}", &cwd); From da7da75e4eea3b97e550f834f1c7149eb6b777cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 18 Feb 2023 16:09:44 +0100 Subject: [PATCH 51/60] update assertion --- cli/tests/integration/watcher_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs index 99d5a572792a95..0c9b8c29f0ea73 100644 --- a/cli/tests/integration/watcher_tests.rs +++ b/cli/tests/integration/watcher_tests.rs @@ -1177,7 +1177,7 @@ fn run_watch_dynamic_imports() { .spawn() .unwrap(); let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child); - + assert_contains!(stderr_lines.next().unwrap(), "No package.json file found"); assert_contains!(stderr_lines.next().unwrap(), "Process started"); wait_contains( From b792073a39f446bd0c4c89a9e64e93313c8e4b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 02:17:21 +0100 Subject: [PATCH 52/60] fix remaining test --- cli/args/mod.rs | 58 ++++++++++++++++++++++++++++-- cli/lsp/language_server.rs | 2 +- cli/npm/mod.rs | 1 + cli/npm/resolvers/mod.rs | 73 ++++++++++++++------------------------ cli/proc_state.rs | 1 + cli/worker.rs | 2 +- 6 files changed, 86 insertions(+), 51 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index dac012effadeb0..aefad07e64c9ca 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -35,6 +35,7 @@ use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::normalize_path; use deno_core::parking_lot::Mutex; +use deno_core::serde_json; use deno_core::url::Url; use deno_graph::npm::NpmPackageReq; use deno_runtime::colors; @@ -46,6 +47,7 @@ use deno_runtime::deno_tls::rustls_pemfile; use deno_runtime::deno_tls::webpki_roots; use deno_runtime::inspector_server::InspectorServer; use deno_runtime::permissions::PermissionsOptions; +use once_cell::sync::Lazy; use std::collections::BTreeMap; use std::collections::HashMap; use std::collections::HashSet; @@ -60,6 +62,9 @@ use std::sync::Arc; use crate::cache::DenoDir; use crate::file_fetcher::FileFetcher; +// TODO(bartlomieju): refactor this bit; we have a circular dependency +// between this file and `cli/npm/resolver/mod.rs`. +use crate::npm::NpmProcessState; use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::version; @@ -535,6 +540,12 @@ pub fn get_root_cert_store( Ok(root_cert_store) } +const RESOLUTION_STATE_ENV_VAR_NAME: &str = + "DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE"; + +static IS_NPM_MAIN: Lazy = + Lazy::new(|| std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).is_ok()); + /// Overrides for the options below that when set will /// use these values over the values derived from the /// CLI flags or config file. @@ -553,6 +564,7 @@ pub struct CliOptions { maybe_package_json: Option, maybe_lockfile: Option>>, overrides: CliOptionOverrides, + npm_process_state: Arc>>, } impl CliOptions { @@ -584,6 +596,7 @@ impl CliOptions { maybe_package_json, flags, overrides: Default::default(), + npm_process_state: Arc::new(Mutex::new(None)), } } @@ -686,16 +699,55 @@ impl CliOptions { .map(Some) } + // TODO(bartlomieju): remove in favor of `is_npm_main()` + pub fn was_npm_process_state_set(&self) -> bool { + *IS_NPM_MAIN + } + + pub fn get_npm_process_state(&self) -> Option { + if !self.was_npm_process_state_set() { + return None; + } + + let mut maybe_state = self.npm_process_state.lock(); + + // TODO(bartlomieju): remove this clone, return a reference maybe? + if maybe_state.is_some() { + return maybe_state.clone(); + } + + let state = std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).ok()?; + let state: NpmProcessState = serde_json::from_str(&state).ok()?; + // remove the environment variable so that sub processes + // that are spawned do not also use this. + std::env::remove_var(RESOLUTION_STATE_ENV_VAR_NAME); + *maybe_state = Some(state.clone()); + Some(state) + } + + // If the main module should be treated as being in an npm package. + // This is triggered via a secret environment variable which is used + // for functionality like child_process.fork. Users should NOT depend + // on this functionality. + pub fn is_npm_main(&self) -> bool { + self.was_npm_process_state_set() + } + /// Overrides the import map specifier to use. pub fn set_import_map_specifier(&mut self, path: Option) { self.overrides.import_map_specifier = Some(path); } pub fn node_modules_dir(&self) -> bool { - match self.flags.node_modules_dir { - Some(value) => value, - None => self.maybe_package_json.is_some(), + if let Some(node_modules_dir) = self.flags.node_modules_dir { + return node_modules_dir; + } + + if let Some(npm_process_state) = self.get_npm_process_state() { + return npm_process_state.local_node_modules_path.is_some(); } + + self.maybe_package_json.is_some() } /// Resolves the path to use for a local node_modules folder. diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index abb2af95c27ece..9a5e36b37e990c 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -322,7 +322,7 @@ fn create_lsp_npm_resolver( http_client, progress_bar, ); - NpmPackageResolver::new(npm_cache, api, false, None) + NpmPackageResolver::new(npm_cache, api, false, None, None) } impl Inner { diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 4be13707ef5241..20db61081e4972 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -16,3 +16,4 @@ pub use resolution::NpmPackageNodeId; pub use resolution::NpmResolutionPackage; pub use resolution::NpmResolutionSnapshot; pub use resolvers::NpmPackageResolver; +pub use resolvers::NpmProcessState; diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 9dda160b0cdcab..e8e61a9644d3c7 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -17,7 +17,6 @@ use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::PathClean; use deno_runtime::deno_node::RequireNpmResolver; use global::GlobalNpmPackageResolver; -use once_cell::sync::Lazy; use serde::Deserialize; use serde::Serialize; use std::collections::HashSet; @@ -35,37 +34,11 @@ use super::NpmPackageNodeId; use super::NpmResolutionSnapshot; use super::RealNpmRegistryApi; -const RESOLUTION_STATE_ENV_VAR_NAME: &str = - "DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE"; - -static IS_NPM_MAIN: Lazy = - Lazy::new(|| std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).is_ok()); - /// State provided to the process via an environment variable. -#[derive(Debug, Serialize, Deserialize)] -struct NpmProcessState { - snapshot: NpmResolutionSnapshot, - local_node_modules_path: Option, -} - -impl NpmProcessState { - pub fn was_set() -> bool { - *IS_NPM_MAIN - } - - pub fn take() -> Option { - // initialize the lazy before we remove the env var below - if !Self::was_set() { - return None; - } - - let state = std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).ok()?; - let state = serde_json::from_str(&state).ok()?; - // remove the environment variable so that sub processes - // that are spawned do not also use this. - std::env::remove_var(RESOLUTION_STATE_ENV_VAR_NAME); - Some(state) - } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NpmProcessState { + pub snapshot: NpmResolutionSnapshot, + pub local_node_modules_path: Option, } #[derive(Clone)] @@ -93,15 +66,25 @@ impl NpmPackageResolver { cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, + process_npm_state: Option, local_node_modules_path: Option, ) -> Self { - Self::new_inner(cache, api, no_npm, local_node_modules_path, None, None) + Self::new_inner( + cache, + api, + no_npm, + process_npm_state, + local_node_modules_path, + None, + None, + ) } pub async fn new_with_maybe_lockfile( cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, + process_npm_state: Option, local_node_modules_path: Option, maybe_lockfile: Option>>, ) -> Result { @@ -127,6 +110,7 @@ impl NpmPackageResolver { cache, api, no_npm, + process_npm_state, local_node_modules_path, maybe_snapshot, maybe_lockfile, @@ -137,16 +121,20 @@ impl NpmPackageResolver { cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, + process_npm_state: Option, local_node_modules_path: Option, initial_snapshot: Option, maybe_lockfile: Option>>, ) -> Self { - let process_npm_state = NpmProcessState::take(); - let local_node_modules_path = local_node_modules_path.or_else(|| { - process_npm_state - .as_ref() - .and_then(|s| s.local_node_modules_path.as_ref().map(PathBuf::from)) - }); + // TODO(bartlomieju): `local_node_modules_path` processing should be done + // in cli/args/mod.rs + let local_node_modules_path = + if let Some(state) = process_npm_state.as_ref() { + state.local_node_modules_path.as_ref().map(PathBuf::from) + } else { + local_node_modules_path + }; + let maybe_snapshot = initial_snapshot.or_else(|| process_npm_state.map(|s| s.snapshot)); let inner: Arc = match &local_node_modules_path @@ -289,14 +277,6 @@ impl NpmPackageResolver { self.inner.set_package_reqs(packages).await } - // If the main module should be treated as being in an npm package. - // This is triggered via a secret environment variable which is used - // for functionality like child_process.fork. Users should NOT depend - // on this functionality. - pub fn is_npm_main(&self) -> bool { - NpmProcessState::was_set() - } - /// Gets the state of npm for the process. pub fn get_npm_process_state(&self) -> String { serde_json::to_string(&NpmProcessState { @@ -315,6 +295,7 @@ impl NpmPackageResolver { self.cache.clone(), self.api.clone(), self.no_npm, + None, self.local_node_modules_path.clone(), Some(self.snapshot()), None, diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 9462cc429eed67..27e22f5fee55ef 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -261,6 +261,7 @@ impl ProcState { npm_cache.clone(), api, cli_options.no_npm(), + cli_options.get_npm_process_state(), cli_options .resolve_local_node_modules_folder() .with_context(|| "Resolving local node_modules folder.")?, diff --git a/cli/worker.rs b/cli/worker.rs index 72126d44fbe32a..7293183bf81203 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -457,7 +457,7 @@ async fn create_main_worker_internal( let is_main_cjs = matches!(node_resolution, node::NodeResolution::CommonJs(_)); (node_resolution.into_url(), is_main_cjs) - } else if ps.npm_resolver.is_npm_main() { + } else if ps.options.is_npm_main() { let node_resolution = node::url_to_node_resolution(main_module, &ps.npm_resolver)?; let is_main_cjs = From 8d2bce5a45a0c040ccdce55395bed2f2d813c76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 02:49:48 +0100 Subject: [PATCH 53/60] don't forward NpmProcessState --- cli/args/mod.rs | 20 +++++++---- cli/lsp/language_server.rs | 2 +- cli/npm/resolvers/mod.rs | 73 ++++++++++++-------------------------- cli/proc_state.rs | 2 +- 4 files changed, 38 insertions(+), 59 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index aefad07e64c9ca..c8e14898ae9b6a 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -10,6 +10,7 @@ pub mod package_json; pub use self::import_map::resolve_import_map_from_specifier; use ::import_map::ImportMap; +use crate::npm::NpmResolutionSnapshot; use crate::util::fs::canonicalize_path; pub use config_file::BenchConfig; pub use config_file::CompilerOptions; @@ -699,13 +700,8 @@ impl CliOptions { .map(Some) } - // TODO(bartlomieju): remove in favor of `is_npm_main()` - pub fn was_npm_process_state_set(&self) -> bool { - *IS_NPM_MAIN - } - pub fn get_npm_process_state(&self) -> Option { - if !self.was_npm_process_state_set() { + if !self.is_npm_main() { return None; } @@ -725,12 +721,20 @@ impl CliOptions { Some(state) } + pub fn get_npm_resolution_snapshot(&self) -> Option { + if let Some(state) = self.get_npm_process_state() { + return Some(state.snapshot); + } + + None + } + // If the main module should be treated as being in an npm package. // This is triggered via a secret environment variable which is used // for functionality like child_process.fork. Users should NOT depend // on this functionality. pub fn is_npm_main(&self) -> bool { - self.was_npm_process_state_set() + *IS_NPM_MAIN } /// Overrides the import map specifier to use. @@ -756,6 +760,8 @@ impl CliOptions { ) -> Result, AnyError> { let path = if !self.node_modules_dir() { return Ok(None); + } else if let Some(state) = self.get_npm_process_state() { + return Ok(state.local_node_modules_path.as_ref().map(PathBuf::from)); } else if let Some(config_path) = self .maybe_config_file .as_ref() diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9a5e36b37e990c..1bde85d8f65b92 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -322,7 +322,7 @@ fn create_lsp_npm_resolver( http_client, progress_bar, ); - NpmPackageResolver::new(npm_cache, api, false, None, None) + NpmPackageResolver::new(npm_cache, api) } impl Inner { diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index e8e61a9644d3c7..a2638a15b083cb 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -62,57 +62,43 @@ impl std::fmt::Debug for NpmPackageResolver { } impl NpmPackageResolver { - pub fn new( - cache: NpmCache, - api: RealNpmRegistryApi, - no_npm: bool, - process_npm_state: Option, - local_node_modules_path: Option, - ) -> Self { - Self::new_inner( - cache, - api, - no_npm, - process_npm_state, - local_node_modules_path, - None, - None, - ) + pub fn new(cache: NpmCache, api: RealNpmRegistryApi) -> Self { + Self::new_inner(cache, api, false, None, None, None) } pub async fn new_with_maybe_lockfile( cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, - process_npm_state: Option, local_node_modules_path: Option, + initial_snapshot: Option, maybe_lockfile: Option>>, ) -> Result { - let maybe_snapshot = if let Some(lockfile) = &maybe_lockfile { - if lockfile.lock().overwrite { - None - } else { - Some( - NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &api) - .await - .with_context(|| { - format!( - "failed reading lockfile '{}'", - lockfile.lock().filename.display() - ) - })?, - ) + let mut initial_snapshot = initial_snapshot; + + if initial_snapshot.is_none() { + if let Some(lockfile) = &maybe_lockfile { + if !lockfile.lock().overwrite { + initial_snapshot = Some( + NpmResolutionSnapshot::from_lockfile(lockfile.clone(), &api) + .await + .with_context(|| { + format!( + "failed reading lockfile '{}'", + lockfile.lock().filename.display() + ) + })?, + ) + } } - } else { - None - }; + } + Ok(Self::new_inner( cache, api, no_npm, - process_npm_state, local_node_modules_path, - maybe_snapshot, + initial_snapshot, maybe_lockfile, )) } @@ -121,22 +107,10 @@ impl NpmPackageResolver { cache: NpmCache, api: RealNpmRegistryApi, no_npm: bool, - process_npm_state: Option, local_node_modules_path: Option, - initial_snapshot: Option, + maybe_snapshot: Option, maybe_lockfile: Option>>, ) -> Self { - // TODO(bartlomieju): `local_node_modules_path` processing should be done - // in cli/args/mod.rs - let local_node_modules_path = - if let Some(state) = process_npm_state.as_ref() { - state.local_node_modules_path.as_ref().map(PathBuf::from) - } else { - local_node_modules_path - }; - - let maybe_snapshot = - initial_snapshot.or_else(|| process_npm_state.map(|s| s.snapshot)); let inner: Arc = match &local_node_modules_path { Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new( @@ -295,7 +269,6 @@ impl NpmPackageResolver { self.cache.clone(), self.api.clone(), self.no_npm, - None, self.local_node_modules_path.clone(), Some(self.snapshot()), None, diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 27e22f5fee55ef..b4467b6be13a62 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -261,10 +261,10 @@ impl ProcState { npm_cache.clone(), api, cli_options.no_npm(), - cli_options.get_npm_process_state(), cli_options .resolve_local_node_modules_folder() .with_context(|| "Resolving local node_modules folder.")?, + cli_options.get_npm_resolution_snapshot(), lockfile.as_ref().cloned(), ) .await?; From d0f29ac8d78dac491546b291554f20e550497cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 02:53:26 +0100 Subject: [PATCH 54/60] remove pub --- cli/args/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index c8e14898ae9b6a..96d458be43d0dc 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -700,7 +700,7 @@ impl CliOptions { .map(Some) } - pub fn get_npm_process_state(&self) -> Option { + fn get_npm_process_state(&self) -> Option { if !self.is_npm_main() { return None; } From a43a91c25e02fba7238313d726240e3fd2056455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 02:59:01 +0100 Subject: [PATCH 55/60] remove node_modules dir --- .../@denotest+check-error@1.0.0/.initialized | 0 .../@denotest/check-error/index.d.ts | 10 ---------- .../node_modules/@denotest/check-error/index.js | 6 ------ .../@denotest/check-error/other_dir.d.ts | 1 - .../@denotest/check-error/other_dir/index.js | 1 - .../@denotest/check-error/package.json | 5 ----- .../@denotest/check-error/sub_dir/index.d.ts | 1 - .../@denotest/check-error/sub_dir/index.js | 1 - .../@denotest/check-error/sub_dir/lib.d.ts | 1 - .../.initialized | 0 .../@denotest/cjs-default-export/index.d.ts | 6 ------ .../@denotest/cjs-default-export/index.js | 17 ----------------- .../@denotest/cjs-default-export/package.json | 5 ----- .../node_modules/@denotest/check-error | 1 - .../node_modules/@denotest/cjs-default-export | 1 - 15 files changed, 56 deletions(-) delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json delete mode 120000 cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error delete mode 120000 cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/.initialized deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts deleted file mode 100644 index bfb0483c286745..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -// intentional type checking errors -export class Class1 extends Class2 { -} - -export class Class2 extends Class1 { -} - -// these should be fine though -export { subDir } from "./sub_dir"; -export { otherDir } from "./other_dir"; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js deleted file mode 100644 index 7eb6b784d59259..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - Class1: class { - }, - Class2: class { - }, -}; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts deleted file mode 100644 index e7254c16c29e1c..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts +++ /dev/null @@ -1 +0,0 @@ -export const otherDir: 2; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js deleted file mode 100644 index 56259f22d25a7b..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.otherDir = 2; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json deleted file mode 100644 index 295920a8f7acee..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@denotest/check-error", - "version": "1.0.0", - "types": "./index.d.ts" -} diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts deleted file mode 100644 index f41a696fd204db..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lib'; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js deleted file mode 100644 index 3dfac4c23520f8..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.subDir = 1; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts deleted file mode 100644 index e5834b52bb83c2..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts +++ /dev/null @@ -1 +0,0 @@ -export const subDir: 1; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts deleted file mode 100644 index 90fdfe5f673998..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default function (): number; -export declare function named(): number; -declare class MyClass { - static someStaticMethod(): string; -} -export { MyClass }; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js deleted file mode 100644 index ec4ece6b339528..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js +++ /dev/null @@ -1,17 +0,0 @@ -Object.defineProperty(module.exports, "__esModule", { - value: true -}); -module.exports["default"] = function() { - return 1; -}; -module.exports["named"] = function() { - return 2; -}; - -class MyClass { - static someStaticMethod() { - return "static method"; - } -} - -module.exports.MyClass = MyClass; diff --git a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json b/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json deleted file mode 100644 index 8da28b91925c6e..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@denotest/cjs-default-export", - "version": "1.0.0", - "types": "./index.d.ts" -} diff --git a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error deleted file mode 120000 index caf3255f1bb934..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/check-error +++ /dev/null @@ -1 +0,0 @@ -/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export b/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export deleted file mode 120000 index 93cb537e4ddecf..00000000000000 --- a/cli/tests/testdata/run/with_package_json/node_modules/@denotest/cjs-default-export +++ /dev/null @@ -1 +0,0 @@ -/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export \ No newline at end of file From ed1e0196816dfb5f146b4c8394fd8e476e56be6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 02:59:29 +0100 Subject: [PATCH 56/60] add git ignore --- cli/tests/testdata/run/with_package_json/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 cli/tests/testdata/run/with_package_json/.gitignore diff --git a/cli/tests/testdata/run/with_package_json/.gitignore b/cli/tests/testdata/run/with_package_json/.gitignore new file mode 100644 index 00000000000000..40b878db5b1c97 --- /dev/null +++ b/cli/tests/testdata/run/with_package_json/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file From b7e28972234027878b957df9c2b4e45ea7f66553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Feb 2023 03:00:09 +0100 Subject: [PATCH 57/60] remove node_modules dir --- .../.deno/@denotest+bin@1.0.0/.initialized | 0 .../node_modules/@denotest/bin/cli-cjs.js | 5 ----- .../node_modules/@denotest/bin/cli-no-ext | 5 ----- .../node_modules/@denotest/bin/cli.mjs | 5 ----- .../node_modules/@denotest/bin/package.json | 9 --------- .../@denotest+check-error@1.0.0/.initialized | 0 .../@denotest/check-error/index.d.ts | 10 ---------- .../node_modules/@denotest/check-error/index.js | 6 ------ .../@denotest/check-error/other_dir.d.ts | 1 - .../@denotest/check-error/other_dir/index.js | 1 - .../@denotest/check-error/package.json | 5 ----- .../@denotest/check-error/sub_dir/index.d.ts | 1 - .../@denotest/check-error/sub_dir/index.js | 1 - .../@denotest/check-error/sub_dir/lib.d.ts | 1 - .../.initialized | 0 .../@denotest/cjs-default-export/index.d.ts | 6 ------ .../@denotest/cjs-default-export/index.js | 17 ----------------- .../@denotest/cjs-default-export/package.json | 5 ----- .../npm_binary/node_modules/@denotest/bin | 1 - .../node_modules/@denotest/check-error | 1 - .../node_modules/@denotest/cjs-default-export | 1 - 21 files changed, 81 deletions(-) delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js delete mode 100644 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json delete mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin delete mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error delete mode 120000 cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/.initialized deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js deleted file mode 100644 index 7b6ba272416a0b..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-cjs.js +++ /dev/null @@ -1,5 +0,0 @@ -const process = require("process"); - -for (const arg of process.argv.slice(2)) { - console.log(arg); -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext deleted file mode 100644 index 7b6ba272416a0b..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli-no-ext +++ /dev/null @@ -1,5 +0,0 @@ -const process = require("process"); - -for (const arg of process.argv.slice(2)) { - console.log(arg); -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs deleted file mode 100644 index 0ae8e919033045..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/cli.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import process from "node:process"; - -for (const arg of process.argv.slice(2)) { - console.log(arg); -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json deleted file mode 100644 index 78a1abff2f97f8..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@deno/bin", - "version": "1.0.0", - "bin": { - "cli-esm": "./cli.mjs", - "cli-no-ext": "./cli-no-ext", - "cli-cjs": "./cli-cjs.js" - } -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/.initialized deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts deleted file mode 100644 index bfb0483c286745..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -// intentional type checking errors -export class Class1 extends Class2 { -} - -export class Class2 extends Class1 { -} - -// these should be fine though -export { subDir } from "./sub_dir"; -export { otherDir } from "./other_dir"; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js deleted file mode 100644 index 7eb6b784d59259..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - Class1: class { - }, - Class2: class { - }, -}; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts deleted file mode 100644 index e7254c16c29e1c..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir.d.ts +++ /dev/null @@ -1 +0,0 @@ -export const otherDir: 2; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js deleted file mode 100644 index 56259f22d25a7b..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/other_dir/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.otherDir = 2; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json deleted file mode 100644 index 295920a8f7acee..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@denotest/check-error", - "version": "1.0.0", - "types": "./index.d.ts" -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts deleted file mode 100644 index f41a696fd204db..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lib'; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js deleted file mode 100644 index 3dfac4c23520f8..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.subDir = 1; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts deleted file mode 100644 index e5834b52bb83c2..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error/sub_dir/lib.d.ts +++ /dev/null @@ -1 +0,0 @@ -export const subDir: 1; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/.initialized deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts deleted file mode 100644 index 90fdfe5f673998..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default function (): number; -export declare function named(): number; -declare class MyClass { - static someStaticMethod(): string; -} -export { MyClass }; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js deleted file mode 100644 index ec4ece6b339528..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/index.js +++ /dev/null @@ -1,17 +0,0 @@ -Object.defineProperty(module.exports, "__esModule", { - value: true -}); -module.exports["default"] = function() { - return 1; -}; -module.exports["named"] = function() { - return 2; -}; - -class MyClass { - static someStaticMethod() { - return "static method"; - } -} - -module.exports.MyClass = MyClass; diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json deleted file mode 100644 index 8da28b91925c6e..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@denotest/cjs-default-export", - "version": "1.0.0", - "types": "./index.d.ts" -} diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin deleted file mode 120000 index 9df6b2918503e5..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/bin +++ /dev/null @@ -1 +0,0 @@ -/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+bin@1.0.0/node_modules/@denotest/bin \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error deleted file mode 120000 index 3fef96e9ece255..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/check-error +++ /dev/null @@ -1 +0,0 @@ -/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+check-error@1.0.0/node_modules/@denotest/check-error \ No newline at end of file diff --git a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export b/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export deleted file mode 120000 index ff3d11314cd58b..00000000000000 --- a/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/@denotest/cjs-default-export +++ /dev/null @@ -1 +0,0 @@ -/Users/ib/dev/deno/cli/tests/testdata/run/with_package_json/npm_binary/node_modules/.deno/@denotest+cjs-default-export@1.0.0/node_modules/@denotest/cjs-default-export \ No newline at end of file From 07ea6f0aaae43663e2d8e0ba7dfc6d240a6e5544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 20 Feb 2023 02:18:10 +0100 Subject: [PATCH 58/60] fix error when parsing --- cli/args/package_json.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index 56a7b0fb3a0d6c..76d353c5ecf0ed 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; +use deno_core::anyhow::anyhow; use deno_core::anyhow::bail; -use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_graph::npm::NpmPackageReq; use deno_graph::semver::VersionReq; @@ -43,11 +43,20 @@ pub fn get_local_package_json_version_reqs( for (key, value) in deps { let (name, version_req) = parse_dep_entry_name_and_raw_version(key, value)?; - let version_req = VersionReq::parse_from_specifier(version_req) - .context(concat!( - "Parsing version constraints in the application-level ", - "package.json is more strict at the moment" - ))?; + + let version_req = { + let result = VersionReq::parse_from_specifier(version_req); + match result { + Ok(version_req) => version_req, + Err(e) => { + let err = anyhow!("{:#}", e).context(concat!( + "Parsing version constraints in the application-level ", + "package.json is more strict at the moment" + )); + return Err(err); + } + } + }; result.insert( key.to_string(), NpmPackageReq { @@ -151,8 +160,6 @@ mod test { "package.json is more strict at the moment: Invalid npm specifier ", "version requirement. Unexpected character.\n", " - 1.3\n", - " ~: Unexpected character.\n", - " - 1.3\n", " ~" ) ); From 594d6ff22583c99f8d96fb5faca829a3e92cc668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 20 Feb 2023 18:10:50 +0100 Subject: [PATCH 59/60] review --- cli/args/mod.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 96d458be43d0dc..d25313f5a1efb4 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -547,6 +547,15 @@ const RESOLUTION_STATE_ENV_VAR_NAME: &str = static IS_NPM_MAIN: Lazy = Lazy::new(|| std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).is_ok()); +static NPM_PROCESS_STATE: Lazy> = Lazy::new(|| { + let state = std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).ok()?; + let state: NpmProcessState = serde_json::from_str(&state).ok()?; + // remove the environment variable so that sub processes + // that are spawned do not also use this. + std::env::remove_var(RESOLUTION_STATE_ENV_VAR_NAME); + Some(state) +}); + /// Overrides for the options below that when set will /// use these values over the values derived from the /// CLI flags or config file. @@ -565,7 +574,6 @@ pub struct CliOptions { maybe_package_json: Option, maybe_lockfile: Option>>, overrides: CliOptionOverrides, - npm_process_state: Arc>>, } impl CliOptions { @@ -597,7 +605,6 @@ impl CliOptions { maybe_package_json, flags, overrides: Default::default(), - npm_process_state: Arc::new(Mutex::new(None)), } } @@ -700,30 +707,18 @@ impl CliOptions { .map(Some) } - fn get_npm_process_state(&self) -> Option { + fn get_npm_process_state(&self) -> Option<&NpmProcessState> { if !self.is_npm_main() { return None; } - let mut maybe_state = self.npm_process_state.lock(); - - // TODO(bartlomieju): remove this clone, return a reference maybe? - if maybe_state.is_some() { - return maybe_state.clone(); - } - - let state = std::env::var(RESOLUTION_STATE_ENV_VAR_NAME).ok()?; - let state: NpmProcessState = serde_json::from_str(&state).ok()?; - // remove the environment variable so that sub processes - // that are spawned do not also use this. - std::env::remove_var(RESOLUTION_STATE_ENV_VAR_NAME); - *maybe_state = Some(state.clone()); - Some(state) + (*NPM_PROCESS_STATE).as_ref() } pub fn get_npm_resolution_snapshot(&self) -> Option { if let Some(state) = self.get_npm_process_state() { - return Some(state.snapshot); + // TODO(bartlomieju): remove this clone + return Some(state.snapshot.clone()); } None From 9f08858a01da1f8a6a1dc65bbd978f6ba42205d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 20 Feb 2023 18:16:14 +0100 Subject: [PATCH 60/60] remove a TODO --- cli/args/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index d25313f5a1efb4..7cb2213e92de97 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -63,8 +63,6 @@ use std::sync::Arc; use crate::cache::DenoDir; use crate::file_fetcher::FileFetcher; -// TODO(bartlomieju): refactor this bit; we have a circular dependency -// between this file and `cli/npm/resolver/mod.rs`. use crate::npm::NpmProcessState; use crate::util::fs::canonicalize_path_maybe_not_exists; use crate::version;