Skip to content

Commit

Permalink
Use published inventory for install (but not build)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider committed Jul 8, 2022
1 parent 52950bb commit 1d5f5b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
9 changes: 1 addition & 8 deletions scripts/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ args:
import { S3 } from "s3";
import { stringify as yaml } from "deno/encoding/yaml.ts"
import { stringify as csv } from "deno/encoding/csv.ts"
import { Inventory } from "../src/hooks/useInventory.ts";

const s3 = new S3({
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
Expand Down Expand Up @@ -75,11 +76,3 @@ for(const [project, platforms] of Object.entries(inventory)) {
}

//end

type Inventory = {
[project: string]: {
[platform: string]: {
[arch: string]: string[]
}
}
}
27 changes: 27 additions & 0 deletions src/hooks/useInventory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { RELOAD_POLICY } from "mxcl/deno-cache";
import { PackageRequirement, semver, SemVer } from "types"
import { GET } from "utils"
import usePlatform from "./usePlatform.ts";

interface Response {
getVersions(pkg: PackageRequirement): Promise<SemVer[]>
}

export interface Inventory {
[project: string]: {
[platform: string]: {
[arch: string]: string[]
}
}
}
export default function useInventory(): Response {
const getVersions = async ({ project, constraint }: PackageRequirement) => {
const { platform, arch } = usePlatform()
const releases = await GET<Inventory>(`https://s3.amazonaws.com/dist.tea.xyz/versions.json`, RELOAD_POLICY)

return releases[project]?.[platform]?.[arch]?.compactMap((version: string) => {
if (semver.satisfies(version, constraint)) { return semver.parse(version) }
})
}
return { getVersions }
}
6 changes: 3 additions & 3 deletions src/prefab/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// deno-lint-ignore-file no-cond-assign
import { Package, PackageRequirement, semver, Installation } from "types"
import usePantry from "hooks/usePantry.ts"
import useCellar from "hooks/useCellar.ts"
import useInventory from "hooks/useInventory.ts";

/// contract there are no duplicate projects

export default async function resolve(reqs: PackageRequirement[]): Promise<Package[]> {
const pantry = usePantry()
const inventory = useInventory()
const cellar = useCellar()
const rv: Package[] = []
let installation: Installation | undefined
Expand All @@ -16,7 +16,7 @@ export default async function resolve(reqs: PackageRequirement[]): Promise<Packa
// if we have a version that matches this constraint installed then we use it
rv.push(installation.pkg)
} else {
const versions = await pantry.getVersions({ project, constraint })
const versions = await inventory.getVersions({ project, constraint })
const version = semver.maxSatisfying(versions, constraint)
if (!version) throw "no-version"
rv.push({ version, project })
Expand Down

0 comments on commit 1d5f5b3

Please sign in to comment.