1 | import { RawPackument } from '../types/raw-packument';
|
2 | import { assertValidPackageName } from '../utils/assert-valid-package-name';
|
3 | import { fetchFromRegistry } from '../utils/fetch-from-registry';
|
4 |
|
5 | /**
|
6 | * `getRawPackument` returns the packument (package document) containing
|
7 | * all the metadata about a package present on the registry.
|
8 | *
|
9 | * Note: the packument is returned as retrieved from the registry.
|
10 | *
|
11 | * @param name - package name
|
12 | * @param registry - URL of the registry (default: npm registry)
|
13 | * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors)
|
14 | * @param cached - accept cached responses (default: `true`)
|
15 | *
|
16 | * @example
|
17 | * Get the packument for package `query-registry` from the npm registry:
|
18 | *
|
19 | * ```typescript
|
20 | * import { getRawPackument } from 'query-registry';
|
21 | *
|
22 | * (async () => {
|
23 | * const packument = await getRawPackument({ name: 'query-registry' });
|
24 | *
|
25 | * // Output: 'query-registry'
|
26 | * console.log(packument.name);
|
27 | * })();
|
28 | * ```
|
29 | *
|
30 | * @see {@link RawPackument}
|
31 | * @see {@link npmRegistry}
|
32 | * @see {@link npmRegistryMirrors}
|
33 | */
|
34 | export async function getRawPackument({
|
35 | name,
|
36 | registry,
|
37 | mirrors,
|
38 | cached,
|
39 | }: {
|
40 | name: string;
|
41 | registry?: string;
|
42 | mirrors?: string[];
|
43 | cached?: boolean;
|
44 | }): Promise<RawPackument> {
|
45 | assertValidPackageName({ name });
|
46 |
|
47 | const endpoint = `/${name}`;
|
48 | return fetchFromRegistry({ endpoint, registry, mirrors, cached });
|
49 | }
|