11import fs from 'node:fs' ;
22import { deleteSync } from 'del' ;
33import chalk from 'chalk' ;
4- import { formatDir , formatGithubDir , checkConfigFile , readConfig , writeConfig } from '../mops.js' ;
4+ import { checkConfigFile , getRootDir , readConfig , writeConfig } from '../mops.js' ;
55import { Config , Dependency } from '../types.js' ;
66import { checkIntegrity } from '../integrity.js' ;
7+ import { getDepCacheDir , getDepCacheName } from '../cache.js' ;
8+ import path from 'node:path' ;
9+ import { syncLocalCache } from './install/sync-local-cache.js' ;
710
811type RemoveOptions = {
912 verbose ?: boolean ;
@@ -12,7 +15,6 @@ type RemoveOptions = {
1215 lock ?: 'update' | 'ignore' ;
1316} ;
1417
15- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1618export async function remove ( name : string , { dev = false , verbose = false , dryRun = false , lock} : RemoveOptions = { } ) {
1719 if ( ! checkConfigFile ( ) ) {
1820 return ;
@@ -31,13 +33,12 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
3133 }
3234
3335 function getTransitiveDependenciesOf ( name : string , version : string | undefined , repo ?: string ) {
34- let pkgDir = '' ;
35- if ( repo ) {
36- pkgDir = formatGithubDir ( name , repo ) ;
37- }
38- else if ( version ) {
39- pkgDir = formatDir ( name , version ) ;
36+ let value = version || repo ;
37+ if ( ! value ) {
38+ return [ ] ;
4039 }
40+ let cacheName = getDepCacheName ( name , value ) ;
41+ let pkgDir = getDepCacheDir ( cacheName ) ;
4142 let configFile = pkgDir + '/mops.toml' ;
4243 if ( ! fs . existsSync ( configFile ) ) {
4344 verbose && console . log ( 'no config' , configFile ) ;
@@ -78,16 +79,11 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
7879 verbose && console . log ( `Ignored transitive dependency ${ depId } (other deps depend on it)` ) ;
7980 continue ;
8081 }
81- let pkgDir ;
82- if ( dep . repo ) {
83- pkgDir = formatGithubDir ( dep . name , dep . repo ) ;
84- }
85- else if ( dep . version ) {
86- pkgDir = formatDir ( dep . name , dep . version ) ;
87- }
88- if ( pkgDir && fs . existsSync ( pkgDir ) ) {
89- dryRun || deleteSync ( [ `${ pkgDir } ` ] , { force : true } ) ;
90- verbose && console . log ( `Removed local cache ${ pkgDir } ` ) ;
82+ let cacheName = getDepCacheName ( dep . name , dep . version || dep . repo || '' ) ;
83+ let localCacheDir = path . join ( getRootDir ( ) , '.mops' , cacheName ) ;
84+ if ( localCacheDir && fs . existsSync ( localCacheDir ) ) {
85+ dryRun || deleteSync ( [ localCacheDir ] , { force : true } ) ;
86+ verbose && console . log ( `Removed local cache ${ localCacheDir } ` ) ;
9187 }
9288 }
9389
@@ -100,6 +96,7 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
10096 }
10197 dryRun || writeConfig ( config ) ;
10298
99+ await syncLocalCache ( ) ;
103100 await checkIntegrity ( lock ) ;
104101
105102 console . log ( chalk . green ( 'Package removed ' ) + `${ name } = "${ version } "` ) ;
0 commit comments