UNPKG

2.7 kBTypeScriptView Raw
1/**
2 * Which versions of which packages are required.
3 */
4interface WantedVersions {
5 /**
6 * Required version of Node.js.
7 */
8 node?: string;
9
10 /**
11 * Required version of npm.
12 */
13 npm?: string;
14
15 /**
16 * Required version of yarn.
17 */
18 yarn?: string;
19}
20
21type OnGetVersion = (error: Error | null, info: VersionInfo) => void;
22
23/**
24 * Gets the version of a package.
25 *
26 * @param packageName Name of the package.
27 * @param onComplete Handler for the package name.
28 */
29type GetVersion = (packageName: string, onComplete: OnGetVersion) => void;
30
31/**
32 * Requested version range of a package.
33 */
34interface Wanted {
35 /**
36 * Resolved semver equivalent of the raw version.
37 */
38 range: string;
39
40 /**
41 * Raw semver requirement for the version.
42 */
43 raw: string;
44}
45
46/**
47 * Positive result of checking a program version.
48 */
49interface SatisfiedVersionInfo {
50 /**
51 * Whether the version was known to satisfy its requirements (true).
52 */
53 isSatisfied: true;
54
55 /**
56 * Retrieved version.
57 */
58 version: string;
59
60 /**
61 * Requested version range of the package, if any.
62 */
63 wanted?: Wanted;
64}
65
66/**
67 * Negative result of checking a program version.
68 */
69interface UnsatisfiedVersionInfo {
70 /**
71 * Whether the version was known to satisfy its requirements (false).
72 */
73 isSatisfied: false;
74
75 /**
76 * Whether the program version was unable to be found.
77 */
78 notfound?: boolean;
79
80 /**
81 * Retrieved version, if available.
82 */
83 version?: string;
84
85 /**
86 * Requested version range of the package, if any.
87 */
88 wanted?: Wanted;
89}
90
91/**
92 * Result of checking a program version.
93 */
94type VersionInfo = SatisfiedVersionInfo | UnsatisfiedVersionInfo;
95
96/**
97 * Versions for each package, keyed by package name.
98 */
99interface VersionInfos {
100 [i: string]: VersionInfo;
101}
102
103/**
104 * Results from checking versions.
105 */
106interface Results {
107 /**
108 * Versions for each package, keyed by package name.
109 */
110 versions: VersionInfos;
111
112 /**
113 * Whether all versions were satisfied.
114 */
115 isSatisfied: boolean;
116}
117
118/**
119 * Handles results from checking versions.
120 *
121 * @param error Error from version checking, if any.
122 * @param results Results from checking versions.
123 */
124type OnComplete = (error: Error | null, results: Results) => void;
125
126/**
127 * Checks package versions.
128 *
129 * @param [wanted] Which versions of programs are required.
130 * @param onComplete Handles results from checking versions.
131 */
132declare function check(onComplete: OnComplete): void;
133declare function check(wanted: WantedVersions, onComplete: OnComplete): void;
134
135export = check;