INNER CODE UNIT · TypeScript
undoLinks
onejs/one · packages/lllink/src/index.ts:97
async function undoLinks() {
const backupDir = join(process.cwd(), 'node_modules', '.cache', 'lllink', 'moved')
let movedItems: string[]
try {
movedItems = await readdir(backupDir)
} catch {
console.info('Nothing to undo.')
return
}
for (const item of movedItems) {
const originalName = item.replace('__', '/')
const nmPath = join(process.cwd(), 'node_modules', ...originalName.split('/'))
await rm(nmPath, { recursive: true, force: true }).catch(() => {})
await rename(join(backupDir, item), nmPath).catch(() => {})
console.info(`Restored: ${originalName}`)
}
}