fix(cli): add proper removal of symlink when uninstalling package

This commit is contained in:
Melvin Chia
2026-01-05 13:00:15 +08:00
parent c4048af9bd
commit eb8ffebd2c
2 changed files with 33 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
import fs from 'fs'
import path from 'path'
import { ROOT_DIR } from '@/constants/constants'
import { bunInstall } from '@/utils/commands'
import Logging from '@/utils/logging'
import normalizePackage from '@/utils/normalizePackage'
@@ -28,6 +30,9 @@ export async function uninstallLocaleHandler(langCode: string): Promise<void> {
Logging.info(`Uninstalling ${Logging.highlight(fullName)}...`)
const symlinkPath = path.join(ROOT_DIR, 'node_modules', fullName)
fs.rmSync(symlinkPath, { recursive: true, force: true })
fs.rmSync(targetDir, { recursive: true, force: true })
removeDependency(fullName)

View File

@@ -1,40 +1,49 @@
import fs from 'fs'
import path from 'path'
import { ROOT_DIR } from '@/constants/constants'
import { bunInstall } from '@/utils/commands'
import Logging from '@/utils/logging'
import { findPackageName, removeDependency } from '@/utils/packageJson'
import normalizePackage from '../../../utils/normalizePackage'
import generateRouteRegistry from '../functions/registry/generateRouteRegistry'
import generateSchemaRegistry from '../functions/registry/generateSchemaRegistry'
import generateServerRegistry from '../functions/registry/generateServerRegistry'
export async function uninstallModuleHandler(
moduleName: string
moduleNames: string[]
): Promise<void> {
const { targetDir, fullName } = normalizePackage(moduleName)
const uninstalled: string[] = []
if (!findPackageName(fullName)) {
Logging.actionableError(
`Module ${Logging.highlight(fullName)} not found`,
'Run "bun forge modules list" to see installed modules'
)
for (const moduleName of moduleNames) {
const { targetDir, fullName } = normalizePackage(moduleName)
return
if (!findPackageName(fullName)) {
Logging.actionableError(
`Module ${Logging.highlight(fullName)} not found`,
'Run "bun forge modules list" to see installed modules'
)
continue
}
Logging.info(`Uninstalling ${Logging.highlight(fullName)}...`)
removeDependency(fullName)
const symlinkPath = path.join(ROOT_DIR, 'node_modules', fullName)
fs.rmSync(symlinkPath, { recursive: true, force: true })
fs.rmSync(targetDir, { recursive: true, force: true })
uninstalled.push(moduleName)
Logging.success(`Uninstalled ${Logging.highlight(fullName)}`)
}
Logging.info(`Uninstalling ${Logging.highlight(fullName)}...`)
removeDependency(fullName)
fs.rmSync(targetDir, { recursive: true, force: true })
if (uninstalled.length === 0) {
return
}
bunInstall()
Logging.info('Regenerating registries...')
generateServerRegistry()
generateRouteRegistry()
generateSchemaRegistry()
Logging.success(`Uninstalled ${Logging.highlight(fullName)}`)
}