1 | import { assertValidPackageName } from '../utils/assert-valid-package-name.esm.js';
|
2 | import { fetchFromRegistry } from '../utils/fetch-from-registry.esm.js';
|
3 |
|
4 | /**
|
5 | * `getRawAbbreviatedPackument` returns the abbreviated packument (package document)
|
6 | * containing only the metadata necessary to install a package present on the registry.
|
7 | *
|
8 | * Note: the abbreviated packument is returned as retrieved from the registry.
|
9 | *
|
10 | * @param name - package name
|
11 | * @param registry - URL of the registry (default: npm registry)
|
12 | * @param mirrors - URLs of the registry mirrors (default: npm registry mirrors)
|
13 | * @param cached - accept cached responses (default: `true`)
|
14 | *
|
15 | * @example
|
16 | * Get the abbreviated packument for package `query-registry` from the npm registry:
|
17 | *
|
18 | * ```typescript
|
19 | * import { getRawAbbreviatedPackument } from 'query-registry';
|
20 | *
|
21 | * (async () => {
|
22 | * const packument = await getRawAbbreviatedPackument({ name: 'query-registry' });
|
23 | *
|
24 | * // Output: 'query-registry'
|
25 | * console.log(packument.name);
|
26 | * })();
|
27 | * ```
|
28 | *
|
29 | * @see {@link RawAbbreviatedPackument}
|
30 | * @see {@link npmRegistry}
|
31 | * @see {@link npmRegistryMirrors}
|
32 | */
|
33 |
|
34 | async function getRawAbbreviatedPackument({
|
35 | name,
|
36 | registry,
|
37 | mirrors,
|
38 | cached
|
39 | }) {
|
40 | assertValidPackageName({
|
41 | name
|
42 | });
|
43 | const endpoint = `/${name}`;
|
44 | const headers = {
|
45 | Accept: 'application/vnd.npm.install-v1+json'
|
46 | };
|
47 | return fetchFromRegistry({
|
48 | endpoint,
|
49 | headers,
|
50 | registry,
|
51 | mirrors,
|
52 | cached
|
53 | });
|
54 | }
|
55 |
|
56 | export { getRawAbbreviatedPackument };
|
57 | //# sourceMappingURL=get-raw-abbreviated-packument.esm.js.map
|