-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.mjs
More file actions
executable file
·55 lines (45 loc) · 1.24 KB
/
bin.mjs
File metadata and controls
executable file
·55 lines (45 loc) · 1.24 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
#! /usr/bin/env node
import npa from 'npm-package-arg';
import pargs from 'pargs';
const {
errors,
help,
positionals: [specifier],
values: { before },
} = await pargs(import.meta.filename, {
allowPositionals: 1,
options: {
before: {
type: 'string',
},
},
});
if (typeof before !== 'undefined' && typeof before !== 'string') {
errors.push('`before` option must be a valid Date value');
}
await help();
let name, rawSpec;
try {
({ name, rawSpec } = npa(specifier));
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() {} });
// @ts-expect-error before is a string
const promise = hasTypes(specifier, { 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'}`);
});