Skip to content

Commit

Permalink
Move prefix initialization to initOptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 17, 2023
1 parent 70b1a12 commit ea6c88f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import mergeOptions from './lib/mergeOptions'
import programError from './lib/programError'
import runGlobal from './lib/runGlobal'
import runLocal from './lib/runLocal'
import packageManagers from './package-managers'
import { Index } from './types/IndexType'
import { Options } from './types/Options'
import { PackageFile } from './types/PackageFile'
Expand Down Expand Up @@ -283,15 +282,6 @@ export async function run(
await cacheClear(options)
}

if (!options.prefix) {
const defaultPrefix =
packageManagers[options.packageManager || '']?.defaultPrefix || packageManagers.npm.defaultPrefix!
const prefix = await defaultPrefix(options)
if (prefix) {
options.prefix = prefix
}
}

let timeout: NodeJS.Timeout | undefined
let timeoutPromise: Promise<void> = new Promise(() => null)
if (options.timeout) {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/initOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import isEqual from 'lodash/isEqual'
import propertyOf from 'lodash/propertyOf'
import cliOptions, { cliOptionsMap } from '../cli-options'
import { print } from '../lib/logging'
import packageManagers from '../package-managers'
import { FilterPattern } from '../types/FilterPattern'
import { Options } from '../types/Options'
import { RunOptions } from '../types/RunOptions'
Expand Down Expand Up @@ -188,6 +189,14 @@ async function initOptions(runOptions: RunOptions, { cli }: { cli?: boolean } =
// imply upgrade in interactive mode when json is not specified as the output
...(options.interactive && options.upgrade === undefined ? { upgrade: !json } : null),
packageManager,
...(options.prefix
? {
// use the npm prefix if the package manager does not define defaultPrefix
prefix: await (packageManagers[packageManager || '']?.defaultPrefix || packageManagers.npm.defaultPrefix!)(
options,
),
}
: null),
registryType: options.registryType || (options.registry?.endsWith('.json') ? 'json' : 'npm'),
}
resolvedOptions.cacher = await cacher(resolvedOptions)
Expand Down

0 comments on commit ea6c88f

Please sign in to comment.