From 0ff0be8fb27e3cab3d53a544729f6f7c3277db37 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 18 Dec 2024 20:40:46 -0500 Subject: [PATCH 01/12] refactor: upgrade to deno_semver 0.7 --- Cargo.lock | 74 ++++++++++++++----- Cargo.toml | 13 +++- cli/args/mod.rs | 11 ++- cli/args/package_json.rs | 27 ++++--- cli/graph_util.rs | 2 +- cli/lsp/analysis.rs | 12 ++- cli/lsp/jsr.rs | 23 ++++-- cli/lsp/language_server.rs | 3 +- cli/lsp/search.rs | 4 +- cli/npm/managed/mod.rs | 6 +- cli/npm/managed/resolution.rs | 10 ++- .../managed/resolvers/common/bin_entries.rs | 4 +- cli/npm/managed/resolvers/local.rs | 15 ++-- cli/standalone/serialization.rs | 15 +++- cli/tools/doc.rs | 5 +- cli/tools/info.rs | 19 +++-- cli/tools/installer.rs | 4 +- cli/tools/registry/pm.rs | 33 +++++---- cli/tools/registry/pm/deps.rs | 28 ++++--- cli/tools/registry/pm/outdated.rs | 3 +- cli/tools/task.rs | 10 ++- cli/tools/upgrade.rs | 5 +- cli/tsc/mod.rs | 2 +- cli/worker.rs | 6 +- resolvers/deno/lib.rs | 2 +- resolvers/deno/npm/byonm.rs | 27 +++---- resolvers/deno/npm/mod.rs | 2 +- resolvers/node/resolution.rs | 2 + resolvers/npm_cache/Cargo.toml | 1 + resolvers/npm_cache/lib.rs | 2 +- resolvers/npm_cache/registry_info.rs | 32 +++++++- resolvers/npm_cache/tarball_extract.rs | 2 +- runtime/permissions/lib.rs | 4 +- 33 files changed, 270 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb0617ceee2118..c0bc6ed5a038cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -677,6 +677,24 @@ dependencies = [ "itoa", ] +[[package]] +name = "capacity_builder" +version = "0.4.1" +dependencies = [ + "capacity_builder_macros", + "ecow", + "hipstr", + "itoa", +] + +[[package]] +name = "capacity_builder_macros" +version = "0.2.0" +dependencies = [ + "quote", + "syn 2.0.87", +] + [[package]] name = "caseless" version = "0.2.1" @@ -1224,7 +1242,7 @@ dependencies = [ "boxed_error", "bytes", "cache_control", - "capacity_builder", + "capacity_builder 0.4.1", "chrono", "clap", "clap_complete", @@ -1463,9 +1481,7 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.39.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce717af3fe6788dae63965d58d5637fd62be8fe4f345f189137ffc06c51837d2" +version = "0.40.0" dependencies = [ "anyhow", "deno_package_json", @@ -1504,7 +1520,7 @@ dependencies = [ "bit-set", "bit-vec", "bytes", - "capacity_builder", + "capacity_builder 0.1.3", "cooked-waker", "deno_core_icudata", "deno_ops", @@ -1719,11 +1735,10 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.86.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc78ed0b4bbcb4197300f0d6e7d1edc2d2c5019cdb9dedba7ff229158441885b" dependencies = [ "anyhow", "async-trait", + "capacity_builder 0.4.1", "data-url", "deno_ast", "deno_semver", @@ -1859,8 +1874,6 @@ dependencies = [ [[package]] name = "deno_lockfile" version = "0.23.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559c19feb00af0c34f0bd4a20e56e12463fafd5c5069d6005f3ce33008027eea" dependencies = [ "deno_semver", "serde", @@ -2019,13 +2032,13 @@ dependencies = [ [[package]] name = "deno_npm" version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f125a5dba7839c46394a0a9c835da9fe60f5f412587ab4956a76492a1cc6a8" dependencies = [ - "anyhow", "async-trait", + "capacity_builder 0.4.1", + "deno_error", "deno_lockfile", "deno_semver", + "ecow", "futures", "log", "monch", @@ -2045,6 +2058,7 @@ dependencies = [ "boxed_error", "deno_cache_dir", "deno_core", + "deno_error", "deno_npm", "deno_semver", "deno_unsync", @@ -2083,9 +2097,8 @@ dependencies = [ [[package]] name = "deno_package_json" version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80b0a3d81c592624a1ae15332a04b4dc2b7c163ef1dfc7c60171f736d1babdf5" dependencies = [ + "boxed_error", "deno_error", "deno_path_util", "deno_semver", @@ -2112,7 +2125,7 @@ dependencies = [ name = "deno_permissions" version = "0.43.0" dependencies = [ - "capacity_builder", + "capacity_builder 0.4.1", "deno_core", "deno_path_util", "deno_terminal 0.2.0", @@ -2218,10 +2231,11 @@ dependencies = [ [[package]] name = "deno_semver" version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d1259270d66a5e6d29bb75c9289656541874f79ae9ff6c9f1c790846d5c07ba" dependencies = [ + "capacity_builder 0.4.1", "deno_error", + "ecow", + "hipstr", "monch", "once_cell", "serde", @@ -2888,6 +2902,15 @@ dependencies = [ "spki", ] +[[package]] +name = "ecow" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42fc0a93992b20c58b99e59d61eaf1635a25bfbe49e4275c34ba0aee98119ba" +dependencies = [ + "serde", +] + [[package]] name = "ed25519" version = "2.2.3" @@ -3824,6 +3847,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "hipstr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97971ffc85d4c98de12e2608e992a43f5294ebb625fdb045b27c731b64c4c6d6" +dependencies = [ + "serde", + "serde_bytes", + "sptr", +] + [[package]] name = "hkdf" version = "0.12.4" @@ -6987,6 +7021,12 @@ dependencies = [ "der", ] +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + [[package]] name = "sqlformat" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 55a94b75a0719a..ee90f9c28c012a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ deno_ast = { version = "=0.44.0", features = ["transpiling"] } deno_core = { version = "0.326.0" } deno_bench_util = { version = "0.177.0", path = "./bench_util" } -deno_config = { version = "=0.39.3", features = ["workspace", "sync"] } +deno_config = { version = "=0.40.0", features = ["workspace", "sync"] } deno_lockfile = "=0.23.2" deno_media_type = { version = "0.2.0", features = ["module_specifier"] } deno_npm = "=0.26.0" @@ -108,7 +108,7 @@ boxed_error = "0.2.3" brotli = "6.0.0" bytes = "1.4.0" cache_control = "=0.2.0" -capacity_builder = "0.1.3" +capacity_builder = "0.4.1" cbc = { version = "=0.1.2", features = ["alloc"] } # Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS. # Instead use util::time::utc_now() @@ -341,3 +341,12 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 + +[patch.crates-io] +capacity_builder = { path = "../capacity_builder" } +deno_semver = { path = "../deno_semver" } +deno_npm = { path = "../deno_npm" } +deno_lockfile = { path = "../deno_lockfile" } +deno_package_json = { path = "../deno_package_json" } +deno_config = { path = "../deno_config" } +deno_graph = { path = "../deno_graph" } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f820afe78d4f81..d0ac6ff6b31430 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -31,6 +31,7 @@ use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot; use deno_npm::NpmSystemInfo; use deno_path_util::normalize_path; use deno_semver::npm::NpmPackageReqReference; +use deno_semver::StackString; use deno_telemetry::OtelConfig; use deno_telemetry::OtelRuntimeConfig; use import_map::resolve_import_map_value_from_specifier; @@ -1946,15 +1947,17 @@ pub fn has_flag_env_var(name: &str) -> bool { pub fn npm_pkg_req_ref_to_binary_command( req_ref: &NpmPackageReqReference, ) -> String { - let binary_name = req_ref.sub_path().unwrap_or(req_ref.req().name.as_str()); - binary_name.to_string() + req_ref + .sub_path() + .map(|s| s.to_string()) + .unwrap_or_else(|| req_ref.req().name.to_string()) } pub fn config_to_deno_graph_workspace_member( config: &ConfigFile, ) -> Result { - let name = match &config.json.name { - Some(name) => name.clone(), + let name: StackString = match &config.json.name { + Some(name) => name.as_str().into(), None => bail!("Missing 'name' field in config file."), }; let version = match &config.json.version { diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index b0f0a2f9ba56e9..7bd83911b902a6 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -11,19 +11,20 @@ use deno_package_json::PackageJsonDepValueParseError; use deno_package_json::PackageJsonDepWorkspaceReq; use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageReq; +use deno_semver::StackString; use deno_semver::VersionReq; use thiserror::Error; #[derive(Debug)] pub struct InstallNpmRemotePkg { - pub alias: Option, + pub alias: Option, pub base_dir: PathBuf, pub req: PackageReq, } #[derive(Debug)] pub struct InstallNpmWorkspacePkg { - pub alias: Option, + pub alias: Option, pub target_dir: PathBuf, } @@ -31,7 +32,7 @@ pub struct InstallNpmWorkspacePkg { #[error("Failed to install '{}'\n at {}", alias, location)] pub struct PackageJsonDepValueParseWithLocationError { pub location: Url, - pub alias: String, + pub alias: StackString, #[source] pub source: PackageJsonDepValueParseError, } @@ -100,10 +101,8 @@ impl NpmInstallDepsProvider { let mut pkg_pkgs = Vec::with_capacity( deps.dependencies.len() + deps.dev_dependencies.len(), ); - for (alias, dep) in deps - .dependencies - .into_iter() - .chain(deps.dev_dependencies.into_iter()) + for (alias, dep) in + deps.dependencies.iter().chain(deps.dev_dependencies.iter()) { let dep = match dep { Ok(dep) => dep, @@ -111,8 +110,8 @@ impl NpmInstallDepsProvider { pkg_json_dep_errors.push( PackageJsonDepValueParseWithLocationError { location: pkg_json.specifier(), - alias, - source: err, + alias: alias.clone(), + source: err.clone(), }, ); continue; @@ -128,21 +127,21 @@ impl NpmInstallDepsProvider { if let Some(pkg) = workspace_pkg { workspace_pkgs.push(InstallNpmWorkspacePkg { - alias: Some(alias), + alias: Some(alias.clone()), target_dir: pkg.pkg_json.dir_path().to_path_buf(), }); } else { pkg_pkgs.push(InstallNpmRemotePkg { - alias: Some(alias), + alias: Some(alias.clone()), base_dir: pkg_json.dir_path().to_path_buf(), - req: pkg_req, + req: pkg_req.clone(), }); } } PackageJsonDepValue::Workspace(workspace_version_req) => { let version_req = match workspace_version_req { PackageJsonDepWorkspaceReq::VersionReq(version_req) => { - version_req + version_req.clone() } PackageJsonDepWorkspaceReq::Tilde | PackageJsonDepWorkspaceReq::Caret => { @@ -153,7 +152,7 @@ impl NpmInstallDepsProvider { pkg.matches_name_and_version_req(&alias, &version_req) }) { workspace_pkgs.push(InstallNpmWorkspacePkg { - alias: Some(alias), + alias: Some(alias.clone()), target_dir: pkg.pkg_json.dir_path().to_path_buf(), }); } diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 6abdbe247aabae..b426b99389c2d6 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -680,7 +680,7 @@ impl ModuleGraphBuilder { for (from, to) in graph.packages.mappings() { lockfile.insert_package_specifier( JsrDepPackageReq::jsr(from.clone()), - to.version.to_string(), + to.version.to_string_ecow(), ); } } diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 9f9cf1486417f3..1ce09ff25b5b4c 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -283,14 +283,17 @@ impl<'a> TsResponseImportMapper<'a> { segments.next()?.to_string() }; let version = Version::parse_standard(segments.next()?).ok()?; - let nv = PackageNv { name, version }; + let nv = PackageNv { + name: name.into(), + version, + }; let path = segments.collect::>().join("/"); let export = self.resolver.jsr_lookup_export_for_path( &nv, &path, Some(&self.file_referrer), )?; - let sub_path = (export != ".").then_some(export); + let sub_path = (export != ".").then_some(export).map(|s| s.into()); let mut req = None; req = req.or_else(|| { let import_map = self.maybe_import_map?; @@ -373,7 +376,10 @@ impl<'a> TsResponseImportMapper<'a> { { if pkg_reqs.contains(package_ref.req()) { let sub_path = sub_path.as_deref().unwrap_or(""); - let value_sub_path = package_ref.sub_path().unwrap_or(""); + let value_sub_path = package_ref + .sub_path() + .map(|s| s.as_str()) + .unwrap_or(""); if let Some(key_sub_path) = sub_path.strip_prefix(value_sub_path) { diff --git a/cli/lsp/jsr.rs b/cli/lsp/jsr.rs index 1d012b42f08296..fc30de2ae08a2c 100644 --- a/cli/lsp/jsr.rs +++ b/cli/lsp/jsr.rs @@ -18,6 +18,7 @@ use deno_graph::ModuleSpecifier; use deno_semver::jsr::JsrPackageReqReference; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; +use deno_semver::StackString; use deno_semver::Version; use serde::Deserialize; use std::collections::HashMap; @@ -33,8 +34,8 @@ pub struct JsrCacheResolver { /// The `module_graph` fields of the version infos should be forcibly absent. /// It can be large and we don't want to store it. info_by_nv: DashMap>>, - info_by_name: DashMap>>, - workspace_scope_by_name: HashMap, + info_by_name: DashMap>>, + workspace_scope_by_name: HashMap, cache: Arc, } @@ -59,7 +60,7 @@ impl JsrCacheResolver { continue; }; let nv = PackageNv { - name: jsr_pkg_config.name.clone(), + name: jsr_pkg_config.name.as_str().into(), version: version.clone(), }; info_by_name.insert( @@ -125,8 +126,8 @@ impl JsrCacheResolver { return nv.value().clone(); } let maybe_get_nv = || { - let name = req.name.clone(); - let package_info = self.package_info(&name)?; + let name = &req.name; + let package_info = self.package_info(name)?; // Find the first matching version of the package which is cached. let mut versions = package_info.versions.keys().collect::>(); versions.sort(); @@ -144,7 +145,10 @@ impl JsrCacheResolver { self.package_version_info(&nv).is_some() }) .cloned()?; - Some(PackageNv { name, version }) + Some(PackageNv { + name: name.clone(), + version, + }) }; let nv = maybe_get_nv(); self.nv_by_req.insert(req.clone(), nv.clone()); @@ -216,7 +220,10 @@ impl JsrCacheResolver { None } - pub fn package_info(&self, name: &str) -> Option> { + pub fn package_info( + &self, + name: &StackString, + ) -> Option> { if let Some(info) = self.info_by_name.get(name) { return info.value().clone(); } @@ -226,7 +233,7 @@ impl JsrCacheResolver { serde_json::from_slice::(&meta_bytes).ok() }; let info = read_cached_package_info().map(Arc::new); - self.info_by_name.insert(name.to_string(), info.clone()); + self.info_by_name.insert(name.clone(), info.clone()); info } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 3ffe4491e01bb1..b7fa94179fb19b 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -3781,7 +3781,8 @@ impl Inner { for (name, def) in tasks { result.push(TaskDefinition { name: name.clone(), - command: def.command.clone(), + // todo(https://github.com/denoland/deno/pull/27191): do not unwrap + command: def.command.unwrap().clone(), source_uri: url_to_uri(&config_file.specifier) .map_err(|_| LspError::internal_error())?, }); diff --git a/cli/lsp/search.rs b/cli/lsp/search.rs index 8933eeb186430b..c98acde6f1b4cb 100644 --- a/cli/lsp/search.rs +++ b/cli/lsp/search.rs @@ -67,7 +67,9 @@ pub mod tests { &self, nv: &PackageNv, ) -> Result>, AnyError> { - let Some(exports_by_version) = self.package_versions.get(&nv.name) else { + let Some(exports_by_version) = + self.package_versions.get(nv.name.as_str()) + else { return Err(anyhow!("Package not found.")); }; let Some(exports) = exports_by_version.get(&nv.version) else { diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 4545800e99b61c..5006902aa1de20 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -560,11 +560,11 @@ impl ManagedCliNpmResolver { &self, ) -> Result<(), Box> { for err in self.npm_install_deps_provider.pkg_json_dep_errors() { - match &err.source { - deno_package_json::PackageJsonDepValueParseError::VersionReq(_) => { + match err.source.as_kind() { + deno_package_json::PackageJsonDepValueParseErrorKind::VersionReq(_) => { return Err(Box::new(err.clone())); } - deno_package_json::PackageJsonDepValueParseError::Unsupported { + deno_package_json::PackageJsonDepValueParseErrorKind::Unsupported { .. } => { // only warn for this one diff --git a/cli/npm/managed/resolution.rs b/cli/npm/managed/resolution.rs index 73c5c31cafd1db..8c8abf72399cc0 100644 --- a/cli/npm/managed/resolution.rs +++ b/cli/npm/managed/resolution.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use std::collections::HashSet; use std::sync::Arc; +use capacity_builder::StringBuilder; use deno_core::error::AnyError; use deno_lockfile::NpmPackageDependencyLockfileInfo; use deno_lockfile::NpmPackageLockfileInfo; @@ -24,6 +25,7 @@ use deno_npm::NpmSystemInfo; use deno_semver::jsr::JsrDepPackageReq; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; +use deno_semver::SmallStackString; use deno_semver::VersionReq; use crate::args::CliLockfile; @@ -336,7 +338,13 @@ fn populate_lockfile_from_snapshot( let id = &snapshot.resolve_package_from_deno_module(nv).unwrap().id; lockfile.insert_package_specifier( JsrDepPackageReq::npm(package_req.clone()), - format!("{}{}", id.nv.version, id.peer_deps_serialized()), + { + StringBuilder::::build(|builder| { + builder.append(&id.nv.name); + builder.append(&id.peer_dependencies); + }) + .unwrap() + }, ); } for package in snapshot.all_packages_for_every_system() { diff --git a/cli/npm/managed/resolvers/common/bin_entries.rs b/cli/npm/managed/resolvers/common/bin_entries.rs index e4a1845689c155..ca47b9a08696a5 100644 --- a/cli/npm/managed/resolvers/common/bin_entries.rs +++ b/cli/npm/managed/resolvers/common/bin_entries.rs @@ -28,8 +28,10 @@ fn default_bin_name(package: &NpmResolutionPackage) -> &str { .id .nv .name + .as_str() .rsplit_once('/') - .map_or(package.id.nv.name.as_str(), |(_, name)| name) + .map(|(_, name)| name) + .unwrap_or(package.id.nv.name.as_str()) } pub fn warn_missing_entrypoint( diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index 1e83717f15a660..c340d10d5df766 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -38,6 +38,7 @@ use deno_resolver::npm::normalize_pkg_name_for_node_modules_deno_folder; use deno_runtime::deno_fs; use deno_runtime::deno_node::NodePermissions; use deno_semver::package::PackageNv; +use deno_semver::StackString; use node_resolver::errors::PackageFolderResolveError; use node_resolver::errors::PackageFolderResolveIoError; use node_resolver::errors::PackageNotFoundError; @@ -355,8 +356,10 @@ async fn sync_resolution_with_fs( let package_partitions = snapshot.all_system_packages_partitioned(system_info); let mut cache_futures = FuturesUnordered::new(); - let mut newest_packages_by_name: HashMap<&String, &NpmResolutionPackage> = - HashMap::with_capacity(package_partitions.packages.len()); + let mut newest_packages_by_name: HashMap< + &StackString, + &NpmResolutionPackage, + > = HashMap::with_capacity(package_partitions.packages.len()); let bin_entries = Rc::new(RefCell::new(bin_entries::BinEntries::new())); let mut lifecycle_scripts = super::common::lifecycle_scripts::LifecycleScripts::new( @@ -536,7 +539,7 @@ async fn sync_resolution_with_fs( } } - let mut found_names: HashMap<&String, &PackageNv> = HashMap::new(); + let mut found_names: HashMap<&StackString, &PackageNv> = HashMap::new(); // set of node_modules in workspace packages that we've already ensured exist let mut existing_child_node_modules_dirs: HashSet = HashSet::new(); @@ -1012,10 +1015,10 @@ fn get_package_folder_id_from_folder_name( ) -> Option { let folder_name = folder_name.replace('+', "/"); let (name, ending) = folder_name.rsplit_once('@')?; - let name = if let Some(encoded_name) = name.strip_prefix('_') { - mixed_case_package_name_decode(encoded_name)? + let name: StackString = if let Some(encoded_name) = name.strip_prefix('_') { + mixed_case_package_name_decode(encoded_name)?.into() } else { - name.to_string() + name.into() }; let (raw_version, copy_index) = match ending.split_once('_') { Some((raw_version, copy_index)) => { diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index ac76172e37776c..5e75995298c6e4 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -6,6 +6,7 @@ use std::collections::BTreeMap; use std::collections::HashMap; use std::io::Write; +use capacity_builder::BytesAppendable; use deno_ast::MediaType; use deno_core::anyhow::bail; use deno_core::anyhow::Context; @@ -20,6 +21,7 @@ use deno_npm::resolution::SerializedNpmResolutionSnapshotPackage; use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot; use deno_npm::NpmPackageId; use deno_semver::package::PackageReq; +use deno_semver::StackString; use crate::standalone::virtual_fs::VirtualDirectory; @@ -188,7 +190,10 @@ impl RemoteModulesStoreBuilder { } } - fn write<'a>(&'a self, builder: &mut capacity_builder::BytesBuilder<'a>) { + fn write<'a, TBytes: capacity_builder::BytesType>( + &'a self, + builder: &mut capacity_builder::BytesBuilder<'a, TBytes>, + ) { builder.append_le(self.specifiers.len() as u32); builder.append_le(self.redirects.len() as u32); for (specifier, offset) in &self.specifiers { @@ -475,12 +480,16 @@ fn deserialize_npm_snapshot( #[allow(clippy::needless_lifetimes)] // clippy bug fn parse_package_dep<'a>( id_to_npm_id: &'a impl Fn(usize) -> Result, - ) -> impl Fn(&[u8]) -> Result<(&[u8], (String, NpmPackageId)), AnyError> + 'a + ) -> impl Fn(&[u8]) -> Result<(&[u8], (StackString, NpmPackageId)), AnyError> + 'a { |input| { let (input, req) = read_string_lossy(input)?; let (input, id) = read_u32_as_usize(input)?; - Ok((input, (req.into_owned(), id_to_npm_id(id)?))) + let req = match req { + Cow::Borrowed(req) => StackString::from(req), + Cow::Owned(req) => StackString::from(req), + }; + Ok((input, (req, id_to_npm_id(id)?))) } } diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 647a36dc480321..bd54d9621bd632 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -28,6 +28,7 @@ use deno_graph::EsParser; use deno_graph::GraphKind; use deno_graph::ModuleAnalyzer; use deno_graph::ModuleSpecifier; +use deno_semver::StackString; use doc::html::ShortPath; use doc::DocDiagnostic; use indexmap::IndexMap; @@ -343,14 +344,14 @@ impl deno_doc::html::HrefResolver for DocResolver { let name = &res.req().name; Some(( format!("https://www.npmjs.com/package/{name}"), - name.to_owned(), + name.to_string(), )) } "jsr" => { let res = deno_semver::jsr::JsrPackageReqReference::from_str(module).ok()?; let name = &res.req().name; - Some((format!("https://jsr.io/{name}"), name.to_owned())) + Some((format!("https://jsr.io/{name}"), name.to_string())) } _ => None, } diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 7a35f597c37038..3851bb1b7f8eaa 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -278,8 +278,10 @@ fn add_npm_packages_to_json( }); if let Some(pkg) = maybe_package { if let Some(module) = module.as_object_mut() { - module - .insert("npmPackage".to_string(), pkg.id.as_serialized().into()); + module.insert( + "npmPackage".to_string(), + pkg.id.as_serialized().to_string().into(), + ); } } } @@ -296,7 +298,7 @@ fn add_npm_packages_to_json( { dep.insert( "npmPackage".to_string(), - pkg.id.as_serialized().into(), + pkg.id.as_serialized().to_string().into(), ); } } @@ -324,19 +326,19 @@ fn add_npm_packages_to_json( let mut json_packages = serde_json::Map::with_capacity(sorted_packages.len()); for pkg in sorted_packages { let mut kv = serde_json::Map::new(); - kv.insert("name".to_string(), pkg.id.nv.name.clone().into()); + kv.insert("name".to_string(), pkg.id.nv.name.to_string().into()); kv.insert("version".to_string(), pkg.id.nv.version.to_string().into()); let mut deps = pkg.dependencies.values().collect::>(); deps.sort(); let deps = deps .into_iter() - .map(|id| serde_json::Value::String(id.as_serialized())) + .map(|id| serde_json::Value::String(id.as_serialized().to_string())) .collect::>(); kv.insert("dependencies".to_string(), deps.into()); let registry_url = npmrc.get_registry_url(&pkg.id.nv.name); kv.insert("registryUrl".to_string(), registry_url.to_string().into()); - json_packages.insert(pkg.id.as_serialized(), kv.into()); + json_packages.insert(pkg.id.as_serialized().to_string(), kv.into()); } json.insert("npmPackages".to_string(), json_packages.into()); @@ -549,7 +551,7 @@ impl<'a> GraphDisplayContext<'a> { None => Specifier(module.specifier().clone()), }; let was_seen = !self.seen.insert(match &package_or_specifier { - Package(package) => package.id.as_serialized(), + Package(package) => package.id.as_serialized().to_string(), Specifier(specifier) => specifier.to_string(), }); let header_text = if was_seen { @@ -631,7 +633,8 @@ impl<'a> GraphDisplayContext<'a> { )); if let Some(package) = self.npm_info.packages.get(dep_id) { if !package.dependencies.is_empty() { - let was_seen = !self.seen.insert(package.id.as_serialized()); + let was_seen = + !self.seen.insert(package.id.as_serialized().to_string()); if was_seen { child.text = format!("{} {}", child.text, colors::gray("*")); } else { diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index dac7340d402953..9c3c06e4977f36 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -161,11 +161,11 @@ pub async fn infer_name_from_url( let npm_ref = npm_ref.into_inner(); if let Some(sub_path) = npm_ref.sub_path { if !sub_path.contains('/') { - return Some(sub_path); + return Some(sub_path.into()); } } if !npm_ref.req.name.contains('/') { - return Some(npm_ref.req.name); + return Some(npm_ref.req.name.into()); } return None; } diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 791e54c67caa32..505f8caf99747b 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -15,6 +15,7 @@ use deno_semver::jsr::JsrPackageReqReference; use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; +use deno_semver::StackString; use deno_semver::Version; use deno_semver::VersionReq; use deps::KeyPath; @@ -283,7 +284,7 @@ fn package_json_dependency_entry( (npm_package.into(), selected.version_req) } else { ( - selected.import_name, + selected.import_name.to_string(), format!("npm:{}@{}", npm_package, selected.version_req), ) } @@ -292,7 +293,7 @@ fn package_json_dependency_entry( let scope_replaced = jsr_package.replace('/', "__"); let version_req = format!("npm:@jsr/{scope_replaced}@{}", selected.version_req); - (selected.import_name, version_req) + (selected.import_name.to_string(), version_req) } else { (selected.package_name, selected.version_req) } @@ -549,10 +550,10 @@ pub async fn add( } struct SelectedPackage { - import_name: String, + import_name: StackString, package_name: String, version_req: String, - selected_version: String, + selected_version: StackString, } enum NotFoundHelp { @@ -683,7 +684,7 @@ async fn find_package_and_select_version_for_req( import_name: add_package_req.alias, package_name: prefixed_name, version_req: format!("{}{}", range_symbol, &nv.version), - selected_version: nv.version.to_string(), + selected_version: nv.version.to_string_hipstr(), })) } @@ -705,7 +706,7 @@ enum AddRmPackageReqValue { #[derive(Debug, PartialEq, Eq)] pub struct AddRmPackageReq { - alias: String, + alias: StackString, value: AddRmPackageReqValue, } @@ -753,7 +754,11 @@ impl AddRmPackageReq { return Ok(Err(PackageReq::from_str(entry_text)?)); } - (maybe_prefix.unwrap(), Some(alias.to_string()), entry_text) + ( + maybe_prefix.unwrap(), + Some(StackString::from(alias)), + entry_text, + ) } None => return Ok(Err(PackageReq::from_str(entry_text)?)), }, @@ -765,7 +770,7 @@ impl AddRmPackageReq { JsrPackageReqReference::from_str(&format!("jsr:{}", entry_text))?; let package_req = req_ref.into_inner().req; Ok(Ok(AddRmPackageReq { - alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()), + alias: maybe_alias.unwrap_or_else(|| package_req.name.clone()), value: AddRmPackageReqValue::Jsr(package_req), })) } @@ -785,7 +790,7 @@ impl AddRmPackageReq { ); } Ok(Ok(AddRmPackageReq { - alias: maybe_alias.unwrap_or_else(|| package_req.name.to_string()), + alias: maybe_alias.unwrap_or_else(|| package_req.name.clone()), value: AddRmPackageReqValue::Npm(package_req), })) } @@ -878,14 +883,14 @@ mod test { assert_eq!( AddRmPackageReq::parse("jsr:foo").unwrap().unwrap(), AddRmPackageReq { - alias: "foo".to_string(), + alias: "foo".into(), value: AddRmPackageReqValue::Jsr(PackageReq::from_str("foo").unwrap()) } ); assert_eq!( AddRmPackageReq::parse("alias@jsr:foo").unwrap().unwrap(), AddRmPackageReq { - alias: "alias".to_string(), + alias: "alias".into(), value: AddRmPackageReqValue::Jsr(PackageReq::from_str("foo").unwrap()) } ); @@ -894,7 +899,7 @@ mod test { .unwrap() .unwrap(), AddRmPackageReq { - alias: "@alias/pkg".to_string(), + alias: "@alias/pkg".into(), value: AddRmPackageReqValue::Npm( PackageReq::from_str("foo@latest").unwrap() ) @@ -905,7 +910,7 @@ mod test { .unwrap() .unwrap(), AddRmPackageReq { - alias: "@alias/pkg".to_string(), + alias: "@alias/pkg".into(), value: AddRmPackageReqValue::Jsr(PackageReq::from_str("foo").unwrap()) } ); @@ -914,7 +919,7 @@ mod test { .unwrap() .unwrap(), AddRmPackageReq { - alias: "alias".to_string(), + alias: "alias".into(), value: AddRmPackageReqValue::Jsr( PackageReq::from_str("foo@^1.5.0").unwrap() ) diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs index bb03e97f2dcd26..3ec06fae32821a 100644 --- a/cli/tools/registry/pm/deps.rs +++ b/cli/tools/registry/pm/deps.rs @@ -27,6 +27,7 @@ use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; use deno_semver::package::PackageReqReference; +use deno_semver::StackString; use deno_semver::Version; use deno_semver::VersionReq; use import_map::ImportMap; @@ -139,13 +140,7 @@ pub enum KeyPart { Scopes, Dependencies, DevDependencies, - String(String), -} - -impl From for KeyPart { - fn from(value: String) -> Self { - KeyPart::String(value) - } + String(StackString), } impl From for KeyPart { @@ -164,7 +159,7 @@ impl KeyPart { KeyPart::Scopes => "scopes", KeyPart::Dependencies => "dependencies", KeyPart::DevDependencies => "devDependencies", - KeyPart::String(s) => s, + KeyPart::String(s) => s.as_str(), } } } @@ -217,12 +212,12 @@ fn import_map_entries( .chain(import_map.scopes().flat_map(|scope| { let path = KeyPath::from_parts([ KeyPart::Scopes, - scope.raw_key.to_string().into(), + KeyPart::String(scope.raw_key.into()), ]); scope.imports.entries().map(move |entry| { let mut full_path = path.clone(); - full_path.push(KeyPart::String(entry.raw_key.to_string())); + full_path.push(KeyPart::String(entry.raw_key.into())); (full_path, entry) }) })) @@ -338,7 +333,7 @@ fn add_deps_from_package_json( package_json: &PackageJsonRc, mut filter: impl DepFilter, package_dep_kind: PackageJsonDepKind, - package_json_deps: PackageJsonDepsMap, + package_json_deps: &PackageJsonDepsMap, deps: &mut Vec, ) { for (k, v) in package_json_deps { @@ -362,9 +357,12 @@ fn add_deps_from_package_json( kind: DepKind::Npm, location: DepLocation::PackageJson( package_json.clone(), - KeyPath::from_parts([package_dep_kind.into(), k.into()]), + KeyPath::from_parts([ + package_dep_kind.into(), + KeyPart::String(k.clone()), + ]), ), - req, + req: req.clone(), alias, }) } @@ -377,14 +375,14 @@ fn add_deps_from_package_json( package_json, filter, PackageJsonDepKind::Normal, - package_json_deps.dependencies, + &package_json_deps.dependencies, deps, ); iterate( package_json, filter, PackageJsonDepKind::Dev, - package_json_deps.dev_dependencies, + &package_json_deps.dev_dependencies, deps, ); } diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs index f767eb15228a9b..20a6043f26560b 100644 --- a/cli/tools/registry/pm/outdated.rs +++ b/cli/tools/registry/pm/outdated.rs @@ -8,6 +8,7 @@ use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; +use deno_semver::StackString; use deno_semver::VersionReq; use deno_terminal::colors; @@ -31,7 +32,7 @@ struct OutdatedPackage { latest: String, semver_compatible: String, current: String, - name: String, + name: StackString, } #[allow(clippy::print_stdout)] diff --git a/cli/tools/task.rs b/cli/tools/task.rs index ec9b238847caf8..f389ddb5ab9224 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -231,7 +231,7 @@ pub async fn execute_script( &Url::from_directory_path(cli_options.initial_cwd()).unwrap(), "", &TaskDefinition { - command: task_flags.task.as_ref().unwrap().to_string(), + command: Some(task_flags.task.as_ref().unwrap().to_string()), dependencies: vec![], description: None, }, @@ -469,7 +469,8 @@ impl<'a> TaskRunner<'a> { self .run_single(RunSingleOptions { task_name, - script: &definition.command, + // todo(https://github.com/denoland/deno/pull/27191): do not unwrap + script: definition.command.as_ref().unwrap(), cwd: &cwd, custom_commands, kill_signal, @@ -837,7 +838,7 @@ fn print_available_tasks( is_deno: false, name: name.to_string(), task: deno_config::deno_json::TaskDefinition { - command: script.to_string(), + command: Some(script.to_string()), dependencies: vec![], description: None, }, @@ -876,7 +877,8 @@ fn print_available_tasks( writeln!( writer, " {}", - strip_ansi_codes_and_escape_control_chars(&desc.task.command) + // todo(https://github.com/denoland/deno/pull/27191): update this + strip_ansi_codes_and_escape_control_chars(&desc.task.command.unwrap()), )?; if !desc.task.dependencies.is_empty() { let dependencies = desc diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index cb85859f7ab2bd..b198bea5ef97fa 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -21,6 +21,7 @@ use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::unsync::spawn; use deno_core::url::Url; +use deno_semver::SmallStackString; use deno_semver::Version; use once_cell::sync::Lazy; use std::borrow::Cow; @@ -255,7 +256,7 @@ async fn print_release_notes( let is_deno_2_rc = new_semver.major == 2 && new_semver.minor == 0 && new_semver.patch == 0 - && new_semver.pre.first() == Some(&"rc".to_string()); + && new_semver.pre.first().map(|s| s.as_str()) == Some("rc"); if is_deno_2_rc || is_switching_from_deno1_to_deno2 { log::info!( @@ -674,7 +675,7 @@ impl RequestedVersion { ); }; - if semver.pre.contains(&"rc".to_string()) { + if semver.pre.contains(&SmallStackString::from("rc")) { (ReleaseChannel::Rc, passed_version) } else { (ReleaseChannel::Stable, passed_version) diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 4c18d1a2b0b23f..b2cd279016d4ca 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -983,7 +983,7 @@ fn resolve_non_graph_specifier_types( .resolve_pkg_folder_from_deno_module_req(npm_req_ref.req(), referrer)?; let res_result = node_resolver.resolve_package_subpath_from_deno_module( &package_folder, - npm_req_ref.sub_path(), + npm_req_ref.sub_path().map(|s| s.as_str()), Some(referrer), resolution_mode, NodeResolutionKind::Types, diff --git a/cli/worker.rs b/cli/worker.rs index 0bbc27b29ff28b..7fc4104e076011 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -518,8 +518,10 @@ impl CliMainWorkerFactory { package_ref.req(), &referrer, )?; - let main_module = self - .resolve_binary_entrypoint(&package_folder, package_ref.sub_path())?; + let main_module = self.resolve_binary_entrypoint( + &package_folder, + package_ref.sub_path().map(|p| p.as_str()), + )?; if let Some(lockfile) = &shared.maybe_lockfile { // For npm binary commands, ensure that the lockfile gets updated diff --git a/resolvers/deno/lib.rs b/resolvers/deno/lib.rs index 05fa416da1b7e4..9038284c6bbf17 100644 --- a/resolvers/deno/lib.rs +++ b/resolvers/deno/lib.rs @@ -329,7 +329,7 @@ impl< return node_resolver .resolve_package_subpath_from_deno_module( pkg_folder, - npm_req_ref.sub_path(), + npm_req_ref.sub_path().map(|v| v.as_str()), Some(referrer), resolution_mode, resolution_kind, diff --git a/resolvers/deno/npm/byonm.rs b/resolvers/deno/npm/byonm.rs index 08d06f9cac14ab..36f08a74f417f6 100644 --- a/resolvers/deno/npm/byonm.rs +++ b/resolvers/deno/npm/byonm.rs @@ -9,6 +9,7 @@ use deno_package_json::PackageJsonDepValue; use deno_package_json::PackageJsonRc; use deno_path_util::url_to_file_path; use deno_semver::package::PackageReq; +use deno_semver::StackString; use deno_semver::Version; use node_resolver::env::NodeResolverEnv; use node_resolver::errors::PackageFolderResolveError; @@ -30,7 +31,7 @@ use super::ResolvePkgFolderFromDenoReqError; #[derive(Debug, Error)] pub enum ByonmResolvePkgFolderFromDenoReqError { #[error("Could not find \"{}\" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `deno install`?", .0)] - MissingAlias(String), + MissingAlias(StackString), #[error(transparent)] PackageJson(#[from] PackageJsonLoadError), #[error("Could not find a matching package for 'npm:{}' in the node_modules directory. Ensure you have all your JSR and npm dependencies listed in your deno.json or package.json, then run `deno install`. Alternatively, turn on auto-install by specifying `\"nodeModulesDir\": \"auto\"` in your deno.json file.", .0)] @@ -177,16 +178,14 @@ impl ByonmNpmResolver { &self, req: &PackageReq, referrer: &Url, - ) -> Result, PackageJsonLoadError> { - fn resolve_alias_from_pkg_json( + ) -> Result, PackageJsonLoadError> { + fn resolve_alias_from_pkg_json<'a>( req: &PackageReq, - pkg_json: &PackageJson, - ) -> Option { + pkg_json: &'a PackageJson, + ) -> Option { let deps = pkg_json.resolve_local_package_json_deps(); - for (key, value) in deps - .dependencies - .into_iter() - .chain(deps.dev_dependencies.into_iter()) + for (key, value) in + deps.dependencies.iter().chain(deps.dev_dependencies.iter()) { if let Ok(value) = value { match value { @@ -194,12 +193,14 @@ impl ByonmNpmResolver { if dep_req.name == req.name && dep_req.version_req.intersects(&req.version_req) { - return Some(key); + return Some(key.clone()); } } PackageJsonDepValue::Workspace(_workspace) => { - if key == req.name && req.version_req.tag() == Some("workspace") { - return Some(key); + if key.as_str() == req.name + && req.version_req.tag() == Some("workspace") + { + return Some(key.clone()); } } } @@ -246,7 +247,7 @@ impl ByonmNpmResolver { if let Ok(Some(dep_pkg_json)) = self.load_pkg_json(&pkg_folder.join("package.json")) { - if dep_pkg_json.name.as_ref() == Some(&req.name) { + if dep_pkg_json.name.as_deref() == Some(req.name.as_str()) { let matches_req = dep_pkg_json .version .as_ref() diff --git a/resolvers/deno/npm/mod.rs b/resolvers/deno/npm/mod.rs index 64ec86fe3f6615..fc41a93f78a5ca 100644 --- a/resolvers/deno/npm/mod.rs +++ b/resolvers/deno/npm/mod.rs @@ -144,7 +144,7 @@ impl ) -> Result { self.resolve_req_with_sub_path( req_ref.req(), - req_ref.sub_path(), + req_ref.sub_path().map(|s| s.as_str()), referrer, resolution_mode, resolution_kind, diff --git a/resolvers/node/resolution.rs b/resolvers/node/resolution.rs index 5f87698cd6eeaf..6b0bda57d7fde8 100644 --- a/resolvers/node/resolution.rs +++ b/resolvers/node/resolution.rs @@ -318,6 +318,8 @@ impl NodeResolver { resolution_mode: ResolutionMode, resolution_kind: NodeResolutionKind, ) -> Result { + // todo(dsherret): don't allocate a string here (maybe use an + // enum that says the subpath is not prefixed with a ./) let package_subpath = package_subpath .map(|s| format!("./{s}")) .unwrap_or_else(|| ".".to_string()); diff --git a/resolvers/npm_cache/Cargo.toml b/resolvers/npm_cache/Cargo.toml index a0a106c89b68ad..010f8a436b4b87 100644 --- a/resolvers/npm_cache/Cargo.toml +++ b/resolvers/npm_cache/Cargo.toml @@ -23,6 +23,7 @@ async-trait.workspace = true base64.workspace = true boxed_error.workspace = true deno_cache_dir.workspace = true +deno_error.workspace = true deno_npm.workspace = true deno_semver.workspace = true deno_unsync = { workspace = true, features = ["tokio"] } diff --git a/resolvers/npm_cache/lib.rs b/resolvers/npm_cache/lib.rs index c16c29aaf2b397..dc135d729ef393 100644 --- a/resolvers/npm_cache/lib.rs +++ b/resolvers/npm_cache/lib.rs @@ -260,7 +260,7 @@ impl NpmCache { .and_then(|cache_id| { Some(NpmPackageCacheFolderId { nv: PackageNv { - name: cache_id.name, + name: cache_id.name.into(), version: Version::parse_from_npm(&cache_id.version).ok()?, }, copy_index: cache_id.copy_index, diff --git a/resolvers/npm_cache/registry_info.rs b/resolvers/npm_cache/registry_info.rs index 543ddadc5afdcd..dd8a6395910f16 100644 --- a/resolvers/npm_cache/registry_info.rs +++ b/resolvers/npm_cache/registry_info.rs @@ -18,6 +18,7 @@ use deno_unsync::sync::MultiRuntimeAsyncValueCreator; use futures::future::LocalBoxFuture; use futures::FutureExt; use parking_lot::Mutex; +use thiserror::Error; use url::Url; use crate::remote::maybe_auth_header_for_npm_registry; @@ -28,6 +29,31 @@ use crate::NpmCacheSetting; type LoadResult = Result>; type LoadFuture = LocalBoxFuture<'static, LoadResult>; +#[derive(Debug, Error)] +#[error(transparent)] +pub struct AnyhowJsError(pub AnyError); + +impl deno_error::JsErrorClass for AnyhowJsError { + fn get_class(&self) -> &'static str { + "generic" + } + + fn get_message(&self) -> std::borrow::Cow<'static, str> { + self.0.to_string().into() + } + + fn get_additional_properties( + &self, + ) -> Option< + Vec<( + std::borrow::Cow<'static, str>, + std::borrow::Cow<'static, str>, + )>, + > { + None + } +} + #[derive(Debug, Clone)] enum FutureResult { PackageNotExists, @@ -157,9 +183,9 @@ impl RegistryInfoProvider { Ok(None) => Err(NpmRegistryPackageInfoLoadError::PackageNotExists { package_name: name.to_string(), }), - Err(err) => { - Err(NpmRegistryPackageInfoLoadError::LoadError(Arc::new(err))) - } + Err(err) => Err(NpmRegistryPackageInfoLoadError::LoadError(Arc::new( + AnyhowJsError(err), + ))), } } diff --git a/resolvers/npm_cache/tarball_extract.rs b/resolvers/npm_cache/tarball_extract.rs index c4c614b35fdb34..affe93eaa498ef 100644 --- a/resolvers/npm_cache/tarball_extract.rs +++ b/resolvers/npm_cache/tarball_extract.rs @@ -236,7 +236,7 @@ mod test { #[test] pub fn test_verify_tarball() { let package = PackageNv { - name: "package".to_string(), + name: "package".into(), version: Version::parse_from_npm("1.0.0").unwrap(), }; let actual_checksum = diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index bbd0301db4545e..1c5fb36f930fa8 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -183,7 +183,7 @@ impl PermissionState { PermissionState::Prompt if prompt => { let msg = { let info = info(); - StringBuilder::build(|builder| { + StringBuilder::::build(|builder| { builder.append(name); builder.append(" access"); if let Some(info) = &info { @@ -498,7 +498,7 @@ impl UnaryPermission { } let maybe_formatted_display_name = desc.map(|d| format_display_name(d.display_name())); - let message = StringBuilder::build(|builder| { + let message = StringBuilder::::build(|builder| { builder.append(TQuery::flag_name()); builder.append(" access"); if let Some(display_name) = &maybe_formatted_display_name { From 6392305b81d35e52ea4862a83458d336f1824691 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 18 Dec 2024 20:50:32 -0500 Subject: [PATCH 02/12] update to git --- Cargo.lock | 24 +++++++++++++++++------- Cargo.toml | 15 +++++++-------- cli/tools/doc.rs | 1 - 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0bc6ed5a038cc..7922ea867a1ec7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -679,7 +679,9 @@ dependencies = [ [[package]] name = "capacity_builder" -version = "0.4.1" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ced42635df19d69e4296203f3d09edf81993fc33f70d1dd9a53e9659964a1ad" dependencies = [ "capacity_builder_macros", "ecow", @@ -689,7 +691,9 @@ dependencies = [ [[package]] name = "capacity_builder_macros" -version = "0.2.0" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2883cccc7b2ed65fb29c1141063b0c544be562aed530bac4f4ada2f163c7618d" dependencies = [ "quote", "syn 2.0.87", @@ -1242,7 +1246,7 @@ dependencies = [ "boxed_error", "bytes", "cache_control", - "capacity_builder 0.4.1", + "capacity_builder 0.4.2", "chrono", "clap", "clap_complete", @@ -1482,6 +1486,7 @@ dependencies = [ [[package]] name = "deno_config" version = "0.40.0" +source = "git+https://github.com/dsherret/deno_config.git?branch=refactor_deno_semver_0_7#1e0e40edc2d7f7bf37266740d90d5bc8c3f5dd63" dependencies = [ "anyhow", "deno_package_json", @@ -1735,10 +1740,11 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.86.3" +source = "git+https://github.com/dsherret/deno_graph.git?branch=refactor_deno_semver_0_7#20e0e943327790637dd59f54a7a6b7960ed76a14" dependencies = [ "anyhow", "async-trait", - "capacity_builder 0.4.1", + "capacity_builder 0.4.2", "data-url", "deno_ast", "deno_semver", @@ -1874,6 +1880,7 @@ dependencies = [ [[package]] name = "deno_lockfile" version = "0.23.2" +source = "git+https://github.com/dsherret/deno_lockfile.git?branch=deno_semver_0_7#2f4d4bef5141c73591c68b578433ddbb8b1442ef" dependencies = [ "deno_semver", "serde", @@ -2032,9 +2039,10 @@ dependencies = [ [[package]] name = "deno_npm" version = "0.26.0" +source = "git+https://github.com/dsherret/deno_npm.git?branch=refactor_deno_semver_0_7#e75af8a5fc919f17811afefb8c03086695e42cb4" dependencies = [ "async-trait", - "capacity_builder 0.4.1", + "capacity_builder 0.4.2", "deno_error", "deno_lockfile", "deno_semver", @@ -2097,6 +2105,7 @@ dependencies = [ [[package]] name = "deno_package_json" version = "0.2.1" +source = "git+https://github.com/dsherret/deno_package_json.git?branch=refactor_deno_semver_0_7#93b8f486ffffa8b0846e5aced09c45324150b1d1" dependencies = [ "boxed_error", "deno_error", @@ -2125,7 +2134,7 @@ dependencies = [ name = "deno_permissions" version = "0.43.0" dependencies = [ - "capacity_builder 0.4.1", + "capacity_builder 0.4.2", "deno_core", "deno_path_util", "deno_terminal 0.2.0", @@ -2231,8 +2240,9 @@ dependencies = [ [[package]] name = "deno_semver" version = "0.6.1" +source = "git+https://github.com/dsherret/deno_semver.git?branch=perf_stack_strings#d5a325428693cac86b033c712c54aa172b677df1" dependencies = [ - "capacity_builder 0.4.1", + "capacity_builder 0.4.2", "deno_error", "ecow", "hipstr", diff --git a/Cargo.toml b/Cargo.toml index ee90f9c28c012a..5894b4f69fe1d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ boxed_error = "0.2.3" brotli = "6.0.0" bytes = "1.4.0" cache_control = "=0.2.0" -capacity_builder = "0.4.1" +capacity_builder = "0.4.2" cbc = { version = "=0.1.2", features = ["alloc"] } # Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS. # Instead use util::time::utc_now() @@ -343,10 +343,9 @@ opt-level = 3 opt-level = 3 [patch.crates-io] -capacity_builder = { path = "../capacity_builder" } -deno_semver = { path = "../deno_semver" } -deno_npm = { path = "../deno_npm" } -deno_lockfile = { path = "../deno_lockfile" } -deno_package_json = { path = "../deno_package_json" } -deno_config = { path = "../deno_config" } -deno_graph = { path = "../deno_graph" } +deno_semver = { git = "https://github.com/dsherret/deno_semver.git", branch = "perf_stack_strings" } +deno_package_json = { git = "https://github.com/dsherret/deno_package_json.git", branch = "refactor_deno_semver_0_7" } +deno_lockfile = { git = "https://github.com/dsherret/deno_lockfile.git", branch = "deno_semver_0_7" } +deno_config = { git = "https://github.com/dsherret/deno_config.git", branch = "refactor_deno_semver_0_7" } +deno_npm = { git = "https://github.com/dsherret/deno_npm.git", branch = "refactor_deno_semver_0_7" } +deno_graph = { git = "https://github.com/dsherret/deno_graph.git", branch = "refactor_deno_semver_0_7" } diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index bd54d9621bd632..90d54f6cd96e28 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -28,7 +28,6 @@ use deno_graph::EsParser; use deno_graph::GraphKind; use deno_graph::ModuleAnalyzer; use deno_graph::ModuleSpecifier; -use deno_semver::StackString; use doc::html::ShortPath; use doc::DocDiagnostic; use indexmap::IndexMap; From e58333a02acb2f7bc3779577a853ec54fb338980 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 19 Dec 2024 11:45:12 -0500 Subject: [PATCH 03/12] update to custom string type --- Cargo.lock | 10 ---------- Cargo.toml | 19 +++++++++++++------ cli/graph_util.rs | 3 ++- cli/lsp/analysis.rs | 22 +++++++++++++++------- cli/npm/managed/resolvers/local.rs | 2 +- cli/standalone/serialization.rs | 5 +---- cli/tools/installer.rs | 4 ++-- cli/tools/registry/pm.rs | 2 +- resolvers/npm_cache/lib.rs | 3 ++- 9 files changed, 37 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7922ea867a1ec7..a95f9ca9de7f19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -680,8 +680,6 @@ dependencies = [ [[package]] name = "capacity_builder" version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ced42635df19d69e4296203f3d09edf81993fc33f70d1dd9a53e9659964a1ad" dependencies = [ "capacity_builder_macros", "ecow", @@ -692,8 +690,6 @@ dependencies = [ [[package]] name = "capacity_builder_macros" version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2883cccc7b2ed65fb29c1141063b0c544be562aed530bac4f4ada2f163c7618d" dependencies = [ "quote", "syn 2.0.87", @@ -1486,7 +1482,6 @@ dependencies = [ [[package]] name = "deno_config" version = "0.40.0" -source = "git+https://github.com/dsherret/deno_config.git?branch=refactor_deno_semver_0_7#1e0e40edc2d7f7bf37266740d90d5bc8c3f5dd63" dependencies = [ "anyhow", "deno_package_json", @@ -1740,7 +1735,6 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.86.3" -source = "git+https://github.com/dsherret/deno_graph.git?branch=refactor_deno_semver_0_7#20e0e943327790637dd59f54a7a6b7960ed76a14" dependencies = [ "anyhow", "async-trait", @@ -1880,7 +1874,6 @@ dependencies = [ [[package]] name = "deno_lockfile" version = "0.23.2" -source = "git+https://github.com/dsherret/deno_lockfile.git?branch=deno_semver_0_7#2f4d4bef5141c73591c68b578433ddbb8b1442ef" dependencies = [ "deno_semver", "serde", @@ -2039,7 +2032,6 @@ dependencies = [ [[package]] name = "deno_npm" version = "0.26.0" -source = "git+https://github.com/dsherret/deno_npm.git?branch=refactor_deno_semver_0_7#e75af8a5fc919f17811afefb8c03086695e42cb4" dependencies = [ "async-trait", "capacity_builder 0.4.2", @@ -2105,7 +2097,6 @@ dependencies = [ [[package]] name = "deno_package_json" version = "0.2.1" -source = "git+https://github.com/dsherret/deno_package_json.git?branch=refactor_deno_semver_0_7#93b8f486ffffa8b0846e5aced09c45324150b1d1" dependencies = [ "boxed_error", "deno_error", @@ -2240,7 +2231,6 @@ dependencies = [ [[package]] name = "deno_semver" version = "0.6.1" -source = "git+https://github.com/dsherret/deno_semver.git?branch=perf_stack_strings#d5a325428693cac86b033c712c54aa172b677df1" dependencies = [ "capacity_builder 0.4.2", "deno_error", diff --git a/Cargo.toml b/Cargo.toml index 5894b4f69fe1d7..9accf05aaaa61e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -343,9 +343,16 @@ opt-level = 3 opt-level = 3 [patch.crates-io] -deno_semver = { git = "https://github.com/dsherret/deno_semver.git", branch = "perf_stack_strings" } -deno_package_json = { git = "https://github.com/dsherret/deno_package_json.git", branch = "refactor_deno_semver_0_7" } -deno_lockfile = { git = "https://github.com/dsherret/deno_lockfile.git", branch = "deno_semver_0_7" } -deno_config = { git = "https://github.com/dsherret/deno_config.git", branch = "refactor_deno_semver_0_7" } -deno_npm = { git = "https://github.com/dsherret/deno_npm.git", branch = "refactor_deno_semver_0_7" } -deno_graph = { git = "https://github.com/dsherret/deno_graph.git", branch = "refactor_deno_semver_0_7" } +# deno_semver = { git = "https://github.com/dsherret/deno_semver.git", branch = "perf_stack_strings" } +# deno_package_json = { git = "https://github.com/dsherret/deno_package_json.git", branch = "refactor_deno_semver_0_7" } +# deno_lockfile = { git = "https://github.com/dsherret/deno_lockfile.git", branch = "deno_semver_0_7" } +# deno_config = { git = "https://github.com/dsherret/deno_config.git", branch = "refactor_deno_semver_0_7" } +# deno_npm = { git = "https://github.com/dsherret/deno_npm.git", branch = "refactor_deno_semver_0_7" } +# deno_graph = { git = "https://github.com/dsherret/deno_graph.git", branch = "refactor_deno_semver_0_7" } +deno_semver = { path = "../deno_semver" } +deno_package_json = { path = "../deno_package_json" } +deno_lockfile = { path = "../deno_lockfile" } +deno_config = { path = "../deno_config" } +deno_npm = { path = "../deno_npm" } +deno_graph = { path = "../deno_graph" } +capacity_builder = { path = "../capacity_builder" } diff --git a/cli/graph_util.rs b/cli/graph_util.rs index b426b99389c2d6..88c412b65a1ce8 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -52,6 +52,7 @@ use deno_runtime::deno_node; use deno_runtime::deno_permissions::PermissionsContainer; use deno_semver::jsr::JsrDepPackageReq; use deno_semver::package::PackageNv; +use deno_semver::SmallStackString; use import_map::ImportMapError; use node_resolver::InNpmPackageChecker; use std::collections::HashSet; @@ -680,7 +681,7 @@ impl ModuleGraphBuilder { for (from, to) in graph.packages.mappings() { lockfile.insert_package_specifier( JsrDepPackageReq::jsr(from.clone()), - to.version.to_string_ecow(), + to.version.to_custom_string::(), ); } } diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 1ce09ff25b5b4c..c11b3596c7ec09 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -36,6 +36,8 @@ use deno_semver::package::PackageNv; use deno_semver::package::PackageNvReference; use deno_semver::package::PackageReq; use deno_semver::package::PackageReqReference; +use deno_semver::SmallStackString; +use deno_semver::StackString; use deno_semver::Version; use import_map::ImportMap; use node_resolver::NodeResolutionKind; @@ -278,22 +280,28 @@ impl<'a> TsResponseImportMapper<'a> { { let mut segments = jsr_path.split('/'); let name = if jsr_path.starts_with('@') { - format!("{}/{}", segments.next()?, segments.next()?) + let scope = segments.next()?; + let name = segments.next()?; + capacity_builder::StringBuilder::::build(|builder| { + builder.append(scope); + builder.append("/"); + builder.append(name); + }) + .unwrap() } else { - segments.next()?.to_string() + StackString::from(segments.next()?) }; let version = Version::parse_standard(segments.next()?).ok()?; - let nv = PackageNv { - name: name.into(), - version, - }; + let nv = PackageNv { name, version }; let path = segments.collect::>().join("/"); let export = self.resolver.jsr_lookup_export_for_path( &nv, &path, Some(&self.file_referrer), )?; - let sub_path = (export != ".").then_some(export).map(|s| s.into()); + let sub_path = (export != ".") + .then_some(export) + .map(|s| SmallStackString::from_string(s)); let mut req = None; req = req.or_else(|| { let import_map = self.maybe_import_map?; diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index c340d10d5df766..788d6569ae60ef 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -1016,7 +1016,7 @@ fn get_package_folder_id_from_folder_name( let folder_name = folder_name.replace('+', "/"); let (name, ending) = folder_name.rsplit_once('@')?; let name: StackString = if let Some(encoded_name) = name.strip_prefix('_') { - mixed_case_package_name_decode(encoded_name)?.into() + StackString::from_string(mixed_case_package_name_decode(encoded_name)?) } else { name.into() }; diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 5e75995298c6e4..30095f97b1dd5c 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -485,10 +485,7 @@ fn deserialize_npm_snapshot( |input| { let (input, req) = read_string_lossy(input)?; let (input, id) = read_u32_as_usize(input)?; - let req = match req { - Cow::Borrowed(req) => StackString::from(req), - Cow::Owned(req) => StackString::from(req), - }; + let req = StackString::from_cow(req); Ok((input, (req, id_to_npm_id(id)?))) } } diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 9c3c06e4977f36..ec538ecb0af2f0 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -161,11 +161,11 @@ pub async fn infer_name_from_url( let npm_ref = npm_ref.into_inner(); if let Some(sub_path) = npm_ref.sub_path { if !sub_path.contains('/') { - return Some(sub_path.into()); + return Some(sub_path.to_string()); } } if !npm_ref.req.name.contains('/') { - return Some(npm_ref.req.name.into()); + return Some(npm_ref.req.name.into_string()); } return None; } diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 505f8caf99747b..404f178c6a815a 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -684,7 +684,7 @@ async fn find_package_and_select_version_for_req( import_name: add_package_req.alias, package_name: prefixed_name, version_req: format!("{}{}", range_symbol, &nv.version), - selected_version: nv.version.to_string_hipstr(), + selected_version: nv.version.to_custom_string::(), })) } diff --git a/resolvers/npm_cache/lib.rs b/resolvers/npm_cache/lib.rs index dc135d729ef393..dbd33d29eb773f 100644 --- a/resolvers/npm_cache/lib.rs +++ b/resolvers/npm_cache/lib.rs @@ -15,6 +15,7 @@ use deno_npm::npm_rc::ResolvedNpmRc; use deno_npm::registry::NpmPackageInfo; use deno_npm::NpmPackageCacheFolderId; use deno_semver::package::PackageNv; +use deno_semver::StackString; use deno_semver::Version; use http::HeaderName; use http::HeaderValue; @@ -260,7 +261,7 @@ impl NpmCache { .and_then(|cache_id| { Some(NpmPackageCacheFolderId { nv: PackageNv { - name: cache_id.name.into(), + name: StackString::from_string(cache_id.name), version: Version::parse_from_npm(&cache_id.version).ok()?, }, copy_index: cache_id.copy_index, From e1c2c3aa1264561a8489abdfb87aab7860eee935 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 19 Dec 2024 12:26:21 -0500 Subject: [PATCH 04/12] update --- Cargo.lock | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a95f9ca9de7f19..0278e90be53331 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -680,6 +680,8 @@ dependencies = [ [[package]] name = "capacity_builder" version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ced42635df19d69e4296203f3d09edf81993fc33f70d1dd9a53e9659964a1ad" dependencies = [ "capacity_builder_macros", "ecow", @@ -690,6 +692,8 @@ dependencies = [ [[package]] name = "capacity_builder_macros" version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2883cccc7b2ed65fb29c1141063b0c544be562aed530bac4f4ada2f163c7618d" dependencies = [ "quote", "syn 2.0.87", @@ -2038,7 +2042,6 @@ dependencies = [ "deno_error", "deno_lockfile", "deno_semver", - "ecow", "futures", "log", "monch", @@ -9224,3 +9227,7 @@ dependencies = [ "cc", "pkg-config", ] + +[[patch.unused]] +name = "capacity_builder" +version = "0.5.0" From f4ff1a4a4633e54409d6742c8a85f1627d25725b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 19 Dec 2024 13:19:37 -0500 Subject: [PATCH 05/12] update --- Cargo.lock | 4 ++-- resolvers/deno/lib.rs | 2 +- resolvers/deno/npm/mod.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7faf565005469d..a0326e788a9c25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1758,7 +1758,7 @@ version = "0.86.3" dependencies = [ "anyhow", "async-trait", - "capacity_builder 0.4.2", + "capacity_builder 0.5.0", "data-url", "deno_ast", "deno_semver", @@ -2054,7 +2054,7 @@ name = "deno_npm" version = "0.26.0" dependencies = [ "async-trait", - "capacity_builder 0.4.2", + "capacity_builder 0.5.0", "deno_error", "deno_lockfile", "deno_semver", diff --git a/resolvers/deno/lib.rs b/resolvers/deno/lib.rs index 9038284c6bbf17..05fa416da1b7e4 100644 --- a/resolvers/deno/lib.rs +++ b/resolvers/deno/lib.rs @@ -329,7 +329,7 @@ impl< return node_resolver .resolve_package_subpath_from_deno_module( pkg_folder, - npm_req_ref.sub_path().map(|v| v.as_str()), + npm_req_ref.sub_path(), Some(referrer), resolution_mode, resolution_kind, diff --git a/resolvers/deno/npm/mod.rs b/resolvers/deno/npm/mod.rs index fc41a93f78a5ca..64ec86fe3f6615 100644 --- a/resolvers/deno/npm/mod.rs +++ b/resolvers/deno/npm/mod.rs @@ -144,7 +144,7 @@ impl ) -> Result { self.resolve_req_with_sub_path( req_ref.req(), - req_ref.sub_path().map(|s| s.as_str()), + req_ref.sub_path(), referrer, resolution_mode, resolution_kind, From 6158044a3b4ec5c76a3ee9f6bd43a597e6d32d4f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 19 Dec 2024 15:02:18 -0500 Subject: [PATCH 06/12] Bump From a90209ab2619faba1dab9c6079e68daaf0fd2881 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 14:55:10 -0500 Subject: [PATCH 07/12] bump versions --- Cargo.lock | 54 +++++++++++++++++++++++--------------------------- Cargo.toml | 27 ++++++------------------- cli/Cargo.toml | 2 +- 3 files changed, 32 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8611171f482cf0..d7488df623774d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -677,39 +677,23 @@ dependencies = [ "itoa", ] -[[package]] -name = "capacity_builder" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ced42635df19d69e4296203f3d09edf81993fc33f70d1dd9a53e9659964a1ad" -dependencies = [ - "capacity_builder_macros 0.2.1", - "itoa", -] - [[package]] name = "capacity_builder" version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f2d24a6dcf0cd402a21b65d35340f3a49ff3475dc5fdac91d22d2733e6641c6" dependencies = [ - "capacity_builder_macros 0.3.0", + "capacity_builder_macros", "ecow", "hipstr", "itoa", ] -[[package]] -name = "capacity_builder_macros" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2883cccc7b2ed65fb29c1141063b0c544be562aed530bac4f4ada2f163c7618d" -dependencies = [ - "quote", - "syn 2.0.87", -] - [[package]] name = "capacity_builder_macros" version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b4a6cae9efc04cc6cbb8faf338d2c497c165c83e74509cf4dbedea948bbf6e5" dependencies = [ "quote", "syn 2.0.87", @@ -1262,7 +1246,7 @@ dependencies = [ "boxed_error", "bytes", "cache_control", - "capacity_builder 0.4.2", + "capacity_builder 0.5.0", "chrono", "clap", "clap_complete", @@ -1501,7 +1485,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.40.0" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afa3beb6b9e0604cfe0380d30f88c5b758d44e228d5a5fc42ae637ccfb7d089" dependencies = [ "anyhow", "deno_package_json", @@ -1754,7 +1740,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.86.4" +version = "0.86.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f669d96d63841d9ba10f86b161d898678ce05bc1e3c9ee1c1f7449a68eed2b64" dependencies = [ "anyhow", "async-trait", @@ -1893,7 +1881,9 @@ dependencies = [ [[package]] name = "deno_lockfile" -version = "0.23.2" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632e835a53ed667d62fdd766c5780fe8361c831d3e3fbf1a760a0b7896657587" dependencies = [ "deno_semver", "serde", @@ -2051,7 +2041,9 @@ dependencies = [ [[package]] name = "deno_npm" -version = "0.26.0" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f818ad5dc4c206b50b5cfa6f10b4b94b127e15c8342c152768eba40c225ca23" dependencies = [ "async-trait", "capacity_builder 0.5.0", @@ -2115,7 +2107,9 @@ dependencies = [ [[package]] name = "deno_package_json" -version = "0.2.1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81d72db99fdebfc371d7be16972c18a47daa7a29cb5fbb3900ab2114b1f42d96" dependencies = [ "boxed_error", "deno_error", @@ -2144,7 +2138,7 @@ dependencies = [ name = "deno_permissions" version = "0.43.0" dependencies = [ - "capacity_builder 0.4.2", + "capacity_builder 0.5.0", "deno_core", "deno_path_util", "deno_terminal 0.2.0", @@ -2249,7 +2243,9 @@ dependencies = [ [[package]] name = "deno_semver" -version = "0.6.1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4775271f9b5602482698f76d24ea9ed8ba27af7f587a7e9a876916300c542435" dependencies = [ "capacity_builder 0.5.0", "deno_error", diff --git a/Cargo.toml b/Cargo.toml index a33c9d229782fc..33f4083b0ca2e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,14 +51,14 @@ deno_ast = { version = "=0.44.0", features = ["transpiling"] } deno_core = { version = "0.326.0" } deno_bench_util = { version = "0.178.0", path = "./bench_util" } -deno_config = { version = "=0.40.0", features = ["workspace", "sync"] } -deno_lockfile = "=0.23.2" +deno_config = { version = "=0.41.0", features = ["workspace", "sync"] } +deno_lockfile = "=0.24.0" deno_media_type = { version = "0.2.0", features = ["module_specifier"] } -deno_npm = "=0.26.0" +deno_npm = "=0.27.0" deno_path_util = "=0.2.2" deno_permissions = { version = "0.43.0", path = "./runtime/permissions" } deno_runtime = { version = "0.192.0", path = "./runtime" } -deno_semver = "=0.6.1" +deno_semver = "=0.7.1" deno_terminal = "0.2.0" napi_sym = { version = "0.114.0", path = "./ext/napi/sym" } test_util = { package = "test_server", path = "./tests/util/server" } @@ -108,7 +108,7 @@ boxed_error = "0.2.3" brotli = "6.0.0" bytes = "1.4.0" cache_control = "=0.2.0" -capacity_builder = "0.4.2" +capacity_builder = "0.5.0" cbc = { version = "=0.1.2", features = ["alloc"] } # Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS. # Instead use util::time::utc_now() @@ -120,7 +120,7 @@ data-encoding = "2.3.3" data-url = "=0.3.1" deno_cache_dir = "=0.15.0" deno_error = "=0.5.2" -deno_package_json = { version = "0.2.1", default-features = false } +deno_package_json = { version = "0.3.0", default-features = false } deno_unsync = "0.4.2" dlopen2 = "0.6.1" ecb = "=0.1.2" @@ -341,18 +341,3 @@ opt-level = 3 opt-level = 3 [profile.release.package.zstd-sys] opt-level = 3 - -[patch.crates-io] -# deno_semver = { git = "https://github.com/dsherret/deno_semver.git", branch = "perf_stack_strings" } -# deno_package_json = { git = "https://github.com/dsherret/deno_package_json.git", branch = "refactor_deno_semver_0_7" } -# deno_lockfile = { git = "https://github.com/dsherret/deno_lockfile.git", branch = "deno_semver_0_7" } -# deno_config = { git = "https://github.com/dsherret/deno_config.git", branch = "refactor_deno_semver_0_7" } -# deno_npm = { git = "https://github.com/dsherret/deno_npm.git", branch = "refactor_deno_semver_0_7" } -# deno_graph = { git = "https://github.com/dsherret/deno_graph.git", branch = "refactor_deno_semver_0_7" } -deno_semver = { path = "../deno_semver" } -deno_package_json = { path = "../deno_package_json" } -deno_lockfile = { path = "../deno_lockfile" } -deno_config = { path = "../deno_config" } -deno_npm = { path = "../deno_npm" } -deno_graph = { path = "../deno_graph" } -capacity_builder = { path = "../capacity_builder" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4b0380717b047d..ad0e4fa95d7fee 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -74,7 +74,7 @@ deno_config.workspace = true deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "=0.161.3", features = ["rust", "comrak"] } deno_error.workspace = true -deno_graph = { version = "=0.86.4" } +deno_graph = { version = "=0.86.5" } deno_lint = { version = "=0.68.2", features = ["docs"] } deno_lockfile.workspace = true deno_npm.workspace = true From cf462619b557161e4f2c72e8f546a1b14f8bc275 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 14:55:54 -0500 Subject: [PATCH 08/12] clippy --- resolvers/deno/npm/byonm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resolvers/deno/npm/byonm.rs b/resolvers/deno/npm/byonm.rs index 36f08a74f417f6..c6f5d1cd041a0d 100644 --- a/resolvers/deno/npm/byonm.rs +++ b/resolvers/deno/npm/byonm.rs @@ -179,9 +179,9 @@ impl ByonmNpmResolver { req: &PackageReq, referrer: &Url, ) -> Result, PackageJsonLoadError> { - fn resolve_alias_from_pkg_json<'a>( + fn resolve_alias_from_pkg_json( req: &PackageReq, - pkg_json: &'a PackageJson, + pkg_json: &PackageJson, ) -> Option { let deps = pkg_json.resolve_local_package_json_deps(); for (key, value) in From 5e5a6cae049110c6ef807656ac73f9fa3c894b6b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 14:58:14 -0500 Subject: [PATCH 09/12] compile errors --- tests/integration/check_tests.rs | 4 ++-- tests/integration/jsr_tests.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index b98d719fcaa303..a1fdf834032b5c 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -218,7 +218,7 @@ fn npm_module_check_then_error() { "npm:@denotest/breaking-change-between-versions", ) .unwrap(), - "1.0.0".to_string(), + "1.0.0".into(), ); lockfile_path.write(lockfile.as_json_string()); temp_dir.write( @@ -236,7 +236,7 @@ fn npm_module_check_then_error() { "npm:@denotest/breaking-change-between-versions", ) .unwrap(), - "2.0.0".to_string(), + "2.0.0".into(), ); lockfile_path.write(lockfile.as_json_string()); diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index c4812e6bfb3b8c..f438ebfd508745 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -159,7 +159,7 @@ console.log(version);"#, .get_mut( &JsrDepPackageReq::from_str("jsr:@denotest/no-module-graph@0.1").unwrap(), ) - .unwrap() = "0.1.0".to_string(); + .unwrap() = "0.1.0".into(); lockfile_path.write(lockfile.as_json_string()); test_context From 3538eaa9cc869e7843fdc4a89503eed5c83beec1 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 15:20:09 -0500 Subject: [PATCH 10/12] issues --- cli/args/mod.rs | 20 ++++++++++---------- cli/args/package_json.rs | 4 ++-- cli/lsp/analysis.rs | 5 +---- cli/lsp/language_server.rs | 3 +-- cli/tsc/mod.rs | 2 +- cli/worker.rs | 6 ++---- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 00e1b3f36a17af..3f42a6b9d4442e 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -993,24 +993,24 @@ impl CliOptions { // https://nodejs.org/api/process.html match target.as_str() { "aarch64-apple-darwin" => NpmSystemInfo { - os: "darwin".to_string(), - cpu: "arm64".to_string(), + os: "darwin".into(), + cpu: "arm64".into(), }, "aarch64-unknown-linux-gnu" => NpmSystemInfo { - os: "linux".to_string(), - cpu: "arm64".to_string(), + os: "linux".into(), + cpu: "arm64".into(), }, "x86_64-apple-darwin" => NpmSystemInfo { - os: "darwin".to_string(), - cpu: "x64".to_string(), + os: "darwin".into(), + cpu: "x64".into(), }, "x86_64-unknown-linux-gnu" => NpmSystemInfo { - os: "linux".to_string(), - cpu: "x64".to_string(), + os: "linux".into(), + cpu: "x64".into(), }, "x86_64-pc-windows-msvc" => NpmSystemInfo { - os: "win32".to_string(), - cpu: "x64".to_string(), + os: "win32".into(), + cpu: "x64".into(), }, value => { log::warn!( diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index 7bd83911b902a6..50d1c047993a62 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -120,7 +120,7 @@ impl NpmInstallDepsProvider { match dep { PackageJsonDepValue::Req(pkg_req) => { let workspace_pkg = workspace_npm_pkgs.iter().find(|pkg| { - pkg.matches_req(&pkg_req) + pkg.matches_req(pkg_req) // do not resolve to the current package && pkg.pkg_json.path != pkg_json.path }); @@ -149,7 +149,7 @@ impl NpmInstallDepsProvider { } }; if let Some(pkg) = workspace_npm_pkgs.iter().find(|pkg| { - pkg.matches_name_and_version_req(&alias, &version_req) + pkg.matches_name_and_version_req(alias, &version_req) }) { workspace_pkgs.push(InstallNpmWorkspacePkg { alias: Some(alias.clone()), diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 6e93b9709e7adb..7faf93a90e182e 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -384,10 +384,7 @@ impl<'a> TsResponseImportMapper<'a> { { if pkg_reqs.contains(package_ref.req()) { let sub_path = sub_path.as_deref().unwrap_or(""); - let value_sub_path = package_ref - .sub_path() - .map(|s| s.as_str()) - .unwrap_or(""); + let value_sub_path = package_ref.sub_path().unwrap_or(""); if let Some(key_sub_path) = sub_path.strip_prefix(value_sub_path) { diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 0632e199b443f7..a7a0a59743bee7 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -3769,8 +3769,7 @@ impl Inner { for (name, def) in tasks { result.push(TaskDefinition { name: name.clone(), - // todo(https://github.com/denoland/deno/pull/27191): do not unwrap - command: def.command.unwrap().clone(), + command: def.command.clone(), source_uri: url_to_uri(&config_file.specifier) .map_err(|_| LspError::internal_error())?, }); diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index b2cd279016d4ca..4c18d1a2b0b23f 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -983,7 +983,7 @@ fn resolve_non_graph_specifier_types( .resolve_pkg_folder_from_deno_module_req(npm_req_ref.req(), referrer)?; let res_result = node_resolver.resolve_package_subpath_from_deno_module( &package_folder, - npm_req_ref.sub_path().map(|s| s.as_str()), + npm_req_ref.sub_path(), Some(referrer), resolution_mode, NodeResolutionKind::Types, diff --git a/cli/worker.rs b/cli/worker.rs index d4ffb2f9b784e9..c733f4132123a9 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -518,10 +518,8 @@ impl CliMainWorkerFactory { package_ref.req(), &referrer, )?; - let main_module = self.resolve_binary_entrypoint( - &package_folder, - package_ref.sub_path().map(|p| p.as_str()), - )?; + let main_module = self + .resolve_binary_entrypoint(&package_folder, package_ref.sub_path())?; if let Some(lockfile) = &shared.maybe_lockfile { // For npm binary commands, ensure that the lockfile gets updated From c4164dfe832625e633331eb02ce9dc1a75990c27 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 15:21:48 -0500 Subject: [PATCH 11/12] clippy --- cli/lsp/analysis.rs | 2 +- cli/tools/registry/pm/deps.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 7faf93a90e182e..8fb3454bc83ee2 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -301,7 +301,7 @@ impl<'a> TsResponseImportMapper<'a> { )?; let sub_path = (export != ".") .then_some(export) - .map(|s| SmallStackString::from_string(s)); + .map(SmallStackString::from_string); let mut req = None; req = req.or_else(|| { let import_map = self.maybe_import_map?; diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs index 3ec06fae32821a..ffa53417e99b2d 100644 --- a/cli/tools/registry/pm/deps.rs +++ b/cli/tools/registry/pm/deps.rs @@ -348,7 +348,7 @@ fn add_deps_from_package_json( deno_package_json::PackageJsonDepValue::Req(req) => { let alias = k.as_str(); let alias = (alias != req.name).then(|| alias.to_string()); - if !filter.should_include(alias.as_deref(), &req, DepKind::Npm) { + if !filter.should_include(alias.as_deref(), req, DepKind::Npm) { continue; } let id = DepId(deps.len()); From 75ef726a1283ead548d46a5deb8db8c9e7cc490e Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 20 Dec 2024 15:38:08 -0500 Subject: [PATCH 12/12] fix --- cli/npm/managed/resolution.rs | 2 +- cli/tools/info.rs | 12 ++++++------ cli/tools/registry/pm.rs | 4 ++-- cli/tools/upgrade.rs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/npm/managed/resolution.rs b/cli/npm/managed/resolution.rs index 8c8abf72399cc0..5d9fcf46469b0b 100644 --- a/cli/npm/managed/resolution.rs +++ b/cli/npm/managed/resolution.rs @@ -340,7 +340,7 @@ fn populate_lockfile_from_snapshot( JsrDepPackageReq::npm(package_req.clone()), { StringBuilder::::build(|builder| { - builder.append(&id.nv.name); + builder.append(&id.nv.version); builder.append(&id.peer_dependencies); }) .unwrap() diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 3851bb1b7f8eaa..39a7a912bf50b7 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -280,7 +280,7 @@ fn add_npm_packages_to_json( if let Some(module) = module.as_object_mut() { module.insert( "npmPackage".to_string(), - pkg.id.as_serialized().to_string().into(), + pkg.id.as_serialized().into_string().into(), ); } } @@ -298,7 +298,7 @@ fn add_npm_packages_to_json( { dep.insert( "npmPackage".to_string(), - pkg.id.as_serialized().to_string().into(), + pkg.id.as_serialized().into_string().into(), ); } } @@ -332,13 +332,13 @@ fn add_npm_packages_to_json( deps.sort(); let deps = deps .into_iter() - .map(|id| serde_json::Value::String(id.as_serialized().to_string())) + .map(|id| serde_json::Value::String(id.as_serialized().into_string())) .collect::>(); kv.insert("dependencies".to_string(), deps.into()); let registry_url = npmrc.get_registry_url(&pkg.id.nv.name); kv.insert("registryUrl".to_string(), registry_url.to_string().into()); - json_packages.insert(pkg.id.as_serialized().to_string(), kv.into()); + json_packages.insert(pkg.id.as_serialized().into_string(), kv.into()); } json.insert("npmPackages".to_string(), json_packages.into()); @@ -551,7 +551,7 @@ impl<'a> GraphDisplayContext<'a> { None => Specifier(module.specifier().clone()), }; let was_seen = !self.seen.insert(match &package_or_specifier { - Package(package) => package.id.as_serialized().to_string(), + Package(package) => package.id.as_serialized().into_string(), Specifier(specifier) => specifier.to_string(), }); let header_text = if was_seen { @@ -634,7 +634,7 @@ impl<'a> GraphDisplayContext<'a> { if let Some(package) = self.npm_info.packages.get(dep_id) { if !package.dependencies.is_empty() { let was_seen = - !self.seen.insert(package.id.as_serialized().to_string()); + !self.seen.insert(package.id.as_serialized().into_string()); if was_seen { child.text = format!("{} {}", child.text, colors::gray("*")); } else { diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 404f178c6a815a..afa9b0222ca0f5 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -284,7 +284,7 @@ fn package_json_dependency_entry( (npm_package.into(), selected.version_req) } else { ( - selected.import_name.to_string(), + selected.import_name.into_string(), format!("npm:{}@{}", npm_package, selected.version_req), ) } @@ -293,7 +293,7 @@ fn package_json_dependency_entry( let scope_replaced = jsr_package.replace('/', "__"); let version_req = format!("npm:@jsr/{scope_replaced}@{}", selected.version_req); - (selected.import_name.to_string(), version_req) + (selected.import_name.into_string(), version_req) } else { (selected.package_name, selected.version_req) } diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index b198bea5ef97fa..b3d7618be96b5b 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -675,7 +675,7 @@ impl RequestedVersion { ); }; - if semver.pre.contains(&SmallStackString::from("rc")) { + if semver.pre.contains(&SmallStackString::from_static("rc")) { (ReleaseChannel::Rc, passed_version) } else { (ReleaseChannel::Stable, passed_version)