File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
packages/auto-install/src Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -26,22 +26,24 @@ export interface RollupAutoInstallOptions {
2626const execAsync = promisify ( exec ) ;
2727
2828export default function autoInstall ( opts : RollupAutoInstallOptions = { } ) : Plugin {
29- const commands : Record < 'npm' | 'yarn' | 'pnpm' , string > = {
29+ const commands = {
3030 npm : 'npm install' ,
3131 pnpm : 'pnpm install' ,
3232 yarn : 'yarn add'
33- } ;
33+ } as const ;
34+ type PackageManager = keyof typeof commands ;
35+ const validManagers = Object . keys ( commands ) as PackageManager [ ] ;
36+
37+ // Keep the project-wide `defaults` pattern for option handling.
38+ const defaults = {
39+ manager : fs . existsSync ( 'yarn.lock' ) ? 'yarn' : fs . existsSync ( 'pnpm-lock.yaml' ) ? 'pnpm' : 'npm' ,
40+ pkgFile : 'package.json'
41+ } as const ;
3442
35- const manager = opts . manager
36- ? opts . manager
37- : fs . existsSync ( 'yarn.lock' )
38- ? 'yarn'
39- : fs . existsSync ( 'pnpm-lock.yaml' )
40- ? 'pnpm'
41- : 'npm' ;
43+ const options = { ...defaults , ...opts } ;
4244
43- const pkgFile = path . resolve ( opts . pkgFile || 'package.json' ) ;
44- const validManagers : Array < RollupAutoInstallOptions [ 'manager' ] > = [ 'npm' , 'yarn' , 'pnpm' ] ;
45+ const { manager } = options ;
46+ const pkgFile = path . resolve ( options . pkgFile ) ;
4547
4648 if ( ! validManagers . includes ( manager ) ) {
4749 throw new RangeError (
You can’t perform that action at this time.
0 commit comments