feat: keep dev dependencies in manifest file

This commit is contained in:
daimond113 2024-08-13 23:52:46 +02:00
parent 159d0bafc1
commit cc85135a8e
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
2 changed files with 56 additions and 51 deletions

View file

@ -11,8 +11,16 @@ use git2::{Remote, Repository, Signature};
use rusty_s3::{actions::PutObject, S3Action}; use rusty_s3::{actions::PutObject, S3Action};
use tar::Archive; use tar::Archive;
use crate::{
auth::UserId,
benv,
error::{Error, ErrorResponse},
package::{s3_name, S3_SIGN_DURATION},
search::update_version,
AppState,
};
use pesde::{ use pesde::{
manifest::Manifest, manifest::{DependencyType, Manifest},
source::{ source::{
git_index::GitBasedSource, git_index::GitBasedSource,
pesde::{IndexFile, IndexFileEntry, ScopeInfo, SCOPE_INFO_FILE}, pesde::{IndexFile, IndexFileEntry, ScopeInfo, SCOPE_INFO_FILE},
@ -23,15 +31,6 @@ use pesde::{
MANIFEST_FILE_NAME, MANIFEST_FILE_NAME,
}; };
use crate::{
auth::UserId,
benv,
error::{Error, ErrorResponse},
package::{s3_name, S3_SIGN_DURATION},
search::update_version,
AppState,
};
fn signature<'a>() -> Signature<'a> { fn signature<'a>() -> Signature<'a> {
Signature::now( Signature::now(
&benv!(required "COMMITTER_GIT_NAME"), &benv!(required "COMMITTER_GIT_NAME"),
@ -122,10 +121,10 @@ pub async fn publish_package(
let dependencies = manifest let dependencies = manifest
.all_dependencies() .all_dependencies()
.map_err(|_| Error::InvalidArchive)?; .map_err(|_| Error::InvalidArchive)?
.into_iter()
for (specifier, _) in dependencies.values() { .filter_map(|(alias, (specifier, ty))| {
match specifier { match &specifier {
DependencySpecifiers::Pesde(specifier) => { DependencySpecifiers::Pesde(specifier) => {
if specifier if specifier
.index .index
@ -137,20 +136,19 @@ pub async fn publish_package(
}) })
.is_none() .is_none()
{ {
return Err(Error::InvalidArchive); return Some(Err(Error::InvalidArchive));
} }
let (dep_scope, dep_name) = specifier.name.as_str(); let (dep_scope, dep_name) = specifier.name.as_str();
if source match source.read_file([dep_scope, dep_name], &app_state.project, None) {
.read_file([dep_scope, dep_name], &app_state.project, None)? Ok(Some(_)) => {}
.is_none() Ok(None) => return Some(Err(Error::InvalidArchive)),
{ Err(e) => return Some(Err(e.into())),
return Err(Error::InvalidArchive);
} }
} }
DependencySpecifiers::Wally(specifier) => { DependencySpecifiers::Wally(specifier) => {
if !config.wally_allowed { if !config.wally_allowed {
return Err(Error::InvalidArchive); return Some(Err(Error::InvalidArchive));
} }
if specifier if specifier
@ -159,17 +157,24 @@ pub async fn publish_package(
.filter(|index| index.parse::<url::Url>().is_ok()) .filter(|index| index.parse::<url::Url>().is_ok())
.is_none() .is_none()
{ {
return Err(Error::InvalidArchive); return Some(Err(Error::InvalidArchive));
} }
} }
DependencySpecifiers::Git(_) => { DependencySpecifiers::Git(_) => {
if !config.git_allowed { if !config.git_allowed {
return Err(Error::InvalidArchive); return Some(Err(Error::InvalidArchive));
} }
} }
}; };
if ty == DependencyType::Dev {
return None;
} }
Some(Ok((alias, (specifier, ty))))
})
.collect::<Result<_, Error>>()?;
let repo = source.repo_git2(&app_state.project)?; let repo = source.repo_git2(&app_state.project)?;
let (scope, name) = manifest.name.as_str(); let (scope, name) = manifest.name.as_str();

View file

@ -82,7 +82,7 @@ pub struct Manifest {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub peer_dependencies: BTreeMap<String, DependencySpecifiers>, pub peer_dependencies: BTreeMap<String, DependencySpecifiers>,
/// The dev dependencies of the package /// The dev dependencies of the package
#[serde(default, skip_serializing)] #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub dev_dependencies: BTreeMap<String, DependencySpecifiers>, pub dev_dependencies: BTreeMap<String, DependencySpecifiers>,
} }