index.d.ts
5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/// <reference types="node"/>
import {Agent as HttpAgent} from 'http';
import {Agent as HttpsAgent} from 'https';
declare class VersionNotFoundErrorClass extends Error {
readonly name: 'VersionNotFoundError';
constructor(packageName: string, version: string);
}
declare class PackageNotFoundErrorClass extends Error {
readonly name: 'PackageNotFoundError';
constructor(packageName: string);
}
declare namespace packageJson {
interface Agents {
http?: HttpAgent;
https?: HttpsAgent;
}
interface Options {
/**
Package version such as `1.0.0` or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`.
The version can also be in any format supported by the [semver](https://github.com/npm/node-semver) module. For example:
- `1` - Get the latest `1.x.x`
- `1.2` - Get the latest `1.2.x`
- `^1.2.3` - Get the latest `1.x.x` but at least `1.2.3`
- `~1.2.3` - Get the latest `1.2.x` but at least `1.2.3`
@default 'latest'
*/
readonly version?: string;
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
@default false
*/
readonly fullMetadata?: boolean;
/**
Return the [main entry](https://registry.npmjs.org/ava) containing all versions.
@default false
*/
readonly allVersions?: boolean;
/**
The registry URL is by default inferred from the npm defaults and `.npmrc`. This is beneficial as `package-json` and any project using it will work just like npm. This option is*only** intended for internal tools. You should*not** use this option in reusable packages. Prefer just using `.npmrc` whenever possible.
*/
readonly registryUrl?: string;
/**
Overwrite the `agent` option that is passed down to [`got`](https://github.com/sindresorhus/got#agent). This might be useful to add [proxy support](https://github.com/sindresorhus/got#proxies).
*/
readonly agent?: HttpAgent | HttpsAgent | Agents | false;
}
interface FullMetadataOptions extends Options {
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
@default false
*/
readonly fullMetadata: true;
}
interface DistTags {
readonly latest: string;
readonly [tagName: string]: string;
}
interface AbbreviatedMetadata {
readonly 'dist-tags': DistTags;
readonly modified: string;
readonly name: string;
readonly versions: {readonly [version: string]: AbbreviatedVersion};
readonly [key: string]: unknown;
}
interface AbbreviatedVersion {
readonly name: string;
readonly version: string;
readonly dist: {
readonly shasum: string;
readonly tarball: string;
readonly integrity?: string;
};
readonly deprecated?: string;
readonly dependencies?: {readonly [name: string]: string};
readonly optionalDependencies?: {readonly [name: string]: string};
readonly devDependencies?: {readonly [name: string]: string};
readonly bundleDependencies?: {readonly [name: string]: string};
readonly peerDependencies?: {readonly [name: string]: string};
readonly bin?: {readonly [key: string]: string};
readonly directories?: readonly string[];
readonly engines?: {readonly [type: string]: string};
readonly _hasShrinkwrap?: boolean;
readonly [key: string]: unknown;
}
interface Person {
readonly name?: string;
readonly email?: string;
readonly url?: string;
}
interface HoistedData {
readonly author?: Person;
readonly bugs?:
| {readonly url: string; readonly email?: string}
| {readonly url?: string; readonly email: string};
readonly contributors?: readonly Person[];
readonly description?: string;
readonly homepage?: string;
readonly keywords?: readonly string[];
readonly license?: string;
readonly maintainers?: readonly Person[];
readonly readme?: string;
readonly readmeFilename?: string;
readonly repository?: {readonly type: string; readonly url: string};
}
interface FullMetadata extends AbbreviatedMetadata, HoistedData {
readonly _id: string;
readonly _rev: string;
readonly time: {
readonly created: string;
readonly modified: string;
readonly [version: string]: string;
};
readonly users?: {readonly [user: string]: boolean};
readonly versions: {readonly [version: string]: FullVersion};
readonly [key: string]: unknown;
}
interface FullVersion extends AbbreviatedVersion, HoistedData {
readonly _id: string;
readonly _nodeVersion: string;
readonly _npmUser: string;
readonly _npmVersion: string;
readonly main?: string;
readonly files?: readonly string[];
readonly man?: readonly string[];
readonly scripts?: {readonly [scriptName: string]: string};
readonly gitHead?: string;
readonly types?: string;
readonly typings?: string;
readonly [key: string]: unknown;
}
type VersionNotFoundError = VersionNotFoundErrorClass;
type PackageNotFoundError = PackageNotFoundErrorClass;
}
declare const packageJson: {
/**
Get metadata of a package from the npm registry.
@param packageName - Name of the package.
@example
```
import packageJson = require('package-json');
(async () => {
console.log(await packageJson('ava'));
//=> {name: 'ava', ...}
// Also works with scoped packages
console.log(await packageJson('@sindresorhus/df'));
})();
```
*/
(packageName: string, options: packageJson.FullMetadataOptions): Promise<
packageJson.FullMetadata
>;
(packageName: string, options?: packageJson.Options): Promise<
packageJson.AbbreviatedMetadata
>;
/**
The error thrown when the given package version cannot be found.
*/
VersionNotFoundError: typeof VersionNotFoundErrorClass;
/**
The error thrown when the given package name cannot be found.
*/
PackageNotFoundError: typeof PackageNotFoundErrorClass;
// TODO: remove this in the next major version
default: typeof packageJson;
};
export = packageJson;