Skip to content

Commit

Permalink
Filter out undefined options.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 16, 2023
1 parent 424937a commit aed727c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ export async function run(
if (!options.prefix) {
const defaultPrefix =
packageManagers[options.packageManager || '']?.defaultPrefix || packageManagers.npm.defaultPrefix!
options.prefix = await defaultPrefix(options)
const prefix = await defaultPrefix(options)
if (prefix) {
options.prefix = prefix
}
}

let timeout: NodeJS.Timeout | undefined
Expand Down
11 changes: 9 additions & 2 deletions src/lib/initOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Target } from '../types/Target'
import cacher from './cache'
import determinePackageManager from './determinePackageManager'
import exists from './exists'
import keyValueBy from './keyValueBy'
import programError from './programError'

function parseFilterExpression(filterExpression: string[] | undefined): string[] | undefined
Expand Down Expand Up @@ -191,13 +192,19 @@ async function initOptions(runOptions: RunOptions, { cli }: { cli?: boolean } =
}
resolvedOptions.cacher = await cacher(resolvedOptions)

// remove undefined values
const resolvedOptionsFiltered: Options = keyValueBy(
resolvedOptions as { [key: string]: Options[keyof Options] },
(key, value) => (value !== undefined ? { [key]: value } : null),
)

// print 'Using yarn/pnpm/etc' when autodetected
// use resolved options so that options.json is set
if (!options.packageManager && packageManager !== 'npm') {
print(resolvedOptions, `Using ${packageManager}`)
print(resolvedOptionsFiltered, `Using ${packageManager}`)
}

return resolvedOptions
return resolvedOptionsFiltered
}

export default initOptions

0 comments on commit aed727c

Please sign in to comment.