Skip to content

Commit

Permalink
refactor: replace minimist on netlify-lambda.ts (#6265)
Browse files Browse the repository at this point in the history
* refactor: replace minimist on netlify-lambda.ts

replace minimist with commander on netlify-lambda.ts

- replace minimist
- update code accordingly

* chore: remove dependency minimist

- remove dependency minimist no longer needed

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
hereje and kodiakhq[bot] authored Dec 19, 2023
1 parent 00ea7f1 commit a882392
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
"lodash": "4.17.21",
"log-symbols": "5.1.0",
"log-update": "5.0.1",
"minimist": "1.2.8",
"multiparty": "4.2.3",
"netlify": "13.1.11",
"netlify-headers-parser": "7.1.2",
Expand Down
20 changes: 12 additions & 8 deletions src/lib/functions/runtimes/js/builders/netlify-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from 'fs/promises'
import { resolve } from 'path'

import minimist from 'minimist'
import { program } from 'commander'

// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
import execa from '../../../../../utils/execa.js'
Expand All @@ -20,14 +20,18 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) {

for (const [key, script] of matchingScripts) {
// E.g. ["netlify-lambda", "build", "functions/folder"]
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
const match = minimist(script.split(' '), {
// these are all valid options for netlify-lambda
boolean: ['s', 'static'],
string: ['c', 'config', 'p', 'port', 'b', 'babelrc', 't', 'timeout'],
})
// these are all valid options for netlify-lambda
program
.option('-s, --static')
.option('-c, --config [file]')
.option('-p, --port [number]')
.option('-b, --babelrc [file]')
.option('-t, --timeout [delay]')

program.parse((script as string).split(' ') ?? [])

// We are not interested in 'netlify-lambda' and 'build' commands
const functionDirectories = match._.slice(2)
const functionDirectories = program.args.filter((arg) => !['netlify-lambda', 'build'].includes(arg))
if (functionDirectories.length === 1) {
const srcFiles = [resolve(functionDirectories[0])]

Expand Down

1 comment on commit a882392

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,399
  • Package size: 405 MB
  • Number of ts-expect-error directives: 1,291

Please sign in to comment.