snyk-nodejs-lockfile-parser
Version:
Generate a dep tree given a lockfile
29 lines (28 loc) • 1.5 kB
TypeScript
/**
* Convert a lockfile `integrity` (SRI) string into `hash:<algorithm>` labels with
* lowercase-hex values. Returns an empty object (and debug-logs) when the value is absent
* or unparseable — never throws.
*/
export declare function hashLabelsFromIntegrity(integrity: string | undefined, nodeId: string): Record<string, string>;
/**
* Produce a `distribution:url` label from a lockfile `resolved` value when it is an
* http(s) tarball URL. `resolved` can also be a `file:`/workspace path for local deps;
* those are debug-logged and skipped.
*/
export declare function distributionUrlLabel(resolved: string | undefined, nodeId: string): Record<string, string>;
/**
* yarn v1 `resolved` values embed the npm-registry tarball shasum as a URL fragment
* (`…-1.0.0.tgz#<40-hex-sha1>`). For older lockfiles that carry no `integrity` line this is the
* only available hash, so surface it as `hash:sha-1`. Restricted to http(s) tarball URLs: a
* `#<40-hex>` fragment on a `git:`/`git+ssh:` resolution is a commit SHA, not a package hash.
*/
export declare function hashLabelFromResolvedFragment(resolved: string | undefined, nodeId: string): Record<string, string>;
/**
* Build the full set of component-metadata labels (package hashes + distribution URL) for a
* node, sourced from its lockfile `integrity` / `resolved` values.
*/
export declare function getComponentMetadataLabels(node: {
id: string;
integrity?: string;
resolved?: string;
}): Record<string, string>;