Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace minimist on netlify-lambda.ts #6265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading