mirror of
https://github.com/Noratrieb/node-package-manager.git
synced 2026-01-14 15:45:03 +01:00
things
This commit is contained in:
parent
c5e1b8011c
commit
b6224e7252
4 changed files with 90 additions and 51 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
|
@ -17,6 +17,15 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
|
|
@ -566,6 +575,7 @@ dependencies = [
|
|||
"color-eyre",
|
||||
"indexmap",
|
||||
"reqwest",
|
||||
"semver_rs",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tracing",
|
||||
|
|
@ -737,6 +747,8 @@ version = "1.5.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
|
|
@ -896,6 +908,19 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver_rs"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9594e1aab972e5b5ecbb330754bef51c7ba0dc12644b6bae9e09a4e19d472586"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.137"
|
||||
|
|
@ -1227,6 +1252,15 @@ version = "0.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.8"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ clap = { version = "3.1.18", features = ["derive"] }
|
|||
color-eyre = "0.6.1"
|
||||
indexmap = { version = "1.8.1", features = ["serde"] }
|
||||
reqwest = { version = "0.11.10", features = ["blocking", "rustls-tls", "json"] }
|
||||
semver_rs = { version = "0.2.0", features = ["serde"] }
|
||||
serde = { version = "1.0.137", features = ["derive"] }
|
||||
serde_json = "1.0.81"
|
||||
tracing = "0.1.34"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use color_eyre::Result;
|
|||
use indexmap::IndexMap;
|
||||
use reqwest::blocking::Client;
|
||||
use serde::Deserialize;
|
||||
use tracing::info;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
manifest::{Bugs, Human, Person, Repository},
|
||||
|
|
@ -12,61 +12,61 @@ use crate::{
|
|||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Dist {
|
||||
shasum: String,
|
||||
tarball: String,
|
||||
integrity: Option<String>,
|
||||
pub struct Dist {
|
||||
pub shasum: String,
|
||||
pub tarball: String,
|
||||
pub integrity: Option<String>,
|
||||
#[serde(rename = "fileCount")]
|
||||
file_count: Option<u32>,
|
||||
pub file_count: Option<u32>,
|
||||
#[serde(rename = "unpackedSize")]
|
||||
unpacked_size: Option<u32>,
|
||||
pub unpacked_size: Option<u32>,
|
||||
#[serde(rename = "npm-signature")]
|
||||
npm_signature: Option<String>,
|
||||
pub npm_signature: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct VersionMeta {
|
||||
_from: Option<String>,
|
||||
_id: String,
|
||||
pub struct VersionMeta {
|
||||
pub _from: Option<String>,
|
||||
pub _id: String,
|
||||
#[serde(rename = "_nodeVersion")]
|
||||
_node_version: String,
|
||||
pub _node_version: String,
|
||||
#[serde(rename = "_npmUser")]
|
||||
_npm_user: Person,
|
||||
pub _npm_user: Person,
|
||||
#[serde(rename = "_npmVersion")]
|
||||
_npm_version: String,
|
||||
_shasum: Option<String>,
|
||||
pub _npm_version: String,
|
||||
pub _shasum: Option<String>,
|
||||
#[serde(rename = "_hasShrinkwrap")]
|
||||
_has_shrinkwrap: Option<bool>,
|
||||
dist: Dist,
|
||||
files: Vec<String>,
|
||||
pub _has_shrinkwrap: Option<bool>,
|
||||
pub dist: Dist,
|
||||
pub files: Vec<String>,
|
||||
|
||||
#[serde(flatten)]
|
||||
package_json: PackageJson,
|
||||
pub package_json: PackageJson,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PackageMeta {
|
||||
_id: String,
|
||||
_rev: String,
|
||||
pub struct PackageMeta {
|
||||
pub _id: String,
|
||||
pub _rev: String,
|
||||
#[serde(rename = "dist-tags")]
|
||||
dist_tags: IndexMap<String, String>,
|
||||
name: String,
|
||||
time: IndexMap<String, String>,
|
||||
users: IndexMap<String, bool>,
|
||||
versions: IndexMap<String, VersionMeta>,
|
||||
pub dist_tags: IndexMap<String, String>,
|
||||
pub name: String,
|
||||
pub time: IndexMap<String, String>,
|
||||
pub users: IndexMap<String, bool>,
|
||||
pub 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>,
|
||||
pub author: Human,
|
||||
pub bugs: Option<Bugs>,
|
||||
pub contributors: Option<Vec<Human>>,
|
||||
pub description: Option<String>,
|
||||
pub homepage: Option<String>,
|
||||
pub keywords: Option<Vec<String>>,
|
||||
pub license: Option<String>,
|
||||
pub maintainers: Option<Vec<Human>>,
|
||||
pub readme: Option<String>,
|
||||
#[serde(rename = "readmeFilename")]
|
||||
readme_filename: Option<String>,
|
||||
repository: Option<Repository>,
|
||||
pub readme_filename: Option<String>,
|
||||
pub repository: Option<Repository>,
|
||||
}
|
||||
|
||||
pub struct NpmClient {
|
||||
|
|
@ -82,20 +82,13 @@ impl NpmClient {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn inspect_package(&self, name: &str) -> Result<()> {
|
||||
pub fn inspect_package(&self, name: &str) -> Result<PackageMeta> {
|
||||
let res = self.reqwest.get(format!("{BASE_URL}/{name}")).send()?;
|
||||
let code = res.status();
|
||||
let body = res.text()?;
|
||||
let meta = serde_json::from_str::<PackageMeta>(&body);
|
||||
if let Err(err) = &meta {
|
||||
tracing::error!(?err, "error");
|
||||
let col = err.column();
|
||||
let after = &body[col..][..10];
|
||||
let before = &body[col - 100..col];
|
||||
tracing::error!(%before, %after, "err");
|
||||
}
|
||||
let meta = serde_json::from_str::<PackageMeta>(&body)?;
|
||||
|
||||
info!(?code, ?meta, "Received response");
|
||||
Ok(())
|
||||
debug!(?code, ?meta, "Received response");
|
||||
Ok(meta)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/main.rs
15
src/main.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::fs;
|
||||
|
||||
use color_eyre::{eyre::WrapErr, Result};
|
||||
use tracing::{debug, metadata::LevelFilter};
|
||||
use tracing::{debug, info, metadata::LevelFilter};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
|
||||
|
||||
use crate::{download::NpmClient, manifest::PackageJson};
|
||||
|
|
@ -23,7 +23,18 @@ fn main() -> Result<()> {
|
|||
let client = NpmClient::new();
|
||||
|
||||
for (name, _) in &manifest.dependencies.unwrap() {
|
||||
client.inspect_package(name)?;
|
||||
look_at_package(name, &client)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(client))]
|
||||
fn look_at_package(name: &str, client: &NpmClient) -> Result<()> {
|
||||
let meta = client.inspect_package(name)?;
|
||||
|
||||
for version in meta.versions.keys() {
|
||||
info!(%version);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue