mirror of
https://github.com/Noratrieb/node-package-manager.git
synced 2026-01-14 15:45:03 +01:00
full package json
This commit is contained in:
parent
bf1809e025
commit
c5e1b8011c
3 changed files with 135 additions and 62 deletions
|
|
@ -4,33 +4,26 @@ use color_eyre::Result;
|
|||
use indexmap::IndexMap;
|
||||
use reqwest::blocking::Client;
|
||||
use serde::Deserialize;
|
||||
use tracing::{error, info};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Person {
|
||||
name: String,
|
||||
url: Option<String>,
|
||||
email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Bugs {
|
||||
url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Repository {
|
||||
r#type: String,
|
||||
url: String,
|
||||
}
|
||||
use crate::{
|
||||
manifest::{Bugs, Human, Person, Repository},
|
||||
PackageJson,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Dist {
|
||||
shasum: String,
|
||||
tarball: String,
|
||||
integrity: Option<String>,
|
||||
#[serde(rename = "fileCount")]
|
||||
file_count: Option<u32>,
|
||||
#[serde(rename = "unpackedSize")]
|
||||
unpacked_size: Option<u32>,
|
||||
#[serde(rename = "npm-signature")]
|
||||
npm_signature: Option<String>,
|
||||
}
|
||||
|
||||
// todo: this is actually just a package.json with extra stuff
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct VersionMeta {
|
||||
_from: Option<String>,
|
||||
|
|
@ -42,48 +35,38 @@ struct VersionMeta {
|
|||
#[serde(rename = "_npmVersion")]
|
||||
_npm_version: String,
|
||||
_shasum: Option<String>,
|
||||
author: Person,
|
||||
bugs: Bugs,
|
||||
dependencies: IndexMap<String, String>,
|
||||
#[serde(rename = "devDependencies")]
|
||||
dev_dependencies: IndexMap<String, String>,
|
||||
#[serde(rename = "_hasShrinkwrap")]
|
||||
_has_shrinkwrap: Option<bool>,
|
||||
dist: Dist,
|
||||
engines: IndexMap<String, String>,
|
||||
files: Vec<String>,
|
||||
homepage: String,
|
||||
keywords: Vec<String>,
|
||||
license: String,
|
||||
main: String,
|
||||
maintainers: Vec<Person>,
|
||||
name: String,
|
||||
repository: Repository,
|
||||
scripts: IndexMap<String, String>,
|
||||
version: String,
|
||||
|
||||
#[serde(flatten)]
|
||||
package_json: PackageJson,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PackageMeta {
|
||||
_id: String,
|
||||
_rev: String,
|
||||
author: Person,
|
||||
bugs: Bugs,
|
||||
#[serde(default = "Vec::new")]
|
||||
contributors: Vec<Person>,
|
||||
description: String,
|
||||
#[serde(rename = "dist-tags")]
|
||||
dist_tags: IndexMap<String, String>,
|
||||
homepage: String,
|
||||
keywords: Vec<String>,
|
||||
license: String,
|
||||
maintainers: Vec<Person>,
|
||||
name: String,
|
||||
readme: String,
|
||||
#[serde(rename = "readmeFilename")]
|
||||
readme_filename: String,
|
||||
repository: Repository,
|
||||
time: IndexMap<String, String>,
|
||||
users: IndexMap<String, bool>,
|
||||
versions: IndexMap<String, VersionMeta>,
|
||||
|
||||
author: Human,
|
||||
bugs: Option<Bugs>,
|
||||
contributors: Option<Vec<Human>>,
|
||||
description: Option<String>,
|
||||
homepage: Option<String>,
|
||||
keywords: Option<Vec<String>>,
|
||||
license: Option<String>,
|
||||
maintainers: Option<Vec<Human>>,
|
||||
readme: Option<String>,
|
||||
#[serde(rename = "readmeFilename")]
|
||||
readme_filename: Option<String>,
|
||||
repository: Option<Repository>,
|
||||
}
|
||||
|
||||
pub struct NpmClient {
|
||||
|
|
@ -104,15 +87,15 @@ impl NpmClient {
|
|||
let code = res.status();
|
||||
let body = res.text()?;
|
||||
let meta = serde_json::from_str::<PackageMeta>(&body);
|
||||
if let Err(err) = meta {
|
||||
error!(?err, "error");
|
||||
if let Err(err) = &meta {
|
||||
tracing::error!(?err, "error");
|
||||
let col = err.column();
|
||||
let after = &body[col..][..50];
|
||||
let before = &body[col - 50..col];
|
||||
error!(%before, %after, "err");
|
||||
let after = &body[col..][..10];
|
||||
let before = &body[col - 100..col];
|
||||
tracing::error!(%before, %after, "err");
|
||||
}
|
||||
|
||||
info!(?code, "Received response");
|
||||
info!(?code, ?meta, "Received response");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ fn main() -> Result<()> {
|
|||
|
||||
let client = NpmClient::new();
|
||||
|
||||
for (name, _) in &manifest.dependencies {
|
||||
for (name, _) in &manifest.dependencies.unwrap() {
|
||||
client.inspect_package(name)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
106
src/manifest.rs
106
src/manifest.rs
|
|
@ -1,16 +1,106 @@
|
|||
use indexmap::map::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Human {
|
||||
pub name: String,
|
||||
pub url: Option<String>,
|
||||
pub email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Person {
|
||||
Simple(String),
|
||||
Expanded(Human),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ExpandedFunding {
|
||||
pub r#type: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Funding {
|
||||
Simple(String),
|
||||
Expanded(ExpandedFunding),
|
||||
Multiple(Vec<ExpandedFunding>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Bugs {
|
||||
pub url: Option<String>,
|
||||
pub email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Repository {
|
||||
pub r#type: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Bin {
|
||||
Single(String),
|
||||
Multiple(IndexMap<String, String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Man {
|
||||
Single(String),
|
||||
Multiple(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PeerDependencyMeta {
|
||||
pub optional: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Override {
|
||||
Version(String),
|
||||
Nested(IndexMap<String, Override>),
|
||||
}
|
||||
|
||||
/// https://docs.npmjs.com/cli/v8/configuring-npm/package-json
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PackageJson {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub description: Option<String>,
|
||||
pub keywords: Option<Vec<String>>,
|
||||
pub homepage: Option<String>,
|
||||
pub bugs: Option<Bugs>,
|
||||
pub license: Option<String>,
|
||||
pub author: Option<Person>,
|
||||
pub contributors: Option<Vec<Person>>,
|
||||
pub funding: Option<Funding>,
|
||||
pub files: Option<Vec<String>>,
|
||||
pub main: Option<String>,
|
||||
pub browser: Option<String>,
|
||||
pub bin: Option<Bin>,
|
||||
pub man: Option<Man>,
|
||||
pub directories: Option<IndexMap<String, String>>,
|
||||
pub repository: Option<Repository>,
|
||||
pub scripts: Option<IndexMap<String, String>>,
|
||||
pub config: Option<IndexMap<String, serde_json::Value>>,
|
||||
pub dependencies: Option<IndexMap<String, String>>,
|
||||
pub dev_dependencies: Option<IndexMap<String, String>>,
|
||||
pub peer_dependencies: Option<IndexMap<String, String>>,
|
||||
pub peer_dependencies_meta: Option<IndexMap<String, PeerDependencyMeta>>,
|
||||
pub bundled_dependencies: Option<Vec<String>>,
|
||||
pub optional_dependencies: Option<IndexMap<String, String>>,
|
||||
pub overrides: Option<IndexMap<String, Override>>,
|
||||
pub engines: Option<IndexMap<String, String>>,
|
||||
pub os: Option<Vec<String>>,
|
||||
pub cpu: Option<Vec<String>>,
|
||||
pub private: Option<bool>,
|
||||
#[serde(default = "IndexMap::new")]
|
||||
pub scripts: IndexMap<String, String>,
|
||||
#[serde(default = "IndexMap::new")]
|
||||
pub dependencies: IndexMap<String, String>,
|
||||
#[serde(default = "IndexMap::new")]
|
||||
pub dev_dependencies: IndexMap<String, String>,
|
||||
pub publish_config: Option<IndexMap<String, serde_json::Value>>,
|
||||
pub workspaces: Option<Vec<String>>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue