UNPKG

2.03 kBPlain TextView Raw
1import { RawPackageManifest } from '../types/raw-package-manifest';
2import { extractRawPackageManifest } from '../utils/extract-package-manifest';
3import { getRawPackument } from './get-raw-packument';
4
5/**
6 * `getRawPackageManifest` returns the manifest describing
7 * a specific version of a package.
8 *
9 * Note: the manifest is returned as retrieved from the registry.
10 *
11 * @param name - package name
12 * @param version - package version (default: `latest`)
13 * @param registry - URL of the registry (default: npm registry)
14 * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors)
15 * @param cached - accept cached responses (default: `true`)
16 *
17 * @example
18 * Get the latest manifest for package `query-registry` from the npm registry:
19 *
20 * ```typescript
21 * import { getRawPackageManifest } from 'query-registry';
22 *
23 * (async () => {
24 * const manifest = await getRawPackageManifest({ name: 'query-registry' });
25 *
26 * // Output: 'query-registry'
27 * console.log(manifest.name);
28 * })();
29 * ```
30 *
31 * @example
32 * Get the manifest for package `query-registry@1.0.0` from the npm registry:
33 *
34 * ```typescript
35 * import { getRawPackageManifest } from 'query-registry';
36 *
37 * (async () => {
38 * const manifest = await getRawPackageManifest({ name: 'query-registry', version: '1.0.0' });
39 *
40 * // Output: 'query-registry'
41 * console.log(manifest.name);
42 *
43 * // Output: '1.0.0'
44 * console.log(manifest.version);
45 * })();
46 * ```
47 *
48 * @see {@link RawPackageManifest}
49 * @see {@link npmRegistry}
50 * @see {@link npmRegistryMirrors}
51 */
52export async function getRawPackageManifest({
53 name,
54 version,
55 registry,
56 mirrors,
57 cached,
58}: {
59 name: string;
60 version?: string;
61 registry?: string;
62 mirrors?: string[];
63 cached?: boolean;
64}): Promise<RawPackageManifest> {
65 const rawPackument = await getRawPackument({
66 name,
67 registry,
68 mirrors,
69 cached,
70 });
71
72 return extractRawPackageManifest({ rawPackument, version });
73}