-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.mjs
executable file
·63 lines (50 loc) · 1.48 KB
/
bin.mjs
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
#! /usr/bin/env node
import { readFileSync } from 'fs';
import { join } from 'path';
import npa from 'npm-package-arg';
import pargs from './pargs.mjs';
const help = readFileSync(join(import.meta.dirname, './help.txt'), 'utf8');
const {
positionals,
values: { before },
} = pargs(help, import.meta.url, {
allowPositionals: true,
options: {
before: {
type: 'string',
},
},
});
const specifiers = positionals.slice(1);
if (specifiers.length !== 1) {
console.error('You must provide exactly one specifier');
process.exit(1);
}
if (typeof before !== 'undefined' && typeof before !== 'string') {
console.error('`before` option must be a valid Date value');
process.exit(1);
}
let name, rawSpec;
try {
({ name, rawSpec } = npa(specifiers[0]));
if (rawSpec === '*') {
rawSpec = 'latest';
}
} catch (e) {
// eslint-disable-next-line no-extra-parens
console.error(/** @type {Error} */ (e)?.message ?? 'Unknown error');
process.exit(1);
}
import hasTypes from './index.mjs';
import mockProperty from 'mock-property';
// eslint-disable-next-line no-empty-function, no-extra-parens
const restore = mockProperty(/** @type {Parameters<typeof mockProperty>[0]} */ (/** @type {unknown} */ (console)), 'error', { value() {} });
const promise = hasTypes(specifiers[0], { before });
promise.finally(() => {
restore();
}).catch((e) => {
console.error(e.message);
process.exit(1);
}).then((r) => {
console.log(`${name}@${rawSpec} ${typeof r === 'string' ? r : r ? 'integrated' : 'none'}`);
});