Skip to content

Commit

Permalink
fix: don't mutate the commander singleton
Browse files Browse the repository at this point in the history
It was redefining the options over and over and over. The latest commander throws.
  • Loading branch information
serhalp committed Jan 23, 2025
1 parent 1f16094 commit 0d11dde
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 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 { program } from 'commander'
import { Command } from 'commander'

import execa from '../../../../../utils/execa.js'
import { fileExistsAsync } from '../../../../fs.js'
Expand All @@ -14,20 +14,21 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) {
return false
}

const program = new Command()
.option('-s, --static')
.option('-c, --config [file]')
.option('-p, --port [number]')
.option('-b, --babelrc [file]')
.option('-t, --timeout [delay]')

program.allowExcessArguments()

// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
const matchingScripts = Object.entries(scripts).filter(([, script]) => script.match(/netlify-lambda\s+build/))

for (const [key, script] of matchingScripts) {
// E.g. ["netlify-lambda", "build", "functions/folder"]
// 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.allowExcessArguments()
program.parse((script as string).split(' ') ?? [])

// We are not interested in 'netlify-lambda' and 'build' commands
Expand Down

0 comments on commit 0d11dde

Please sign in to comment.