-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repair.ts is now just a proxy for
pkg cellar --repair
- Loading branch information
Showing
2 changed files
with
3 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,3 @@ | ||
#!/usr/bin/env -S deno run -A | ||
#!/bin/sh | ||
|
||
import { hooks, semver, Installation, plumbing } from "tea" | ||
import { useConfig } from "hooks" | ||
const { useCellar } = hooks | ||
const { link } = plumbing | ||
|
||
if (import.meta.main) { | ||
useConfig() | ||
|
||
for (const project of Deno.args) { | ||
await repairLinks(project) | ||
} | ||
} | ||
|
||
export default async function repairLinks(project: string) { | ||
const cellar = useCellar() | ||
const installed = await cellar.ls(project) | ||
const shelf = cellar.shelf(project) | ||
|
||
for await (const [path, {isSymlink}] of shelf.ls()) { | ||
//FIXME shouldn't delete things we may not have created | ||
if (isSymlink) path.rm() | ||
} | ||
|
||
const majors: {[key: number]: Installation[]} = {} | ||
const minors: {[key: number]: Installation[]} = {} | ||
|
||
for (const installation of installed) { | ||
const {pkg: {version: v}} = installation | ||
majors[v.major] ??= [] | ||
majors[v.major].push(installation) | ||
minors[v.minor] ??= [] | ||
minors[v.minor].push(installation) | ||
} | ||
|
||
for (const arr of [minors, majors]) { | ||
for (const installations of Object.values(arr)) { | ||
const version = installations | ||
.map(({pkg: {version}}) => version) | ||
.sort(semver.compare) | ||
.slice(-1)[0] // safe bang since we have no empty arrays in above logic | ||
|
||
link({project, version}) //TODO link lvl2 is possible here | ||
} | ||
} | ||
} | ||
exec deno task run +tea.xyz/brewkit pkg cellar --repair "$@" |