Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bin/cmd/edit
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

set -eo pipefail

d="$(cd "$(dirname "$0")" && pwd)"

if test -z "$1"; then
if test -z "$PKGX_PANTRY_PATH"; then
echo "error: PKGX_PANTRY_PATH is not set" >&2
exit 1
fi
d="$(cd "$(dirname "$0")" && pwd)"

for x in $(echo "$PKGX_PANTRY_PATH" | tr ':' '\n'); do
if test -z "$PKGS" -a -d "$x"/.git; then
#^^^^^^^^^^^^^^^ stop at first match
PKGS=($(GIT_WORK_TREE="$x" "$d/status" --print-paths))
fi
done
else
PKGS=($(deno run --allow-read --allow-env - <<EoTS
PKGS="$(cd $d/../.. && deno run --allow-read --allow-env - "$@" <<EoTS
import { hooks } from "pkgx";
const pp = Deno.args.map(arg => hooks.usePantry().find(arg).then(x => x.map(y => y.path.string)));
const paths = await Promise.all(pp);
console.log(paths.flatMap(x => x).join("\n"));
console.log(paths.flat().map(x => x.replaceAll(" ", "\\\\ ")).join("\n"));
Deno.exit(0);
EoTS
))

echo "${PKGS[@]}"
)"
fi

if test -z "$EDITOR"; then
Expand Down Expand Up @@ -53,9 +53,9 @@ if test -z "$PKGS"; then
echo "usage: bk edit <pkgspec>" >&2
fi
exit 1
elif test "$EDITOR" = code; then
exec $EDITOR "$PKGX_PANTRY_PATH" "${PKGS[@]}"
elif test "$EDITOR" = code -a -n "$PKGX_PANTRY_PATH"; then
exec $EDITOR "$PKGX_PANTRY_PATH" ${PKGS[@]}
# ^^ be more useful
else
exec $EDITOR "${PKGS[@]}"
exec $EDITOR ${PKGS}
fi
92 changes: 62 additions & 30 deletions lib/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ const getPlatforms = async (pkg: Package | PackageRequirement) => {
return rv
}

const getRawDistributableURL = (yml: PlainObject) => {
if (isPlainObject(yml.distributable)) {
return validate.str(yml.distributable.url)
} else if (isString(yml.distributable)) {
return yml.distributable
} else if (yml.distributable === null || yml.distributable === undefined) {
const getRawDistributableURL = (dist: PlainObject) => {
if (isPlainObject(dist)) {
return validate.str(dist.url)
} else if (isString(dist)) {
return dist
} else if (dist === null || dist === undefined) {
return
} else {
throw new Error(`invalid distributable node: ${yml.distributable}`)
throw new Error(`invalid distributable node: ${dist}`)
}
}

Expand All @@ -93,30 +93,62 @@ const getDistributable = async (pkg: Package) => {
const moustaches = useMoustaches()

const yml = await hooks.usePantry().project(pkg).yaml()

if (yml.distributable?.git) {
console.warn("brewkit: using distributable.git instead of distributable.url is deprecated")
return getGitDistribution({ pkg, ...yml.distributable})
}
if (yml.distributable?.url?.startsWith("git")) {
return getGitDistribution({ pkg, ...yml.distributable})
const dists = isArray(yml.distributable) ? yml.distributable : [yml.distributable]

for (const dist of dists) {
if (!dist) continue
//FIXME: Add check for Git dists as well
if (dist.git) {
console.warn(
"brewkit: using distributable.git instead of distributable.url is deprecated",
)
return getGitDistribution({ pkg, ...dist })
}

if (dist.url?.startsWith("git")) {
return getGitDistribution({ pkg, ...dist })
}

let urlstr = getRawDistributableURL(dist)
if (!urlstr) continue

let v = pkg.version
const stripComponents = flatmap(dist["strip-components"], coerceNumber)

if (isPlainObject(dist)) {
if (dist.rewrite?.match) {
const v_raw = v.raw.replace(
new RegExp(dist.rewrite["match"], "gi"),
dist.rewrite["with"],
)
Object.assign(v, { raw: v_raw })
}

if (dist.if) {
const matched = new RegExp(dist.if).test(pkg.version.raw);
if (!matched) continue
}
}

urlstr = moustaches.apply(urlstr, [
...moustaches.tokenize.version(v),
...moustaches.tokenize.host(),
])

try {
const rsp = await fetch(urlstr, { method: "HEAD" })

if (rsp.status == 200) {
const url = new URL(urlstr)
return { url, ref: undefined, stripComponents, type: "url" }
} else {
console.warn(`brewkit: Could not fetch ${urlstr} [${rsp.status}]`)
}
} catch (err) {
console.warn(`brewkit: Could not fetch ${urlstr}\nError: ${err}`)
}
}

let urlstr = getRawDistributableURL(yml)
if (!urlstr) return
let stripComponents: number | undefined
if (isPlainObject(yml.distributable)) {
stripComponents = flatmap(yml.distributable["strip-components"], coerceNumber)
}

urlstr = moustaches.apply(urlstr, [
...moustaches.tokenize.version(pkg.version),
...moustaches.tokenize.host()
])

const url = new URL(urlstr)

return { url, ref: undefined, stripComponents, type: 'url' }
return;
}

// deno-lint-ignore no-explicit-any
Expand Down
5 changes: 3 additions & 2 deletions projects/toolchain.com/package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributable:
url: https://github.com/pkgxdev/brewkit/archive/refs/tags/v{{ version }}.tar.gz
strip-components: 1
- url: https://FAILURE.DOT.COM
- url: https://github.com/pkgxdev/brewkit/archive/refs/tags/v{{ version }}.tar.gz
strip-components: 1

versions:
github: pkgxdev/brewkit
Expand Down