Skip to main content

PackageJson

Struct PackageJson 

Source
pub struct PackageJson {
Show 21 fields pub name: Option<String>, pub private: Option<bool>, pub main: Option<String>, pub module: Option<String>, pub types: Option<String>, pub typings: Option<String>, pub source: Option<String>, pub files: Vec<String>, pub browser: Option<Value>, pub bin: Option<Value>, pub exports: Option<Value>, pub imports: Option<Value>, pub dependencies: Option<HashMap<String, String>>, pub dev_dependencies: Option<HashMap<String, String>>, pub peer_dependencies: Option<HashMap<String, String>>, pub peer_dependencies_meta: Option<HashMap<String, PeerDependencyMeta>>, pub optional_dependencies: Option<HashMap<String, String>>, pub scripts: Option<HashMap<String, String>>, pub napi: Option<NapiConfig>, pub workspaces: Option<Value>, pub package_manager: Option<String>,
}
Expand description

Parsed package.json with fields relevant to fallow.

Fields§

§name: Option<String>

The name field: the package’s npm name, used to identify workspace packages and match public_packages config entries.

§private: Option<bool>

The private field. Non-boolean values become None rather than failing manifest parsing.

§main: Option<String>

The main field: CommonJS entry-point path, seeded as an entry point.

§module: Option<String>

The module field: ESM entry-point path, seeded as an entry point.

§types: Option<String>

The types field: type-declaration entry-point path.

§typings: Option<String>

The typings field: legacy spelling of types.

§source: Option<String>

The source field: unbundled source entry point used by bundler-based packages (Parcel convention).

§files: Vec<String>

The files field: publish allowlist patterns. Non-array values become empty rather than failing manifest parsing.

§browser: Option<Value>

The browser field, kept raw because it is either a string entry point or a path-remap object.

§bin: Option<Value>

The bin field, kept raw because it is either a string path or a name-to-path object; every referenced file is an entry point.

§exports: Option<Value>

The exports field, kept raw because of its many shapes (string, conditions object, subpath map); referenced files are entry points and the map drives subpath resolution.

§imports: Option<Value>

The imports field (#-prefixed internal subpath map), kept raw and consumed by the module resolver.

§dependencies: Option<HashMap<String, String>>

The dependencies map (package name to version range), the base set for unused/unlisted-dependency accounting.

§dev_dependencies: Option<HashMap<String, String>>

The devDependencies map, checked by unused-dev-dependencies and dev-dependency-in-production.

§peer_dependencies: Option<HashMap<String, String>>

The peerDependencies map. Peers are provided by the consumer, so they are exempt from unused-dependency reporting.

§peer_dependencies_meta: Option<HashMap<String, PeerDependencyMeta>>

The peerDependenciesMeta map, marking which peers are optional.

§optional_dependencies: Option<HashMap<String, String>>

The optionalDependencies map, checked by unused-optional-dependencies.

§scripts: Option<HashMap<String, String>>

The scripts map, scanned so packages invoked from scripts count as used tooling dependencies.

§napi: Option<NapiConfig>

The NAPI-RS napi block; see NapiConfig. Non-object values become None rather than failing manifest parsing.

§workspaces: Option<Value>

The workspaces field, kept raw because it is either a pattern array or an object with a packages array; drives workspace discovery.

§package_manager: Option<String>

The packageManager field (e.g. "pnpm@9.1.0"), used to determine the canonical package manager for the project.

Implementations§

Source§

impl PackageJson

Source

pub fn load(path: &Path) -> Result<Self, String>

Load from a package.json file.

§Errors

Returns an error string when the file cannot be read or parsed as JSON.

Source

pub fn all_dependency_names(&self) -> Vec<String>

Get all dependency names (production + dev + peer + optional).

Source

pub fn production_dependency_names(&self) -> Vec<String>

Get production dependency names only.

Source

pub fn dev_dependency_names(&self) -> Vec<String>

Get dev dependency names only.

Source

pub fn optional_dependency_names(&self) -> Vec<String>

Get optional dependency names only.

Source

pub fn peer_dependency_names(&self) -> Vec<String>

Get every peer dependency name, required or optional.

Source

pub fn peer_dependency_is_optional(&self, dep: &str) -> bool

Whether peerDependenciesMeta marks the peer dep as optional.

Source

pub fn entry_points(&self) -> Vec<String>

Extract entry points from package.json fields.

Source

pub fn exports_subdirectories(&self) -> Vec<String>

Extract unique subdirectory names referenced by the exports field keys.

For exports like "./compat": { ... }, "./hooks/client": { ... }, this returns ["compat", "hooks"]. Used to discover sub-packages in projects that define their internal package structure via the exports map (e.g., preact with compat/, hooks/, debug/ sub-packages).

Source

pub fn workspace_patterns(&self) -> Vec<String>

Extract workspace patterns from package.json.

Dependencies with a link: or file: spec in dependencies, devDependencies or optionalDependencies, as (name, target) pairs sorted by name.

The target is the path as written, relative to this manifest’s directory. The caller decides which targets are real package directories.

Trait Implementations§

Source§

impl Clone for PackageJson

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PackageJson

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PackageJson

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PackageJson

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PackageJson

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more