Skip to content

Commit

Permalink
feat: add getPackageManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Apr 12, 2024
1 parent fe7812b commit 188235f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/get-package-manifest.ts
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.
Expand Down Expand Up @@ -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));
};

0 comments on commit 188235f

Please sign in to comment.