Skip to content

Commit

Permalink
repair.ts is now just a proxy for pkg cellar --repair
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jun 28, 2023
1 parent 93138cf commit f0ad97f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</p>


# tea/cli 0.35.8
# tea/cli 0.36.0

`tea` puts the whole open source ecosystem at your fingertips:

Expand Down
48 changes: 2 additions & 46 deletions scripts/repair.ts
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 "$@"

0 comments on commit f0ad97f

Please sign in to comment.