Skip to content

Commit

Permalink
all configurable PKGX_DIST_URL
Browse files Browse the repository at this point in the history
closes #71
  • Loading branch information
jhheider authored and mxcl committed Sep 6, 2024
1 parent 672b7e9 commit 4409fe4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface Config {
cache: Path
data: Path

dist: string

options: {
/// prefer xz or gz for bottle downloads
compression: 'xz' | 'gz'
Expand Down Expand Up @@ -53,6 +55,7 @@ export function ConfigDefault(env = Deno.env.toObject()): Config {
const pantries = env['PKGX_PANTRY_PATH']?.split(SEP).compact(x => flatmap(x.trim(), x => Path.abs(x) ?? Path.cwd().join(x))) ?? []
const cache = (flatmap(env["XDG_CACHE_HOME"], Path.abs) ?? platform_cache_default(home, env)).join("pkgx")
const data = (flatmap(env["XDG_DATA_HOME"], Path.abs) ?? platform_data_home_default(home, env)).join("pkgx")
const dist = env['PKGX_DIST_URL']?.trim() ?? 'https://dist.pkgx.dev'
const isCI = boolize(env['CI']) ?? false
const UserAgent = flatmap(getv(), v => `libpkgx/${v}`) ?? 'libpkgx'
//TODO prefer 'xz' on Linux (as well) if supported
Expand All @@ -63,6 +66,7 @@ export function ConfigDefault(env = Deno.env.toObject()): Config {
pantries,
cache,
data,
dist,
UserAgent,
options: {
compression,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useInventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SemVer from "../utils/semver.ts"
import useFetch from "./useFetch.ts"
import host from "../utils/host.ts"
import "../utils/misc.ts"
import useConfig from "./useConfig.ts";

export interface Inventory {
[project: string]: {
Expand All @@ -25,7 +26,7 @@ const select = async (rq: PackageRequirement | Package) => {

const get = async (rq: PackageRequirement | Package) => {
const { platform, arch } = host()
const url = new URL(`https://dist.pkgx.dev/${rq.project}/${platform}/${arch}/versions.txt`)
const url = new URL(`${useConfig().dist}/${rq.project}/${platform}/${arch}/versions.txt`)
const rsp = await useFetch(url)

if (!rsp.ok) {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useOffLicense.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Stowage } from "../types.ts"
import host from "../utils/host.ts"
import useConfig from "./useConfig.ts";

type Type = 's3'

Expand All @@ -24,5 +25,5 @@ function key(stowage: Stowage) {
}

function url(stowage: Stowage) {
return new URL(`https://dist.pkgx.dev/${key(stowage)}`)
return new URL(`${useConfig().dist}/${key(stowage)}`)
}

0 comments on commit 4409fe4

Please sign in to comment.