1
1
import fs from 'node:fs' ;
2
2
import { deleteSync } from 'del' ;
3
3
import chalk from 'chalk' ;
4
- import { formatDir , formatGithubDir , checkConfigFile , readConfig , writeConfig } from '../mops.js' ;
4
+ import { checkConfigFile , getRootDir , readConfig , writeConfig } from '../mops.js' ;
5
5
import { Config , Dependency } from '../types.js' ;
6
6
import { 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' ;
7
10
8
11
type RemoveOptions = {
9
12
verbose ?: boolean ;
@@ -12,7 +15,6 @@ type RemoveOptions = {
12
15
lock ?: 'update' | 'ignore' ;
13
16
} ;
14
17
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
18
export async function remove ( name : string , { dev = false , verbose = false , dryRun = false , lock} : RemoveOptions = { } ) {
17
19
if ( ! checkConfigFile ( ) ) {
18
20
return ;
@@ -31,13 +33,12 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
31
33
}
32
34
33
35
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 [ ] ;
40
39
}
40
+ let cacheName = getDepCacheName ( name , value ) ;
41
+ let pkgDir = getDepCacheDir ( cacheName ) ;
41
42
let configFile = pkgDir + '/mops.toml' ;
42
43
if ( ! fs . existsSync ( configFile ) ) {
43
44
verbose && console . log ( 'no config' , configFile ) ;
@@ -78,16 +79,11 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
78
79
verbose && console . log ( `Ignored transitive dependency ${ depId } (other deps depend on it)` ) ;
79
80
continue ;
80
81
}
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 } ` ) ;
91
87
}
92
88
}
93
89
@@ -100,6 +96,7 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
100
96
}
101
97
dryRun || writeConfig ( config ) ;
102
98
99
+ await syncLocalCache ( ) ;
103
100
await checkIntegrity ( lock ) ;
104
101
105
102
console . log ( chalk . green ( 'Package removed ' ) + `${ name } = "${ version } "` ) ;
0 commit comments