11#! /usr/bin/env node
22
3- import { readFileSync } from 'fs' ;
4- import { join } from 'path' ;
5-
63import npa from 'npm-package-arg' ;
74
8- import pargs from './pargs.mjs' ;
9-
10- const help = readFileSync ( join ( import . meta. dirname , './help.txt' ) , 'utf8' ) ;
5+ import pargs from 'pargs' ;
116
127const {
13- positionals,
8+ errors,
9+ help,
10+ positionals : [ specifier ] ,
1411 values : { before } ,
15- } = pargs ( help , import . meta. url , {
16- allowPositionals : true ,
12+ } = await pargs ( import . meta. filename , {
13+ allowPositionals : 1 ,
1714 options : {
1815 before : {
1916 type : 'string' ,
2017 } ,
2118 } ,
2219} ) ;
2320
24- const specifiers = positionals . slice ( 1 ) ;
25-
26- if ( specifiers . length !== 1 ) {
27- console . error ( 'You must provide exactly one specifier' ) ;
28- process . exit ( 1 ) ;
29- }
30-
3121if ( typeof before !== 'undefined' && typeof before !== 'string' ) {
32- console . error ( '`before` option must be a valid Date value' ) ;
33- process . exit ( 1 ) ;
22+ errors . push ( '`before` option must be a valid Date value' ) ;
3423}
3524
25+ await help ( ) ;
26+
3627let name , rawSpec ;
3728try {
38- ( { name, rawSpec } = npa ( specifiers [ 0 ] ) ) ;
29+ ( { name, rawSpec } = npa ( specifier ) ) ;
3930 if ( rawSpec === '*' ) {
4031 rawSpec = 'latest' ;
4132 }
@@ -51,7 +42,8 @@ import mockProperty from 'mock-property';
5142
5243// eslint-disable-next-line no-empty-function, no-extra-parens
5344const restore = mockProperty ( /** @type {Parameters<typeof mockProperty>[0] } */ ( /** @type {unknown } */ ( console ) ) , 'error' , { value ( ) { } } ) ;
54- const promise = hasTypes ( specifiers [ 0 ] , { before } ) ;
45+ // @ts -expect-error before is a string
46+ const promise = hasTypes ( specifier , { before } ) ;
5547
5648promise . finally ( ( ) => {
5749 restore ( ) ;
0 commit comments