Skip to content

Commit 4293cd2

Browse files
committed
Make it so some actions don’t ping our inventory
1 parent d588330 commit 4293cd2

File tree

4 files changed

+46
-28
lines changed

4 files changed

+46
-28
lines changed

lib/actions/platform-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env -S pkgx deno run --allow-env --allow-read
22

33
import { Command } from "cliffy/command/mod.ts"
4-
import get_config from '../config.ts'
4+
import get_config from '../resolve-pkg.ts'
55
import { utils } from 'pkgx'
66

77
let { options: { pkg, platform } } = await new Command()

lib/actions/stage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env -S pkgx deno run --allow-read --allow-env --allow-write
22

33
import { hooks, Path } from "pkgx"
4-
import get_config from '../config.ts'
4+
import get_config from '../resolve-pkg.ts'
55

66
const config = await get_config(Deno.args[1])
77

lib/config.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Path, Package, PackageRequirement, utils, hooks, plumbing, Installation
33
const { flatmap, host } = utils
44
const { usePantry } = hooks
55
const { hydrate } = plumbing
6+
import resolve_pkg from "./resolve-pkg.ts"
67

78
export interface Config {
89
pkg: Package
@@ -33,32 +34,7 @@ export interface ConfigPath {
3334
}
3435

3536
export default async function config(arg?: string): Promise<Config> {
36-
if (!arg) {
37-
arg ||= Deno.env.get("BREWKIT_PKGJSON")
38-
arg ||= Deno.env.get("BREWKIT_PKGSPEC")
39-
arg ||= (await get_pantry_status())?.[0]
40-
if (!arg) throw new Error(`usage: ${Deno.execPath()} <pkgspec>`)
41-
}
42-
43-
const { pkg, constraint, path } = await (async (arg: string) => {
44-
if (arg.startsWith("{")) {
45-
const json = JSON.parse(arg)
46-
const project = json.project
47-
const version = new SemVer(json.version.raw)
48-
const [found] = await usePantry().find(project)
49-
return {
50-
pkg: {project, version},
51-
constraint: new semver.Range(`=${version}`),
52-
path: found.path
53-
}
54-
} else {
55-
const { constraint, project } = utils.pkg.parse(arg.trim())
56-
const [found, ...rest] = await usePantry().find(project)
57-
if (rest.length) throw new Error("ambiguous pkg spec")
58-
const pkg = await usePantry().resolve({project: found.project, constraint})
59-
return { constraint, path: found.path, pkg }
60-
}
61-
})(arg)
37+
const { pkg, path, constraint } = await resolve_pkg(arg)
6238

6339
let pantry = path
6440
for (let x = 0, N = pkg.project.split('/').length + 1; x < N; x++) {

lib/resolve-pkg.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Path, utils, hooks, SemVer, semver } from "pkgx"
2+
const { usePantry } = hooks
3+
4+
export default async function(arg?: string) {
5+
if (!arg) {
6+
arg ||= Deno.env.get("BREWKIT_PKGJSON")
7+
arg ||= Deno.env.get("BREWKIT_PKGSPEC")
8+
arg ||= (await get_pantry_status())?.[0]
9+
if (!arg) throw new Error(`usage: ${Deno.execPath()} <pkgspec>`)
10+
}
11+
12+
const { pkg, constraint, path } = await (async (arg: string) => {
13+
if (arg.startsWith("{")) {
14+
const json = JSON.parse(arg)
15+
const project = json.project
16+
const version = new SemVer(json.version.raw)
17+
const [found] = await usePantry().find(project)
18+
return {
19+
pkg: {project, version},
20+
constraint: new semver.Range(`=${version}`),
21+
path: found.path
22+
}
23+
} else {
24+
const { constraint, project } = utils.pkg.parse(arg.trim())
25+
const [found, ...rest] = await usePantry().find(project)
26+
if (rest.length) throw new Error("ambiguous pkg spec")
27+
const pkg = await usePantry().resolve({project: found.project, constraint})
28+
return { constraint, path: found.path, pkg }
29+
}
30+
})(arg)
31+
32+
return {pkg, path, constraint}
33+
}
34+
35+
async function get_pantry_status() {
36+
const bkroot = new Path(new URL(import.meta.url).pathname).parent().parent()
37+
const proc = new Deno.Command("bash", {args: [bkroot.join('bin/cmd/status').string], stdout: 'piped'}).spawn()
38+
const [out, { success }] = await Promise.all([proc.output(), proc.status])
39+
if (success) {
40+
return new TextDecoder().decode(out.stdout).split(/\s+/).filter(x => x)
41+
}
42+
}

0 commit comments

Comments
 (0)