-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it so some actions don’t ping our inventory
- Loading branch information
Showing
4 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |