-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import urlJoin from "url-join"; | ||
import { z } from "zod"; | ||
import { PackageJson } from "zod-package-json"; | ||
import { assertValidPackageName } from "./assert-valid-package-name"; | ||
import { fetchData } from "./fetch-data"; | ||
import { npmRegistryUrl } from "./npm-registry"; | ||
|
||
/** | ||
`Dist` describes the distribution metadata generated by the registry. | ||
|
@@ -91,3 +95,21 @@ The manifest contains data extracted from `package.json` as well as data generat | |
@see {@link https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version} | ||
*/ | ||
export type PackageManifest = z.infer<typeof PackageManifest>; | ||
|
||
/** | ||
`getPackageManifest` returns the manifest describing a specific version of a package (e.g., `[email protected]`). | ||
@param name - package name | ||
@param versionOrTag - semver version number (e.g., `1.0.0`) or distribution tag (e.g., `latest`) (default: `latest`) | ||
@param registry - URL of the registry (default: npm registry) | ||
@see {@link PackageManifest} | ||
*/ | ||
export const getPackageManifest = async ( | ||
name: string, | ||
versionOrTag = "latest", | ||
registry = npmRegistryUrl, | ||
): Promise<PackageManifest> => { | ||
assertValidPackageName(name); | ||
return fetchData(PackageManifest, urlJoin(registry, name, versionOrTag)); | ||
}; |