refactor: separate publish from pm subcommands (#28237)

This commit is contained in:
David Sherret 2025-02-21 17:02:33 -05:00 committed by GitHub
parent 761a9b62ce
commit 29c4661d0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 38 additions and 46 deletions

View file

@ -15,6 +15,7 @@ mod module_loader;
mod node; mod node;
mod npm; mod npm;
mod ops; mod ops;
mod registry;
mod resolver; mod resolver;
mod standalone; mod standalone;
mod task_runner; mod task_runner;
@ -108,10 +109,10 @@ fn spawn_subcommand<F: Future<Output = T> + 'static, T: SubcommandOutput>(
async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> { async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
let handle = match flags.subcommand.clone() { let handle = match flags.subcommand.clone() {
DenoSubcommand::Add(add_flags) => spawn_subcommand(async { DenoSubcommand::Add(add_flags) => spawn_subcommand(async {
tools::registry::add(flags, add_flags, tools::registry::AddCommandName::Add).await tools::pm::add(flags, add_flags, tools::pm::AddCommandName::Add).await
}), }),
DenoSubcommand::Remove(remove_flags) => spawn_subcommand(async { DenoSubcommand::Remove(remove_flags) => spawn_subcommand(async {
tools::registry::remove(flags, remove_flags).await tools::pm::remove(flags, remove_flags).await
}), }),
DenoSubcommand::Bench(bench_flags) => spawn_subcommand(async { DenoSubcommand::Bench(bench_flags) => spawn_subcommand(async {
if bench_flags.watch.is_some() { if bench_flags.watch.is_some() {
@ -193,7 +194,7 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
}), }),
DenoSubcommand::Outdated(update_flags) => { DenoSubcommand::Outdated(update_flags) => {
spawn_subcommand(async move { spawn_subcommand(async move {
tools::registry::outdated(flags, update_flags).await tools::pm::outdated(flags, update_flags).await
}) })
} }
DenoSubcommand::Repl(repl_flags) => { DenoSubcommand::Repl(repl_flags) => {
@ -316,7 +317,7 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
), ),
DenoSubcommand::Vendor => exit_with_message("⚠️ `deno vendor` was removed in Deno 2.\n\nSee the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", 1), DenoSubcommand::Vendor => exit_with_message("⚠️ `deno vendor` was removed in Deno 2.\n\nSee the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", 1),
DenoSubcommand::Publish(publish_flags) => spawn_subcommand(async { DenoSubcommand::Publish(publish_flags) => spawn_subcommand(async {
tools::registry::publish(flags, publish_flags).await tools::publish::publish(flags, publish_flags).await
}), }),
DenoSubcommand::Help(help_flags) => spawn_subcommand(async move { DenoSubcommand::Help(help_flags) => spawn_subcommand(async move {
use std::io::Write; use std::io::Write;

View file

@ -212,7 +212,7 @@ pub async fn uninstall(
let uninstall_flags = match uninstall_flags.kind { let uninstall_flags = match uninstall_flags.kind {
UninstallKind::Global(flags) => flags, UninstallKind::Global(flags) => flags,
UninstallKind::Local(remove_flags) => { UninstallKind::Local(remove_flags) => {
return super::registry::remove(flags, remove_flags).await; return super::pm::remove(flags, remove_flags).await;
} }
}; };
@ -300,12 +300,7 @@ async fn install_local(
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
match install_flags { match install_flags {
InstallFlagsLocal::Add(add_flags) => { InstallFlagsLocal::Add(add_flags) => {
super::registry::add( super::pm::add(flags, add_flags, super::pm::AddCommandName::Install).await
flags,
add_flags,
super::registry::AddCommandName::Install,
)
.await
} }
InstallFlagsLocal::Entrypoints(entrypoints) => { InstallFlagsLocal::Entrypoints(entrypoints) => {
install_from_entrypoints(flags, &entrypoints).await install_from_entrypoints(flags, &entrypoints).await
@ -314,7 +309,7 @@ async fn install_local(
let factory = CliFactory::from_flags(flags); let factory = CliFactory::from_flags(flags);
// surface any errors in the package.json // surface any errors in the package.json
factory.npm_installer()?.ensure_no_pkg_json_dep_errors()?; factory.npm_installer()?.ensure_no_pkg_json_dep_errors()?;
crate::tools::registry::cache_top_level_deps(&factory, None).await?; crate::tools::pm::cache_top_level_deps(&factory, None).await?;
if let Some(lockfile) = factory.cli_options()?.maybe_lockfile() { if let Some(lockfile) = factory.cli_options()?.maybe_lockfile() {
lockfile.write_if_changed()?; lockfile.write_if_changed()?;
@ -393,8 +388,7 @@ async fn install_global(
let entry_text = install_flags_global.module_url.as_str(); let entry_text = install_flags_global.module_url.as_str();
if !cli_options.initial_cwd().join(entry_text).exists() { if !cli_options.initial_cwd().join(entry_text).exists() {
// check for package requirement missing prefix // check for package requirement missing prefix
if let Ok(Err(package_req)) = if let Ok(Err(package_req)) = super::pm::AddRmPackageReq::parse(entry_text)
super::registry::AddRmPackageReq::parse(entry_text)
{ {
if jsr_resolver.req_to_nv(&package_req).await.is_some() { if jsr_resolver.req_to_nv(&package_req).await.is_some() {
bail!( bail!(

View file

@ -12,7 +12,8 @@ pub mod init;
pub mod installer; pub mod installer;
pub mod jupyter; pub mod jupyter;
pub mod lint; pub mod lint;
pub mod registry; pub mod pm;
pub mod publish;
pub mod repl; pub mod repl;
pub mod run; pub mod run;
pub mod serve; pub mod serve;

View file

@ -20,8 +20,8 @@ use deno_semver::VersionReq;
use deno_terminal::colors; use deno_terminal::colors;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::tools::registry::pm::deps::DepId; use crate::tools::pm::deps::DepId;
use crate::tools::registry::pm::deps::DepKind; use crate::tools::pm::deps::DepKind;
#[derive(Debug)] #[derive(Debug)]
pub struct PackageInfo { pub struct PackageInfo {

View file

@ -16,6 +16,7 @@ use deno_terminal::colors;
use super::deps::Dep; use super::deps::Dep;
use super::deps::DepId; use super::deps::DepId;
use super::deps::DepKind;
use super::deps::DepManager; use super::deps::DepManager;
use super::deps::DepManagerArgs; use super::deps::DepManagerArgs;
use super::deps::PackageLatestVersion; use super::deps::PackageLatestVersion;
@ -26,7 +27,6 @@ use crate::factory::CliFactory;
use crate::file_fetcher::CliFileFetcher; use crate::file_fetcher::CliFileFetcher;
use crate::jsr::JsrFetchResolver; use crate::jsr::JsrFetchResolver;
use crate::npm::NpmFetchResolver; use crate::npm::NpmFetchResolver;
use crate::tools::registry::pm::deps::DepKind;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
struct OutdatedPackage { struct OutdatedPackage {

View file

@ -379,7 +379,7 @@ impl Diagnostic for PublishDiagnostic {
use PublishDiagnostic::*; use PublishDiagnostic::*;
match &self { match &self {
InvalidExternalImport { imported, .. } => { InvalidExternalImport { imported, .. } => {
match super::api::get_jsr_alternative(imported) { match crate::registry::get_jsr_alternative(imported) {
Some(replacement) => { Some(replacement) => {
let replacement = SourceTextInfo::new(replacement.into()); let replacement = SourceTextInfo::new(replacement.into());
let start = replacement.line_start(0); let start = replacement.line_start(0);

View file

@ -34,6 +34,8 @@ use serde::Serialize;
use sha2::Digest; use sha2::Digest;
use tokio::process::Command; use tokio::process::Command;
use self::diagnostics::PublishDiagnostic;
use self::diagnostics::PublishDiagnosticsCollector;
use self::graph::GraphDiagnosticsCollector; use self::graph::GraphDiagnosticsCollector;
use self::module_content::ModuleContentProvider; use self::module_content::ModuleContentProvider;
use self::paths::CollectedPublishPath; use self::paths::CollectedPublishPath;
@ -46,21 +48,18 @@ use crate::args::PublishFlags;
use crate::factory::CliFactory; use crate::factory::CliFactory;
use crate::graph_util::ModuleGraphCreator; use crate::graph_util::ModuleGraphCreator;
use crate::http_util::HttpClient; use crate::http_util::HttpClient;
use crate::registry;
use crate::tools::lint::collect_no_slow_type_diagnostics; use crate::tools::lint::collect_no_slow_type_diagnostics;
use crate::tools::registry::diagnostics::PublishDiagnostic;
use crate::tools::registry::diagnostics::PublishDiagnosticsCollector;
use crate::type_checker::CheckOptions; use crate::type_checker::CheckOptions;
use crate::type_checker::TypeChecker; use crate::type_checker::TypeChecker;
use crate::util::display::human_size; use crate::util::display::human_size;
mod api;
mod auth; mod auth;
mod diagnostics; mod diagnostics;
mod graph; mod graph;
mod module_content; mod module_content;
mod paths; mod paths;
mod pm;
mod provenance; mod provenance;
mod publish_order; mod publish_order;
mod tar; mod tar;
@ -68,12 +67,6 @@ mod unfurl;
use auth::get_auth_method; use auth::get_auth_method;
use auth::AuthMethod; use auth::AuthMethod;
pub use pm::add;
pub use pm::cache_top_level_deps;
pub use pm::outdated;
pub use pm::remove;
pub use pm::AddCommandName;
pub use pm::AddRmPackageReq;
use publish_order::PublishOrderGraph; use publish_order::PublishOrderGraph;
use unfurl::SpecifierUnfurler; use unfurl::SpecifierUnfurler;
@ -558,10 +551,11 @@ async fn get_auth_headers(
.send() .send()
.await .await
.context("Failed to create interactive authorization")?; .context("Failed to create interactive authorization")?;
let auth = let auth = registry::parse_response::<
api::parse_response::<api::CreateAuthorizationResponse>(response) registry::CreateAuthorizationResponse,
.await >(response)
.context("Failed to create interactive authorization")?; .await
.context("Failed to create interactive authorization")?;
let auth_url = format!("{}?code={}", auth.verification_url, auth.code); let auth_url = format!("{}?code={}", auth.verification_url, auth.code);
let pkgs_text = if packages.len() > 1 { let pkgs_text = if packages.len() > 1 {
@ -594,9 +588,10 @@ async fn get_auth_headers(
.send() .send()
.await .await
.context("Failed to exchange authorization")?; .context("Failed to exchange authorization")?;
let res = let res = registry::parse_response::<
api::parse_response::<api::ExchangeAuthorizationResponse>(response) registry::ExchangeAuthorizationResponse,
.await; >(response)
.await;
match res { match res {
Ok(res) => { Ok(res) => {
log::info!( log::info!(
@ -668,7 +663,7 @@ async fn get_auth_headers(
text text
); );
} }
let api::OidcTokenResponse { value } = serde_json::from_str(&text) let registry::OidcTokenResponse { value } = serde_json::from_str(&text)
.with_context(|| { .with_context(|| {
format!( format!(
"Failed to parse OIDC token: '{}' (status {})", "Failed to parse OIDC token: '{}' (status {})",
@ -702,13 +697,13 @@ async fn check_if_scope_and_package_exist(
let mut needs_scope = false; let mut needs_scope = false;
let mut needs_package = false; let mut needs_package = false;
let response = api::get_scope(client, registry_api_url, scope).await?; let response = registry::get_scope(client, registry_api_url, scope).await?;
if response.status() == 404 { if response.status() == 404 {
needs_scope = true; needs_scope = true;
} }
let response = let response =
api::get_package(client, registry_api_url, scope, package).await?; registry::get_package(client, registry_api_url, scope, package).await?;
if response.status() == 404 { if response.status() == 404 {
needs_package = true; needs_package = true;
} }
@ -780,7 +775,7 @@ async fn ensure_scopes_and_packages_exist(
log::warn!("{}", colors::gray("Waiting...")); log::warn!("{}", colors::gray("Waiting..."));
let _ = open::that_detached(&create_package_url); let _ = open::that_detached(&create_package_url);
let package_api_url = api::get_package_api_url( let package_api_url = registry::get_package_api_url(
registry_api_url, registry_api_url,
&package.scope, &package.scope,
&package.package, &package.package,
@ -926,11 +921,12 @@ async fn publish_package(
.send() .send()
.await?; .await?;
let res = api::parse_response::<api::PublishingTask>(response).await; let res =
registry::parse_response::<registry::PublishingTask>(response).await;
let mut task = match res { let mut task = match res {
Ok(task) => task, Ok(task) => task,
Err(mut err) if err.code == "duplicateVersionPublish" => { Err(mut err) if err.code == "duplicateVersionPublish" => {
let task = serde_json::from_value::<api::PublishingTask>( let task = serde_json::from_value::<registry::PublishingTask>(
err.data.get_mut("task").unwrap().take(), err.data.get_mut("task").unwrap().take(),
) )
.unwrap(); .unwrap();
@ -976,7 +972,7 @@ async fn publish_package(
package.scope, package.package, package.version package.scope, package.package, package.version
) )
})?; })?;
task = api::parse_response::<api::PublishingTask>(resp) task = registry::parse_response::<registry::PublishingTask>(resp)
.await .await
.with_context(|| { .with_context(|| {
format!( format!(
@ -1285,10 +1281,10 @@ mod tests {
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
use super::has_license_file;
use super::tar::PublishableTarball; use super::tar::PublishableTarball;
use super::tar::PublishableTarballFile; use super::tar::PublishableTarballFile;
use super::verify_version_manifest; use super::verify_version_manifest;
use crate::tools::registry::has_license_file;
#[test] #[test]
fn test_verify_version_manifest() { fn test_verify_version_manifest() {

View file

@ -16,6 +16,7 @@ use lazy_regex::Lazy;
use sys_traits::FsMetadata; use sys_traits::FsMetadata;
use sys_traits::FsRead; use sys_traits::FsRead;
use super::diagnostics::PublishDiagnostic;
use super::diagnostics::PublishDiagnosticsCollector; use super::diagnostics::PublishDiagnosticsCollector;
use super::unfurl::SpecifierUnfurler; use super::unfurl::SpecifierUnfurler;
use super::unfurl::SpecifierUnfurlerDiagnostic; use super::unfurl::SpecifierUnfurlerDiagnostic;
@ -23,7 +24,6 @@ use crate::args::deno_json::TsConfigResolver;
use crate::cache::LazyGraphSourceParser; use crate::cache::LazyGraphSourceParser;
use crate::cache::ParsedSourceCache; use crate::cache::ParsedSourceCache;
use crate::sys::CliSys; use crate::sys::CliSys;
use crate::tools::registry::diagnostics::PublishDiagnostic;
struct JsxFolderOptions<'a> { struct JsxFolderOptions<'a> {
jsx_factory: &'a str, jsx_factory: &'a str,

View file

@ -25,11 +25,11 @@ use spki::der::asn1;
use spki::der::pem::LineEnding; use spki::der::pem::LineEnding;
use spki::der::EncodePem; use spki::der::EncodePem;
use super::api::OidcTokenResponse;
use super::auth::gha_oidc_token; use super::auth::gha_oidc_token;
use super::auth::is_gha; use super::auth::is_gha;
use crate::http_util; use crate::http_util;
use crate::http_util::HttpClient; use crate::http_util::HttpClient;
use crate::registry::OidcTokenResponse;
const PAE_PREFIX: &str = "DSSEv1"; const PAE_PREFIX: &str = "DSSEv1";