1
1
import { readFile } from 'fs/promises'
2
2
import { resolve } from 'path'
3
3
4
- import minimist from 'minimist '
4
+ import { program } from 'commander '
5
5
6
6
// @ts -expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
7
7
import execa from '../../../../../utils/execa.js'
@@ -20,14 +20,18 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) {
20
20
21
21
for ( const [ key , script ] of matchingScripts ) {
22
22
// E.g. ["netlify-lambda", "build", "functions/folder"]
23
- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
24
- const match = minimist ( script . split ( ' ' ) , {
25
- // these are all valid options for netlify-lambda
26
- boolean : [ 's' , 'static' ] ,
27
- string : [ 'c' , 'config' , 'p' , 'port' , 'b' , 'babelrc' , 't' , 'timeout' ] ,
28
- } )
23
+ // these are all valid options for netlify-lambda
24
+ program
25
+ . option ( '-s, --static' )
26
+ . option ( '-c, --config [file]' )
27
+ . option ( '-p, --port [number]' )
28
+ . option ( '-b, --babelrc [file]' )
29
+ . option ( '-t, --timeout [delay]' )
30
+
31
+ program . parse ( ( script as string ) . split ( ' ' ) ?? [ ] )
32
+
29
33
// We are not interested in 'netlify-lambda' and 'build' commands
30
- const functionDirectories = match . _ . slice ( 2 )
34
+ const functionDirectories = program . args . filter ( ( arg ) => ! [ 'netlify-lambda' , 'build' ] . includes ( arg ) )
31
35
if ( functionDirectories . length === 1 ) {
32
36
const srcFiles = [ resolve ( functionDirectories [ 0 ] ) ]
33
37
0 commit comments