Skip to content

Commit

Permalink
Make it so some actions don’t ping our inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 15, 2023
1 parent d588330 commit 4293cd2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/actions/platform-key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S pkgx deno run --allow-env --allow-read

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

let { options: { pkg, platform } } = await new Command()
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/stage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S pkgx deno run --allow-read --allow-env --allow-write

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

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

Expand Down
28 changes: 2 additions & 26 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Path, Package, PackageRequirement, utils, hooks, plumbing, Installation
const { flatmap, host } = utils
const { usePantry } = hooks
const { hydrate } = plumbing
import resolve_pkg from "./resolve-pkg.ts"

export interface Config {
pkg: Package
Expand Down Expand Up @@ -33,32 +34,7 @@ export interface ConfigPath {
}

export default async function config(arg?: string): Promise<Config> {
if (!arg) {
arg ||= Deno.env.get("BREWKIT_PKGJSON")
arg ||= Deno.env.get("BREWKIT_PKGSPEC")
arg ||= (await get_pantry_status())?.[0]
if (!arg) throw new Error(`usage: ${Deno.execPath()} <pkgspec>`)
}

const { pkg, constraint, path } = await (async (arg: string) => {
if (arg.startsWith("{")) {
const json = JSON.parse(arg)
const project = json.project
const version = new SemVer(json.version.raw)
const [found] = await usePantry().find(project)
return {
pkg: {project, version},
constraint: new semver.Range(`=${version}`),
path: found.path
}
} else {
const { constraint, project } = utils.pkg.parse(arg.trim())
const [found, ...rest] = await usePantry().find(project)
if (rest.length) throw new Error("ambiguous pkg spec")
const pkg = await usePantry().resolve({project: found.project, constraint})
return { constraint, path: found.path, pkg }
}
})(arg)
const { pkg, path, constraint } = await resolve_pkg(arg)

let pantry = path
for (let x = 0, N = pkg.project.split('/').length + 1; x < N; x++) {
Expand Down
42 changes: 42 additions & 0 deletions lib/resolve-pkg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Path, utils, hooks, SemVer, semver } from "pkgx"
const { usePantry } = hooks

export default async function(arg?: string) {
if (!arg) {
arg ||= Deno.env.get("BREWKIT_PKGJSON")
arg ||= Deno.env.get("BREWKIT_PKGSPEC")
arg ||= (await get_pantry_status())?.[0]
if (!arg) throw new Error(`usage: ${Deno.execPath()} <pkgspec>`)
}

const { pkg, constraint, path } = await (async (arg: string) => {
if (arg.startsWith("{")) {
const json = JSON.parse(arg)
const project = json.project
const version = new SemVer(json.version.raw)
const [found] = await usePantry().find(project)
return {
pkg: {project, version},
constraint: new semver.Range(`=${version}`),
path: found.path
}
} else {
const { constraint, project } = utils.pkg.parse(arg.trim())
const [found, ...rest] = await usePantry().find(project)
if (rest.length) throw new Error("ambiguous pkg spec")
const pkg = await usePantry().resolve({project: found.project, constraint})
return { constraint, path: found.path, pkg }
}
})(arg)

return {pkg, path, constraint}
}

async function get_pantry_status() {
const bkroot = new Path(new URL(import.meta.url).pathname).parent().parent()
const proc = new Deno.Command("bash", {args: [bkroot.join('bin/cmd/status').string], stdout: 'piped'}).spawn()
const [out, { success }] = await Promise.all([proc.output(), proc.status])
if (success) {
return new TextDecoder().decode(out.stdout).split(/\s+/).filter(x => x)
}
}

0 comments on commit 4293cd2

Please sign in to comment.