pub struct PackageJson { /* private fields */ }Expand description
Browser-favoring conditional-exports resolver over a parsed package.json.
Resolves the bare entry and subpaths to relative file paths using the
condition order browsers want — browser → module → import → default
(never node/require) — with a module → browser → main fallback when
there is no exports field. Enough of the Node resolution algorithm to
generate an ES-module import map; not a general-purpose resolver.
Implementations§
Source§impl PackageJson
impl PackageJson
Sourcepub fn from_path(path: &Path) -> Result<Self, Box<dyn Error>>
pub fn from_path(path: &Path) -> Result<Self, Box<dyn Error>>
Read and parse a package.json from disk.
Sourcepub fn from_json(s: &str) -> Result<Self, Box<dyn Error>>
pub fn from_json(s: &str) -> Result<Self, Box<dyn Error>>
Parse a package.json from a JSON string (e.g. read out of a tarball).
Sourcepub fn from_value(raw: Value) -> Self
pub fn from_value(raw: Value) -> Self
Wrap an already-parsed JSON document.
Sourcepub fn package_type(&self) -> PackageType
pub fn package_type(&self) -> PackageType
Module when "type": "module", else CommonJs (Node’s default).
Sourcepub fn resolve_main(&self) -> Option<String>
pub fn resolve_main(&self) -> Option<String>
Resolve the bare entry (the . export) to a relative path, for the browser.
Sourcepub fn resolve_subpath(&self, subpath: &str) -> Option<String>
pub fn resolve_subpath(&self, subpath: &str) -> Option<String>
Resolve a subpath (e.g. "./helpers/decorate"; leading ./ optional) via
the exports map — exact key first, then the longest "./…/*" pattern.
Sourcepub fn entries(&self) -> Vec<Entry>
pub fn entries(&self) -> Vec<Entry>
Enumerate the import-map-worthy entries: the bare entry, concrete subpaths,
and "./*"-pattern prefixes.
Sourcepub fn referenced_paths(&self) -> Vec<String>
pub fn referenced_paths(&self) -> Vec<String>
Every relative path the resolution references (concrete targets + pattern
directories) — used to keep the right files when vendoring, even under src/.
Trait Implementations§
Source§impl Clone for PackageJson
impl Clone for PackageJson
Source§fn clone(&self) -> PackageJson
fn clone(&self) -> PackageJson
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more