Skip to content

Commit 07fcde9

Browse files
committed
restore tea finds prefix if properly installed
1 parent fc9cd60 commit 07fcde9

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</p>
1717

1818

19-
# tea/cli 0.33.0
19+
# tea/cli 0.33.1
2020

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

src/hooks/useConfig.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ export default function(input?: Config): Config {
4949
}
5050

5151
export function ConfigDefault(flags?: Flags, arg0 = Deno.execPath(), env = Deno.env.toObject()): Config {
52+
if (!env['TEA_PREFIX']) {
53+
const shelf = new Path(arg0)
54+
.readlink() // resolves the leaf symlink (if any)
55+
.parent()
56+
.parent()
57+
.parent()
58+
59+
if (shelf.basename() == 'tea.xyz') {
60+
env['TEA_PREFIX'] = shelf.parent().string
61+
}
62+
}
63+
5264
const defaults = ConfigBaseDefault(env)
5365

5466
const {

tests/unit/useConfig.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import useConfig, { ConfigDefault } from "../../src/hooks/useConfig.ts"
2+
import { assertEquals } from "deno/testing/asserts.ts"
3+
import { _internals } from "tea/hooks/useConfig.ts"
4+
import { Path } from "tea"
5+
6+
Deno.test("prefix discovery", async () => {
7+
const tmp = new Path(await Deno.makeTempDir())
8+
const tea = tmp.join("tea.xyz/v1.2.3/bin").mkdir('p').join("tea").touch()
9+
const config = ConfigDefault(undefined, tea.string, {})
10+
assertEquals(config.prefix, tmp)
11+
})
12+
13+
Deno.test("prefix discovery via versioned symlink", async () => {
14+
const tmp = new Path(await Deno.makeTempDir())
15+
const shelf = tmp.join("tea.xyz")
16+
const keg = shelf.join("v1.2.3")
17+
18+
keg.join("bin").mkdir('p').join("tea").touch()
19+
20+
const v1 = shelf.join("v1").ln('s', { target: keg })
21+
const config = ConfigDefault(undefined, v1.join('bin/tea').string, {})
22+
assertEquals(config.prefix, tmp)
23+
})
24+
25+
Deno.test("prefix discovery via separate symlink", async () => {
26+
const tmp = new Path(await Deno.makeTempDir())
27+
const tea = tmp.join('tea').ln('s', { target: tmp.join("tea.xyz/v1.2.3/bin").mkdir('p').join("tea").touch() })
28+
29+
const config = ConfigDefault(undefined, tea.string, {})
30+
assertEquals(config.prefix, tmp)
31+
})
32+
33+
Deno.test("prefix discovery defaults to ~/.tea", async () => {
34+
const tmp = new Path(await Deno.makeTempDir())
35+
const tea = tmp.join('tea').touch()
36+
37+
const config = ConfigDefault(undefined, tea.string, {})
38+
assertEquals(config.prefix, Path.home().join(".tea"))
39+
})

0 commit comments

Comments
 (0)