Skip to content

Commit e2c6142

Browse files
authored
use libtea (#589)
1 parent 9f4d3ae commit e2c6142

78 files changed

Lines changed: 817 additions & 4240 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.sync.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
paths:
66
- import-map.json
77
- src/hooks/app.sync.ts
8-
- src/hooks/useSync.ts
98
- src/prefab/install.ts
109
- .github/workflows/ci.sync.yml
1110

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- macos-latest
2525
steps:
2626
- uses: actions/checkout@v3
27-
- uses: ./.github/actions/cache # avoids sporadic 500s from deno’s CDN
2827
- uses: denoland/setup-deno@v1 # using ourself to install deno could compromise the tests
28+
- run: deno cache $(find . -name \*.ts)
2929
- run: deno task test --coverage=cov_profile
3030
- run: deno coverage cov_profile --lcov --exclude=tests/ --output=cov_profile.lcov
3131
- uses: coverallsapp/github-action@v1
@@ -48,7 +48,7 @@ jobs:
4848
steps:
4949
- uses: actions/checkout@v3
5050
- uses: teaxyz/setup@v0
51-
- run: deno lint src/*/**.ts
51+
- run: deno lint
5252

5353
typecheck:
5454
runs-on: ubuntu-latest

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.32.1
19+
# tea/cli 0.33.0
2020

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

deno.jsonc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"coverage" : "scripts/run_coverage.sh",
99
"typecheck": "deno check --unstable ./src/app.ts",
1010
// runs this source checkout for testing
11-
// NOTE this doesn't currently work due (our bug)
1211
"run": "deno run --unstable --allow-all src/app.ts",
1312
// compiles to ./tea
1413
"compile": "deno compile --allow-read --allow-write --allow-net --allow-run --allow-env --unstable --output $INIT_CWD/tea src/app.ts",
@@ -23,10 +22,22 @@
2322
]
2423
}
2524
},
25+
"lint": {
26+
"include": ["src/", "scripts/"]
27+
},
2628
"tea": {
2729
"dependencies": {
28-
"deno.land": "^1.31.1"
30+
"deno.land": "^1.33.3"
2931
}
3032
},
31-
"importMap": "import-map.json"
33+
"imports": {
34+
"is-what": "https://deno.land/x/is_what@v4.1.8/src/index.ts",
35+
"jsonc": "https://deno.land/x/jsonc_parser@v0.0.1/mod.ts",
36+
"tea": "https://raw.github.com/teaxyz/lib/v0.1.3/mod.ts",
37+
"tea/": "https://raw.github.com/teaxyz/lib/v0.1.3/src/",
38+
"outdent": "https://deno.land/x/outdent@v0.8.0/mod.ts",
39+
"cliffy/": "https://deno.land/x/cliffy@v0.25.7/",
40+
"deno/": "https://deno.land/std@0.187.0/",
41+
"hooks": "./src/hooks/index.ts"
42+
}
3243
}

import-map.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

scripts/repair.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env -S deno run -A
22

3-
import { init } from "../src/init.ts";
4-
import { useCellar } from "hooks"
5-
import { Installation } from "types"
6-
import { link } from "prefab"
7-
import * as semver from "semver"
3+
import { hooks, semver, Installation, prefab } from "tea"
4+
import { useConfig } from "hooks"
5+
const { useCellar } = hooks
6+
const { link } = prefab
87

98
if (import.meta.main) {
10-
init()
9+
useConfig()
1110

1211
for (const project of Deno.args) {
1312
await repairLinks(project)

src/app.dump.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { useEnv, usePrint } from "hooks"
2-
import { flatmap } from "utils"
3-
import { isPlainObject } from "is_what"
1+
import { useConfig, usePrint } from "hooks"
2+
import { isPlainObject } from "is-what"
3+
import { utils } from "tea"
4+
const { flatmap } = utils
45

56
//TODO should read from the shell configuration files to get originals properly
67
//TODO don’t wait on each print, instead chain the promises to be more time-efficient
@@ -11,7 +12,7 @@ interface Parameters {
1112
}
1213

1314
export default async function dump({ env, shell }: Parameters) {
14-
const { TEA_REWIND, getEnvAsObject } = useEnv();
15+
const { TEA_REWIND, obj: oldenv } = useConfig().env
1516
const { print } = usePrint()
1617

1718
const [set, unset]= (() => {
@@ -37,11 +38,9 @@ export default async function dump({ env, shell }: Parameters) {
3738
const is_env = env['SRCROOT']
3839

3940
if (is_env) {
40-
const oldenv = getEnvAsObject()
41-
4241
// first rewind the env to the original state
43-
if (oldenv['TEA_REWIND']) {
44-
const rewind = JSON.parse(oldenv['TEA_REWIND']) as { revert: Record<string, string>, unset: string[] }
42+
if (TEA_REWIND) {
43+
const rewind = JSON.parse(TEA_REWIND) as { revert: Record<string, string>, unset: string[] }
4544
delete oldenv['TEA_REWIND']
4645

4746
for (const key of rewind.unset) {
@@ -59,7 +58,7 @@ export default async function dump({ env, shell }: Parameters) {
5958
}
6059

6160
// now calculate the new rewind
62-
const TEA_REWIND = (() => {
61+
const new_TEA_REWIND = (() => {
6362
const revert: Record<string, string> = {}
6463
const unset: string[] = []
6564
for (const key of Object.keys(env)) {
@@ -79,7 +78,7 @@ export default async function dump({ env, shell }: Parameters) {
7978
for (const [key, value] of Object.entries(env)) {
8079
if (value) await print(set(key, value))
8180
}
82-
await print(set('TEA_REWIND', TEA_REWIND))
81+
await print(set('TEA_REWIND', new_TEA_REWIND))
8382

8483
} else {
8584
const unwind = flatmap(TEA_REWIND, JSON.parse) as { revert: Record<string, string>, unset: string[] }

src/app.exec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
import { pkg as pkgutils, TeaError, chuzzle } from "utils"
2-
import { ExitError, Installation } from "types"
3-
import { useEnv, useConfig, useRun } from "hooks"
4-
import { RunError } from "hooks/useRun.ts"
5-
import { gray, red, teal } from "hooks/useLogger.ts"
1+
import { useConfig, useRun, useLogger, RunError, Verbosity, ExitError } from "hooks"
2+
import { Installation, Path, utils, TeaError } from "tea"
63
import { basename } from "deno/path/mod.ts"
7-
import { isNumber } from "is_what"
8-
import Path from "path"
4+
import { isNumber } from "is-what"
95

106
export default async function(cmd: string[], env: Record<string, string>) {
11-
const { TEA_FORK_BOMB_PROTECTOR } = useEnv()
7+
const { TEA_FORK_BOMB_PROTECTOR } = useConfig().env
8+
const { red, teal } = useLogger()
129

1310
// ensure we cannot fork bomb the user since this is basically the worst thing tea/cli can do
14-
let nobomb = chuzzle(parseInt(TEA_FORK_BOMB_PROTECTOR ?? '0')) ?? 0
11+
let nobomb = parseInt(TEA_FORK_BOMB_PROTECTOR ?? '0').chuzzle() ?? 0
1512
env['TEA_FORK_BOMB_PROTECTOR'] = `${++nobomb}`
1613
if (nobomb > 20) throw new Error("FORK BOMB KILL SWITCH ACTIVATED")
1714

1815
try {
1916
await useRun({cmd, env})
2017
} catch (err) {
21-
const { debug } = useConfig()
18+
const debug = useConfig().modifiers.verbosity >= Verbosity.debug
2219
const arg0 = cmd?.[0]
2320

2421
if (err instanceof TeaError) {
@@ -44,8 +41,9 @@ export default async function(cmd: string[], env: Record<string, string>) {
4441
}
4542

4643
export async function repl(installations: Installation[], env: Record<string, string>) {
47-
const { SHELL } = useEnv()
48-
const pkgs_str = () => installations.map(({pkg}) => gray(pkgutils.str(pkg))).join(", ")
44+
const { SHELL } = useConfig().env
45+
const { gray } = useLogger()
46+
const pkgs_str = () => installations.map(({pkg}) => gray(utils.pkg.str(pkg))).join(", ")
4947

5048
// going to stderr so that we don’t potentially break (nonsensical) pipe scenarios, eg.
5149
// tea -E | env
@@ -84,7 +82,7 @@ export async function repl(installations: Installation[], env: Record<string, st
8482
}
8583

8684
try {
87-
await useRun({ cmd, env })
85+
await useRun({cmd, env})
8886
} catch (err) {
8987
if (err instanceof RunError) {
9088
throw new ExitError(err.code)

src/app.help.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { useConfig, usePrint } from "hooks"
2-
import { undent } from "utils"
1+
import { Verbosity } from "./hooks/useConfig.ts"
2+
import { usePrint } from "hooks"
3+
import undent from "outdent"
34

4-
export default async function help() {
5-
const { verbose } = useConfig()
5+
export default async function help(verbosity = Verbosity.normal) {
66
const { print } = usePrint()
77

8-
if (!verbose) {
8+
if (verbosity < Verbosity.loud) {
99
// 10| 20| 30| 40| 50| 60| 70| | 80|
1010
await print(undent`
1111
usage:
@@ -42,6 +42,7 @@ export default async function help() {
4242
--dry-run,-n don’t do anything, just print
4343
--keep-going,-k keep going as much as possible after errors
4444
--verbose,-v print version and then increase verbosity †
45+
--quiet,-q status messages are more concise
4546
--silent,-s no chat, no errors: only output the requested data
4647
--cd,-C,--chdir <dir> change directory first
4748
--chaste abstain from networking, installing packages, etc.

src/app.magic.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { basename } from "deno/path/mod.ts"
2-
import { undent } from "utils"
3-
import Path from "path"
4-
import { useEnv } from "./hooks/useConfig.ts"
2+
import { useConfig } from "hooks"
3+
import undent from "outdent"
4+
import { Path } from "tea"
55

66
export default function(self: Path, shell?: string) {
7-
const { SHELL } = useEnv()
7+
const { SHELL } = useConfig().env
88
shell ??= basename(SHELL ?? "unknown")
99
const d = self.parent()
1010

0 commit comments

Comments
 (0)