PackageJson

Struct PackageJson 

Source
pub struct PackageJson {
    pub path: PathBuf,
    pub realpath: PathBuf,
    /* private fields */
}
Expand description

Serde implementation for the deserialized package.json.

This implementation is used by the crate::Cache and enabled through the fs_cache feature.

Fields§

§path: PathBuf

Path to package.json. Contains the package.json filename.

§realpath: PathBuf

Realpath to package.json. Contains the package.json filename.

Implementations§

Source§

impl PackageJson

Source

pub fn path(&self) -> &Path

Returns the path where the package.json was found.

Contains the package.json filename.

This does not need to be the path where the file is stored on disk. See Self::realpath().

Source

pub fn realpath(&self) -> &Path

Returns the path where the package.json file was stored on disk.

Contains the package.json filename.

This is the canonicalized version of Self::path(), where all symbolic links are resolved.

Source

pub fn directory(&self) -> &Path

Directory to package.json.

§Panics
  • When the package.json path is misconfigured.
Source

pub fn name(&self) -> Option<&str>

Name of the package.

The “name” field can be used together with the “exports” field to self-reference a package using its name.

https://nodejs.org/api/packages.html#name

Source

pub fn version(&self) -> Option<&str>

Source

pub fn type(&self) -> Option<PackageType>

Returns the package type, if one is configured in the package.json.

https://nodejs.org/api/packages.html#type

Source

pub fn side_effects(&self) -> Option<SideEffects<'_>>

The “sideEffects” field.

https://webpack.js.org/guides/tree-shaking

Source

pub fn exports(&self) -> Option<ImportsExportsEntry<'_>>

The “exports” field allows defining the entry points of a package.

https://nodejs.org/api/packages.html#exports

Source

pub fn parse<Fs: FileSystem>( fs: &Fs, path: PathBuf, realpath: PathBuf, json: Vec<u8>, ) -> Result<Self, JSONError>

Parse a package.json file from JSON bytes

§Panics
§Errors

Trait Implementations§

Source§

impl Debug for PackageJson

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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