import type { DepID } from '@vltpkg/dep-id'; import type { Spec, SpecLikeBase, SpecOptions } from '@vltpkg/spec'; /** * Utility type that overrides specific properties of type T with new types * from R. Constrains override values to exclude undefined, ensuring that * normalization cannot introduce undefined to fields that shouldn't have it. */ export type Override = { [K in keyof T]: K extends keyof R ? R[K] : T[K]; }; /** anything that can be encoded in JSON */ export type JSONField = JSONField[] | boolean | number | string | { [k: string]: JSONField; } | null | undefined; /** sha512 SRI string */ export type Integrity = `sha512-${string}`; /** SHA256 key identifier */ export type KeyID = `SHA256:${string}`; /** The Manifest['dist'] field present in registry manifests */ export type Dist = { integrity?: Integrity; shasum?: string; tarball?: string; fileCount?: number; unpackedSize?: number; signatures?: { keyid: KeyID; sig: string; }[]; }; /** An object used to mark some peerDeps as optional */ export type PeerDependenciesMetaValue = { optional?: boolean; }; export type ConditionalValueObject = { [k: string]: ConditionalValue; }; export type ConditionalValue = ConditionalValue[] | ConditionalValueObject | string | null; export type ExportsSubpaths = { [path in '.' | `./${string}`]?: ConditionalValue; }; export type Exports = Exclude | ExportsSubpaths; export type Imports = Record<`#${string}`, ConditionalValue>; export type FundingEntry = string | { url: string; type?: string; [key: string]: JSONField; }; export type Funding = FundingEntry | FundingEntry[]; /** * An object with url and optional additional properties */ export type NormalizedFundingEntry = { url: string; type?: string; [key: string]: JSONField; }; /** * Normalized funding information, an array of {@link NormalizedFundingEntry}. */ export type NormalizedFunding = NormalizedFundingEntry[]; /** * Normalize funding information to a consistent format. */ export declare const normalizeFunding: (funding: unknown) => NormalizedFunding | undefined; /** * Type guard to check if a value is a {@link NormalizedFundingEntry}. */ export declare const isNormalizedFundingEntry: (o: unknown) => o is NormalizedFundingEntry; /** * Type guard to check if a value is a {@link NormalizedFunding}. */ export declare const isNormalizedFunding: (o: unknown) => o is NormalizedFunding; /** * Given a version Normalize the version field in a manifest. */ export declare const fixManifestVersion: (manifest: T) => T; declare const kWriteAccess: unique symbol; declare const kIsPublisher: unique symbol; /** * Parse a string or object into a normalized contributor. */ export declare const parsePerson: (person: unknown, writeAccess?: boolean, isPublisher?: boolean) => NormalizedContributorEntry | undefined; /** * Normalized contributors - always an array of {@link NormalizedContributorEntry}. */ export type NormalizedContributors = NormalizedContributorEntry[]; /** * Represents a normalized contributor object. This is the type that is * used in the {@link NormalizedManifest} and {@link NormalizedManifestRegistry} * objects. */ export type NormalizedContributorEntry = { email?: string; name?: string; url?: string; [kWriteAccess]?: boolean; [kIsPublisher]?: boolean; writeAccess?: boolean; isPublisher?: boolean; }; /** * Type guard to check if a value is a normalized contributor entry. */ export declare const isNormalizedContributorEntry: (o: unknown) => o is NormalizedContributorEntry; /** * Type guard to check if a value is a {@link NormalizedContributors}. */ export declare const isNormalizedContributors: (o: unknown) => o is NormalizedContributors; /** * Normalize contributors and maintainers from various formats */ export declare const normalizeContributors: (contributors: unknown, maintainers?: unknown) => NormalizedContributorEntry[] | undefined; export type Person = string | { name: string; url?: string; email?: string; }; export type Repository = string | { type: string; url: string; }; export type Bugs = string | { url?: string; email?: string; }; export type Keywords = string[] | string; /** * Normalized bugs entry - always an object with type and url/email */ export type NormalizedBugsEntry = { type?: 'email' | 'link'; url?: string; email?: string; }; /** * Normalized keywords - always an array of strings */ export type NormalizedKeywords = string[]; /** * Normalized engines - always a record of string to string */ export type NormalizedEngines = Record; /** * Normalized OS list - always an array of strings */ export type NormalizedOs = string[]; /** * Normalized CPU list - always an array of strings */ export type NormalizedCpu = string[]; /** * Normalized libc list - always an array of strings */ export type NormalizedLibc = string[]; /** * Normalized bugs - always an array of {@link NormalizedBugsEntry} */ export type NormalizedBugs = NormalizedBugsEntry[]; /** * Normalized bin - always a record of string to string */ export type NormalizedBin = Record; /** * Normalize bugs information to a {@link NormalizedBugs} consistent format. */ export declare const normalizeBugs: (bugs: unknown) => NormalizedBugs | undefined; /** * Type guard to check if a value is a {@link NormalizedBugsEntry}. */ export declare const isNormalizedBugsEntry: (o: unknown) => o is NormalizedBugsEntry; /** * Type guard to check if a value is a {@link NormalizedBugs}. */ export declare const isNormalizedBugs: (o: unknown) => o is NormalizedBugs; /** * Normalize keywords information to a {@link NormalizedKeywords} consistent format. */ export declare const normalizeKeywords: (keywords: unknown) => NormalizedKeywords | undefined; /** * Type guard to check if a value is a {@link NormalizedKeywords}. */ export declare const isNormalizedKeywords: (o: unknown) => o is NormalizedKeywords; /** * Normalize engines information to a {@link NormalizedEngines} consistent format. */ export declare const normalizeEngines: (engines: unknown) => NormalizedEngines | undefined; /** * Normalize OS information to a {@link NormalizedOs} consistent format. */ export declare const normalizeOs: (os: unknown) => NormalizedOs | undefined; /** * Normalize CPU information to a {@link NormalizedCpu} consistent format. */ export declare const normalizeCpu: (cpu: unknown) => NormalizedCpu | undefined; /** * Normalize libc information to a {@link NormalizedLibc} consistent format. */ export declare const normalizeLibc: (libc: unknown) => NormalizedLibc | undefined; /** * Type guard to check if a value is a {@link NormalizedEngines}. */ export declare const isNormalizedEngines: (o: unknown) => o is NormalizedEngines; /** * Type guard to check if a value is a {@link NormalizedOs}. */ export declare const isNormalizedOs: (o: unknown) => o is NormalizedOs; /** * Type guard to check if a value is a {@link NormalizedCpu}. */ export declare const isNormalizedCpu: (o: unknown) => o is NormalizedCpu; /** * Type guard to check if a value is a {@link NormalizedLibc}. */ export declare const isNormalizedLibc: (o: unknown) => o is NormalizedLibc; /** * Normalizes the bin paths. */ export declare const normalizeBinPaths: (manifest: Pick) => Record | undefined; export type Manifest = { /** The name of the package. optional because {} is a valid package.json */ name?: string; /** The version of the package. optional because {} is a valid package.json */ version?: string; /** production dependencies, name:specifier */ dependencies?: Record; /** development dependencies, name:specifier */ devDependencies?: Record; /** optional dependencies, name:specifier */ optionalDependencies?: Record; /** peer dependencies, name:specifier */ peerDependencies?: Record; /** peer dependencies marked as optional */ peerDependenciesMeta?: Record; /** dependency ranges that are acceptable, but not forced */ acceptDependencies?: Record; /** names of dependencies included in the package tarball */ bundleDependencies?: string[]; /** a message indicating that this is not to be used */ deprecated?: string; /** executable built and linked by this package */ bin?: Record | string; /** run-script actions for this package */ scripts?: Record; /** supported run-time platforms this package can run on */ engines?: Record; /** supported operating systems this package can run on */ os?: string[] | string; /** supported CPU architectures this package can run on */ cpu?: string[] | string; /** supported libc implementations this package can run on (e.g. glibc, musl) */ libc?: string[] | string; /** URLs that can be visited to fund this project */ funding?: Funding; /** The homepage of the repository */ homepage?: string; /** * Only present in Manifests served by a registry. Contains information * about the artifact served for this package release. */ dist?: Dist; /** a short description of the package */ description?: string; /** search keywords */ keywords?: Keywords; /** where to go to file issues */ bugs?: Bugs; /** where the development happens */ repository?: Repository; /** the main module, if exports['.'] is not set */ main?: string; /** named subpath exports */ exports?: Exports; /** named #identifier imports */ imports?: Imports; /** * the HEAD of the git repo this was published from * only present in published packages */ gitHead?: string; /** whether the package is private */ private?: boolean; /** whether this is ESM or CommonJS by default */ type?: 'commonjs' | 'module'; /** npm puts this on published manifests */ gypfile?: boolean; /** the author of a package */ author?: Person; /** contributors to the package */ contributors?: Person[]; /** the license of the package */ license?: string; }; export type NormalizedFields = { bugs: NormalizedBugs | undefined; author: NormalizedContributorEntry | undefined; contributors: NormalizedContributors | undefined; funding: NormalizedFunding | undefined; keywords: NormalizedKeywords | undefined; engines: NormalizedEngines | undefined; os: NormalizedOs | undefined; cpu: NormalizedCpu | undefined; libc: NormalizedLibc | undefined; bin: NormalizedBin | undefined; }; /** * A {@link Manifest} object that contains normalized fields. */ export type NormalizedManifest = Override; /** * A {@link ManifestRegistry} object that contains normalized fields. */ export type NormalizedManifestRegistry = Override; /** * A specific type of {@link Manifest} that represents manifests that were * retrieved from a registry, these will always have `name`, `version` * and `dist` information along with an optional `maintainers` field. */ export type ManifestRegistry = Manifest & Required> & { maintainers?: unknown; }; /** * Maps the manifest type to the equivalent normalized manifest type. */ export type SomeNormalizedManifest = T extends ManifestRegistry ? NormalizedManifestRegistry : NormalizedManifest; /** * A document that represents available package versions in a given registry * along with extra information, such as `dist-tags` and `maintainers` info. * The `versions` field is key-value structure in which keys are the * available versions of a given package and values are * {@link ManifestRegistry} objects. */ export type Packument = { name: string; 'dist-tags': Record; versions: Record; modified?: string; time?: Record; readme?: string; contributors?: Person[]; maintainers?: Person[]; }; export type RefType = 'branch' | 'head' | 'other' | 'pull' | 'tag'; /** * A representation of a given remote ref in a {@link RevDoc} object. */ export type RevDocEntry = Omit & Required> & { /** sha this references */ sha: string; /** ref as passed git locally */ ref: string; /** canonical full ref, like `refs/tags/blahblah` */ rawRef: string; /** what type of ref this is: 'branch', 'tag', etc. */ type: RefType; }; /** * An object kind of resembling a packument, but about a git repo. */ export type RevDoc = Omit & { /** all semver-looking tags go in this record */ versions: Record; /** all named things that can be cloned down remotely */ refs: Record; /** all named shas referenced above */ shas: Record; }; /** * A type guard to check if a value is a boolean. */ export declare const isBoolean: (value: unknown) => value is boolean; export declare const integrityRE: RegExp; export declare const isIntegrity: (i: unknown) => i is Integrity; export declare const asIntegrity: (i: unknown) => Integrity; export declare const assertIntegrity: (i: unknown) => asserts i is Integrity; export declare const keyIDRE: RegExp; export declare const isKeyID: (k: unknown) => k is KeyID; export declare const asKeyID: (k: unknown) => KeyID; export declare const assertKeyID: (k: unknown) => asserts k is KeyID; /** * Convert an unknown value to an error. */ export declare const asError: (er: unknown, fallbackMessage?: string) => Error; /** * Check if a value is an error. */ export declare const isError: (er: unknown) => er is Error; /** * Check if an error has a cause property. */ export declare const isErrorWithCause: (er: unknown) => er is Error & { cause: unknown; }; /** * Check if an unknown value is a plain object. */ export declare const isObject: (v: unknown) => v is Record; export declare const maybeRecordStringString: (o: unknown) => o is Record | undefined; export declare const isRecordStringString: (o: unknown) => o is Record; export declare const assertRecordStringString: (o: unknown) => void; export declare const isRecordStringT: (o: unknown, check: (o: unknown) => o is T) => o is Record; export declare const assertRecordStringT: (o: unknown, check: (o: unknown) => o is T, wanted: string) => asserts o is Record; export declare const isRecordStringManifest: (o: unknown) => o is Record; export declare const maybePeerDependenciesMetaSet: (o: unknown) => o is Record | undefined; export declare const maybeBoolean: (o: unknown) => o is boolean; export declare const isPeerDependenciesMetaValue: (o: unknown) => o is PeerDependenciesMetaValue; export declare const maybeString: (a: unknown) => a is string | undefined; export declare const maybeDist: (a: unknown) => a is Manifest["dist"]; /** * Is a given unknown value a valid {@link Manifest} object? * Returns `true` if so. */ export declare const isManifest: (m: unknown) => m is Manifest; /** * A specific {@link Manifest} that is retrieved uniquely from reading * registry packument and manifest endpoints, it has `dist`, `name` and * `version` fields defined. */ export declare const isManifestRegistry: (m: unknown) => m is ManifestRegistry; /** * Given an unknown value, convert it to a {@link Manifest}. */ export declare const asManifest: (m: unknown, from?: (...a: unknown[]) => any) => Manifest; /** * Given a {@link Manifest} returns a {@link NormalizedManifest} that * contains normalized author, bugs, funding, contributors, keywords and * version fields. */ export declare const normalizeManifest: (manifest: T) => SomeNormalizedManifest; /** * Type guard to check if a value is a {@link NormalizedManifest}. */ export declare const isNormalizedManifest: (o: unknown) => o is NormalizedManifest; /** * Given an unknown value, convert it to a {@link NormalizedManifest}. */ export declare const asNormalizedManifest: (m: unknown, from?: (...a: unknown[]) => any) => NormalizedManifest; /** * Given an unknown value, convert it to a {@link ManifestRegistry}. */ export declare const asManifestRegistry: (m: unknown, from?: (...a: unknown[]) => any) => ManifestRegistry; /** * Type guard to check if a value is a {@link NormalizedManifestRegistry}. */ export declare const isNormalizedManifestRegistry: (o: unknown) => o is NormalizedManifestRegistry; /** * Given an unknown value, convert it to a {@link NormalizedManifestRegistry}. */ export declare const asNormalizedManifestRegistry: (m: unknown, from?: (...a: unknown[]) => any) => NormalizedManifestRegistry; /** * Walks a normalized manifest and expands any symbols found * in the `author` and `contributors` fields. */ export declare const expandNormalizedManifestSymbols: (m: NormalizedManifest) => NormalizedManifest; export declare const assertManifest: (m: unknown) => asserts m is Manifest; export declare const assertManifestRegistry: (m: unknown) => asserts m is ManifestRegistry; export declare const isPackument: (p: unknown) => p is Packument; export declare const asPackument: (p: unknown, from?: (...a: unknown[]) => any) => Packument; export declare const assertPackument: (m: unknown) => asserts m is Packument; /** * Name of the package.json keys used to define different types of dependencies. */ export type DependencyTypeLong = 'dependencies' | 'devDependencies' | 'optionalDependencies' | 'peerDependencies'; /** * Unique keys that define different types of dependencies relationship. */ export type DependencyTypeShort = 'dev' | 'optional' | 'peer' | 'peerOptional' | 'prod'; /** * Unique keys that indicate how a new or updated dependency should be saved * back to a manifest. * * `'implicit'` is used to indicate that a dependency should be saved as * whatever type it already exists as. If the dependency does not exist, * then `'implicit'` is equivalent to `'prod'`, as that is the default * save type. */ export type DependencySaveType = DependencyTypeShort | 'implicit'; /** * A set of the possible long dependency type names, * as used in `package.json` files. */ export declare const longDependencyTypes: Set; /** * A set of the short type keys used to represent dependency relationships. */ export declare const shortDependencyTypes: Set; /** * Maps between long form names usually used in `package.json` files * to a corresponding short form name, used in lockfiles. */ export declare const dependencyTypes: Map; export type EdgeLike = { name: string; from: NodeLike; spec: SpecLikeBase; to?: NodeLike; type: DependencyTypeShort; optional?: boolean; peer?: boolean; }; export type GraphLike = { importers: Set; mainImporter: NodeLike; projectRoot: string; nodes: Map; nodesByName: Map>; edges: Set; addEdge: (type: DependencyTypeShort, spec: Spec, from: NodeLike, to?: NodeLike) => EdgeLike; addNode: (id?: DepID, manifest?: NormalizedManifest, spec?: Spec, name?: string, version?: string) => NodeLike; removeNode(node: NodeLike, replacement?: NodeLike, keepEdges?: boolean): void; }; export type NodeLike = { id: DepID; confused: boolean; edgesIn: Set; edgesOut: Map; workspaces: Map | undefined; location?: string; manifest?: NormalizedManifest | null; rawManifest?: NormalizedManifest | null; name?: string | null; version?: string | null; integrity?: string | null; resolved?: string | null; importer: boolean; graph: GraphLike; mainImporter: boolean; projectRoot: string; dev: boolean; optional: boolean; modifier?: string | undefined; peerSetHash?: string | undefined; registry?: string; platform?: { engines?: Record; os?: string[] | string; cpu?: string[] | string; libc?: string[] | string; }; bins?: Record; buildState?: 'none' | 'needed' | 'built' | 'failed'; buildAllowed?: boolean; buildBlocked?: boolean; options: SpecOptions; toJSON: () => Pick & { rawManifest?: NodeLike['manifest']; }; toString(): string; setResolved(): void; setConfusedManifest(fixed: NormalizedManifest, confused?: NormalizedManifest): void; maybeSetConfusedManifest(spec: Spec, confused?: NormalizedManifest): void; }; /** * Parse a scoped package name into its scope and name components. */ export declare const parseScope: (scoped: string) => [string | undefined, string]; export {};