-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (38 loc) · 1.2 KB
/
index.js
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
'use strict';
const every = require('array.prototype.every');
const fromEntries = require('object.fromentries');
const entries = require('object.entries');
const pacote = require('pacote');
const isString = /** @type {(str: unknown) => str is string} */ (str) => typeof str === 'string';
const { from } = Array;
/** @typedef {import('.').DeprecationsByVersion} DeprecationsByVersion */
/** @type {import('.')} */
module.exports = function deprecations(packageName, ...morePackageNames) {
if (arguments.length < 1) {
throw new TypeError('at least 1 package name is required');
}
if (!every(arguments, isString)) {
throw new TypeError('module names must all be strings');
}
const depEntries = Promise.all(from(
arguments,
/** @type {(name: string) => Promise<[name, DeprecationsByVersion]>} */ async (name) => {
const { versions } = await pacote.packument(name, { fullMetadata: true });
// eslint-disable-next-line no-extra-parens
const obj = /** @type {DeprecationsByVersion} */ (
fromEntries(entries(versions).map(([
version,
{ deprecated },
]) => [
version,
deprecated,
]))
);
return [
name,
obj,
];
},
));
return depEntries.then(fromEntries);
};