Skip to content

Commit

Permalink
fix: filter out potential '--' from argv to get yargs to play nice
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Mar 21, 2024
1 parent 9602241 commit 8d29f0c
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions shared/packages/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export interface WorkforceConfig {

export async function getWorkforceConfig(): Promise<WorkforceConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...workforceArguments,
...processOptions,
}).argv
Expand Down Expand Up @@ -335,7 +335,7 @@ export interface HTTPServerConfig {
}
export async function getHTTPServerConfig(): Promise<HTTPServerConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...httpServerArguments,
...processOptions,
}).argv
Expand Down Expand Up @@ -378,7 +378,7 @@ export interface PackageManagerConfig {
}
export async function getPackageManagerConfig(): Promise<PackageManagerConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...packageManagerArguments,
...processOptions,
}).argv
Expand Down Expand Up @@ -419,7 +419,7 @@ export interface WorkerConfig {
}
export async function getWorkerConfig(): Promise<WorkerConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...workerArguments,
...processOptions,
}).argv
Expand Down Expand Up @@ -450,7 +450,7 @@ export interface AppContainerProcessConfig {
}
export async function getAppContainerConfig(): Promise<AppContainerProcessConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...appContainerArguments,
...processOptions,
}).argv
Expand Down Expand Up @@ -520,7 +520,7 @@ export async function getSingleAppConfig(): Promise<SingleAppConfig> {
// @ts-expect-error not optional
delete options.port

const argv = await Promise.resolve(yargs(process.argv.slice(2)).options(options).argv)
const argv = await Promise.resolve(yargs(getProcessArgv()).options(options).argv)

return {
process: getProcessConfig(argv),
Expand Down Expand Up @@ -551,7 +551,7 @@ export interface QuantelHTTPTransformerProxyConfig {
}
export async function getQuantelHTTPTransformerProxyConfig(): Promise<QuantelHTTPTransformerProxyConfig> {
const argv = await Promise.resolve(
yargs(process.argv.slice(2)).options({
yargs(getProcessArgv()).options({
...quantelHTTPTransformerProxyConfigArguments,
...processOptions,
}).argv
Expand All @@ -573,3 +573,23 @@ export async function getQuantelHTTPTransformerProxyConfig(): Promise<QuantelHTT
function defineArguments<O extends { [key: string]: Options }>(opts: O): O {
return opts
}

function getProcessArgv() {
// Note: process.argv typically looks like this:
// [
// 'C:\\Program Files\\nodejs\\node.exe',
// 'C:\\path\\to\\my\\package-manager\\apps\\single-app\\app\\dist\\index.js',
// '--',
// '--watchFiles=true',
// '--noCore=true',
// '--logLevel=debug'
// ]

// Remove the first two arguments
let args = process.argv.slice(2)

// If the first argument is just '--', remove it:
if (args[0] === '--') args = args.slice(1)

return args
}

0 comments on commit 8d29f0c

Please sign in to comment.