11import process from 'node:process' ;
2- import path from 'node:path' ;
32import fs from 'node:fs' ;
3+ import path from 'node:path' ;
4+ import { Buffer } from 'node:buffer' ;
45import { createLogUpdate } from 'log-update' ;
56import chalk from 'chalk' ;
6- import { checkConfigFile , formatDir , progressBar , readConfig } from '../mops.js' ;
7- import { getHighestVersion } from '../api/getHighestVersion.js' ;
8- import { storageActor } from '../api/actors.js' ;
9- import { parallel } from '../parallel.js' ;
10- import { installFromGithub } from '../vessel.js' ;
11- import { addCache , copyCache , isCached } from '../cache.js' ;
12- import { downloadFile , getPackageFilesInfo } from '../api/downloadPackageFiles.js' ;
13- import { installLocal } from './install-local.js' ;
14-
15- export async function install ( pkg : string , version = '' , { verbose = false , silent = false , dep = false , threads = 12 } = { } ) : Promise < Record < string , string > | false > {
7+ import { checkConfigFile , formatDir , progressBar , readConfig } from '../../mops.js' ;
8+ import { getHighestVersion } from '../../api/getHighestVersion.js' ;
9+ import { storageActor } from '../../api/actors.js' ;
10+ import { parallel } from '../../parallel.js' ;
11+ import { addCache , copyCache , isCached } from '../../cache.js' ;
12+ import { downloadFile , getPackageFilesInfo } from '../../api/downloadPackageFiles.js' ;
13+ import { installDeps } from './install-deps.js' ;
14+
15+ type InstallMopsDepOptions = {
16+ verbose ?: boolean ;
17+ silent ?: boolean ;
18+ dep ?: boolean ;
19+ threads ?: number ;
20+ } ;
21+
22+ export async function installMopsDep ( pkg : string , version = '' , { verbose, silent, dep, threads} : InstallMopsDepOptions = { } ) : Promise < Record < string , string > | false > {
23+ threads = threads || 12 ;
24+
1625 if ( ! checkConfigFile ( ) ) {
1726 return false ;
1827 }
@@ -95,31 +104,17 @@ export async function install(pkg : string, version = '', {verbose = false, sile
95104 }
96105
97106 // install dependencies
98- let ok = true ;
99107 let config = readConfig ( path . join ( dir , 'mops.toml' ) ) ;
100- let deps = Object . values ( config . dependencies || { } ) ;
101- let installedDeps = { } ;
102- for ( const { name, repo, version, path : depPath } of deps ) {
103- if ( repo ) {
104- await installFromGithub ( name , repo , { silent, verbose} ) ;
105- }
106- else {
107- let res = await ( depPath ? installLocal ( name , depPath , { silent, verbose} ) : install ( name , version , { silent, verbose} ) ) ;
108- if ( res ) {
109- installedDeps = { ...installedDeps , ...res } ;
110- }
111- else {
112- ok = false ;
113- }
114- }
108+ let res = await installDeps ( Object . values ( config . dependencies || { } ) , { silent, verbose} ) ;
109+
110+ if ( ! res ) {
111+ return false ;
115112 }
113+ let installedDeps = res ;
116114
115+ // add self to installed deps
117116 if ( ! alreadyInstalled ) {
118117 installedDeps = { ...installedDeps , [ pkg ] : version } ;
119118 }
120-
121- if ( ! ok ) {
122- return false ;
123- }
124119 return installedDeps ;
125120}
0 commit comments