mirror of
https://github.com/ivabus/pantry
synced 2025-06-08 08:20:32 +03:00
Refactor (#142)
This commit is contained in:
parent
54781e96e1
commit
c7ec7f150c
15 changed files with 91 additions and 110 deletions
|
@ -12,14 +12,12 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
--- */
|
||||
|
||||
import { Installation, parsePackageRequirement } from "types"
|
||||
import { Path } from "types"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import { run } from "utils"
|
||||
import useCache from "hooks/useCache.ts"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import { Installation } from "types"
|
||||
import { useCellar, useCache, useFlags } from "hooks"
|
||||
import { run, parse_pkg_requirement } from "utils"
|
||||
import { crypto } from "deno/crypto/mod.ts"
|
||||
import { encodeToString } from "encodeToString"
|
||||
import { encode } from "deno/encoding/hex.ts"
|
||||
import Path from "path"
|
||||
|
||||
const cellar = useCellar()
|
||||
const filesListName = 'files.txt'
|
||||
|
@ -33,7 +31,7 @@ if (import.meta.main) {
|
|||
const bottles: Path[] = []
|
||||
const checksums: Path[] = []
|
||||
const artifacts: Path[] = []
|
||||
for (const pkg of Deno.args.map(parsePackageRequirement)) {
|
||||
for (const pkg of Deno.args.map(parse_pkg_requirement)) {
|
||||
console.log({ bottling: { pkg } })
|
||||
|
||||
const installation = await cellar.resolve(pkg)
|
||||
|
@ -130,11 +128,9 @@ export async function walk(root: Path, body: (entry: Path) => Continuation): Pro
|
|||
}
|
||||
|
||||
async function sha256(file: Path): Promise<Path> {
|
||||
const file_contents = await Deno.readFile(file.string)
|
||||
const checksum = encodeToString(new Uint8Array(await crypto.subtle.digest("SHA-256", file_contents)))
|
||||
const checksum_contents = new TextEncoder().encode(`${checksum} ${file.basename()}`)
|
||||
const checksum_file = new Path(`${file.string}.sha256sum`)
|
||||
await Deno.writeFile(checksum_file.string, checksum_contents)
|
||||
|
||||
return checksum_file
|
||||
const sha = await Deno.open(file.string, { read: true })
|
||||
.then(file => crypto.subtle.digest("SHA-256", file.readable))
|
||||
.then(buf => new TextDecoder().decode(encode(new Uint8Array(buf))))
|
||||
const text = `${sha} ${file.basename()}`
|
||||
return new Path(`${file}.sha256sum`).write({ text })
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
--- */
|
||||
|
||||
import { Path } from "types"
|
||||
import Path from "path"
|
||||
import { undent } from "utils"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import { useFlags } from "hooks"
|
||||
|
||||
useFlags()
|
||||
|
||||
|
|
|
@ -12,17 +12,18 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import usePantry from "hooks/usePantry.ts"
|
||||
import { usePantry } from "hooks"
|
||||
import build from "./build/build.ts"
|
||||
import { Package, parsePackageRequirement, semver } from "types"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import { Package } from "types"
|
||||
import { parse_pkg_requirement } from "utils"
|
||||
import { useFlags, useCellar } from "hooks"
|
||||
import * as semver from "semver"
|
||||
|
||||
useFlags()
|
||||
|
||||
const pantry = usePantry()
|
||||
const cellar = useCellar()
|
||||
const dry = Deno.args.map(parsePackageRequirement)
|
||||
const dry = Deno.args.map(parse_pkg_requirement)
|
||||
const gha = !!Deno.env.get("GITHUB_ACTIONS")
|
||||
const group_it = gha && dry.length > 1
|
||||
const rv: Package[] = []
|
||||
|
@ -39,7 +40,7 @@ for (const pkgrq of dry) {
|
|||
const pkg = { project: pkgrq.project, version }
|
||||
|
||||
if (group_it) {
|
||||
console.log("::group::", `${pkg.project}@${pkg.version}`)
|
||||
console.log("::group::", `${pkg.project}=${pkg.version}`)
|
||||
} else {
|
||||
console.log({ building: pkgrq.project })
|
||||
}
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
import useSourceUnarchiver from "hooks/useSourceUnarchiver.ts"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import usePantry from "hooks/usePantry.ts"
|
||||
import useCache from "hooks/useCache.ts"
|
||||
import { lvl1 as link } from "prefab/link.ts"
|
||||
import { Installation, Package, Path, semver } from "types"
|
||||
import usePlatform from "hooks/usePlatform.ts"
|
||||
import hydrate from "prefab/hydrate.ts"
|
||||
import { useSourceUnarchiver, useCellar, usePantry, useCache } from "hooks"
|
||||
import { link, hydrate } from "prefab"
|
||||
import { Installation, Package } from "types"
|
||||
import useShellEnv, { expand } from "hooks/useShellEnv.ts"
|
||||
import { run, undent } from "utils"
|
||||
import { run, undent, host } from "utils"
|
||||
import fix_pkg_config_files from "./fix-pkg-config-files.ts"
|
||||
import fix_linux_rpaths from "./fix-linux-rpaths.ts"
|
||||
import Path from "path"
|
||||
import * as semver from "semver"
|
||||
|
||||
const cellar = useCellar()
|
||||
const pantry = usePantry()
|
||||
const { platform } = usePlatform()
|
||||
const { platform } = host()
|
||||
|
||||
export default async function _build(pkg: Package) {
|
||||
const [deps, wet] = await calc_deps()
|
||||
|
@ -33,6 +30,7 @@ export default async function _build(pkg: Package) {
|
|||
const deps = await pantry.getDeps(pkg)
|
||||
const wet = await hydrate([...deps.runtime, ...deps.build], pkg => pantry.getDeps(pkg).then(x => x.runtime))
|
||||
deps.runtime.push(...wet.pkgs)
|
||||
// deno-lint-ignore no-explicit-any
|
||||
function tuplize<T extends any[]>(...elements: T) { return elements }
|
||||
return tuplize(deps, wet)
|
||||
}
|
||||
|
@ -49,10 +47,11 @@ export default async function _build(pkg: Package) {
|
|||
async function should_clean() {
|
||||
// only required as we aren't passing everything into hydrate
|
||||
const depends_on_self = () => deps.build.some(x => x.project === pkg.project)
|
||||
const wet_dep = () => wet.pkgs.some(x => x.project === pkg.project)
|
||||
|
||||
// provided this package doesn't transitively depend on itself (yes this happens)
|
||||
// clean out the destination prefix first
|
||||
if (!wet.bootstrap_required.has(pkg.project) && !depends_on_self()) {
|
||||
if (!wet.bootstrap_required.has(pkg.project) && !depends_on_self() && !wet_dep()) {
|
||||
return await cellar.isInstalled(pkg)
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +98,7 @@ export default async function _build(pkg: Package) {
|
|||
}
|
||||
|
||||
async function fix_binaries(installation: Installation) {
|
||||
switch (usePlatform().platform) {
|
||||
switch (host().platform) {
|
||||
case 'darwin':
|
||||
await fix_macho(installation)
|
||||
break
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Installation } from "types"
|
||||
import { Path } from "types"
|
||||
|
||||
import Path from "path"
|
||||
|
||||
export default async function fix_pkg_config_files(installation: Installation) {
|
||||
for await (const pcfile of find_pkg_config_files(installation)) {
|
||||
|
|
|
@ -9,10 +9,10 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { PackageRequirement, parsePackageRequirement } from "types"
|
||||
import usePantry from "hooks/usePantry.ts"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import hydrate from "prefab/hydrate.ts"
|
||||
import { PackageRequirement } from "types"
|
||||
import { usePantry, useFlags } from "hooks"
|
||||
import { hydrate } from "prefab"
|
||||
import { parse_pkg_requirement } from "utils"
|
||||
|
||||
const pantry = usePantry()
|
||||
|
||||
|
@ -29,10 +29,10 @@ const get_deps = async (pkg: PackageRequirement) => {
|
|||
}
|
||||
}
|
||||
|
||||
const dry = Deno.args.compactMap(arg => !arg.startsWith('-') && parsePackageRequirement(arg))
|
||||
const dry = Deno.args.compact_map(arg => !arg.startsWith('-') && parse_pkg_requirement(arg))
|
||||
const explicit = new Set(dry.map(x=>x.project))
|
||||
const wet = await hydrate(dry, get_deps)
|
||||
const gas = wet.pkgs.compactMap(({project}) => {
|
||||
const gas = wet.pkgs.compact_map(({project}) => {
|
||||
if (Deno.args.includes('-i')) {
|
||||
return project
|
||||
} else if (!explicit.has(project)){
|
||||
|
|
|
@ -12,13 +12,10 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import usePantry from "hooks/usePantry.ts"
|
||||
import useCache from "hooks/useCache.ts"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import useSourceUnarchiver from "hooks/useSourceUnarchiver.ts"
|
||||
import { parsePackageRequirement, semver } from "types"
|
||||
import { usePantry, useCache, useCellar, useSourceUnarchiver } from "hooks"
|
||||
import { Command } from "cliffy/command/mod.ts"
|
||||
import { print } from "utils"
|
||||
import { print, parse_pkg_requirement } from "utils"
|
||||
import * as semver from "semver"
|
||||
|
||||
const { args } = await new Command()
|
||||
.name("tea-fetch-src")
|
||||
|
@ -26,7 +23,7 @@ const { args } = await new Command()
|
|||
.parse(Deno.args)
|
||||
|
||||
const pantry = usePantry()
|
||||
const req = parsePackageRequirement(args[0])
|
||||
const req = parse_pkg_requirement(args[0])
|
||||
const versions = await pantry.getVersions(req)
|
||||
const version = semver.maxSatisfying(versions, req.constraint)
|
||||
if (!version) throw "no-version-found"
|
||||
|
|
|
@ -9,9 +9,8 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { parsePackageRequirement } from "types"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import { parse_pkg_requirement } from "utils"
|
||||
import { useCellar, useFlags } from "hooks"
|
||||
|
||||
useFlags()
|
||||
|
||||
|
@ -21,7 +20,7 @@ const cellar = useCellar()
|
|||
const desired_filter = !!Deno.env.get("INVERT")
|
||||
|
||||
const rv: string[] = []
|
||||
for (const pkg of Deno.args.map(parsePackageRequirement)) {
|
||||
for (const pkg of Deno.args.map(parse_pkg_requirement)) {
|
||||
const isInstalled = !!await cellar.isInstalled(pkg)
|
||||
if (isInstalled == desired_filter) {
|
||||
rv.push(pkg.project)
|
||||
|
|
|
@ -9,10 +9,9 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { S3 } from "s3";
|
||||
import { crypto } from "deno/crypto/mod.ts";
|
||||
import { readerFromStreamReader, readAll } from "deno/streams/conversion.ts";
|
||||
import { encodeToString } from "encodeToString";
|
||||
import { S3 } from "s3"
|
||||
import { Sha256 } from "deno/hash/sha256.ts"
|
||||
import { readerFromStreamReader, readAll } from "deno/streams/conversion.ts"
|
||||
|
||||
const s3 = new S3({
|
||||
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
||||
|
@ -32,7 +31,7 @@ for await (const pkg of bucket.listAllObjects({ batchSize: 200 })) {
|
|||
const contents = await readAll(readerFromStreamReader(reader))
|
||||
|
||||
const basename = pkg.key.split("/").pop()
|
||||
const sha256sum = encodeToString(new Uint8Array(await crypto.subtle.digest("SHA-256", contents)))
|
||||
const sha256sum = new Sha256().update(contents).toString()
|
||||
const body = new TextEncoder().encode(`${sha256sum} ${basename}`)
|
||||
|
||||
await bucket.putObject(`${pkg.key}.sha256sum`, body);
|
||||
|
|
|
@ -13,7 +13,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";
|
||||
import { Inventory } from "hooks/useInventory.ts"
|
||||
|
||||
const s3 = new S3({
|
||||
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
||||
|
@ -61,7 +61,7 @@ bucket.putObject("versions.json", json)
|
|||
|
||||
// CSV: project,platform,arch,version
|
||||
|
||||
const csvData = te.encode(await csv(flat, ["project", "platform", "arch", "version"]))
|
||||
const csvData = te.encode(csv(flat, { columns: ["project", "platform", "arch", "version"]}))
|
||||
|
||||
bucket.putObject("versions.csv", csvData)
|
||||
|
||||
|
|
|
@ -11,9 +11,8 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { Path } from "types"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import Path from "path"
|
||||
import { useFlags, useCellar } from "hooks"
|
||||
|
||||
const prefix = new Path(`${useCellar().prefix}/tea.xyz/var/pantry/projects`)
|
||||
|
||||
|
|
|
@ -16,10 +16,9 @@ args:
|
|||
// does a full hydration, but only returns ordered, dry packages
|
||||
|
||||
|
||||
import { parsePackageRequirement } from "types"
|
||||
import hydrate from "prefab/hydrate.ts"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import usePantry from "../src/hooks/usePantry.ts"
|
||||
import { parse_pkg_requirement } from "utils"
|
||||
import { usePantry, useFlags } from "hooks"
|
||||
import { hydrate } from "prefab"
|
||||
|
||||
const flags = useFlags()
|
||||
const pantry = usePantry()
|
||||
|
@ -27,7 +26,7 @@ const pantry = usePantry()
|
|||
const dry = Deno.args.map(project => {
|
||||
const match = project.match(/projects\/(.*)\/package.yml/)
|
||||
return match ? match[1] : project
|
||||
}).map(parsePackageRequirement)
|
||||
}).map(parse_pkg_requirement)
|
||||
|
||||
const wet = await hydrate(dry, async (pkg, dry) => {
|
||||
const deps = await pantry.getDeps(pkg)
|
||||
|
|
|
@ -12,31 +12,25 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { parsePackage, semver, Path, PackageRequirement, parsePackageRequirement } from "types"
|
||||
import usePantry from "hooks/usePantry.ts"
|
||||
import { PackageRequirement } from "types"
|
||||
import { usePantry, useCellar, useFlags } from "hooks"
|
||||
import useShellEnv, { expand } from "hooks/useShellEnv.ts"
|
||||
import { run, undent } from "utils"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import useCellar from "hooks/useCellar.ts"
|
||||
import resolve from "prefab/resolve.ts"
|
||||
import install from "prefab/install.ts"
|
||||
import hydrate from "prefab/hydrate.ts"
|
||||
import { lvl1 as link } from "prefab/link.ts"
|
||||
import { run, undent, parse_pkg_requirement } from "utils"
|
||||
import { resolve, install, hydrate, link } from "prefab"
|
||||
import Path from "path"
|
||||
import * as semver from "semver"
|
||||
|
||||
const { debug, magic } = useFlags()
|
||||
const { debug } = useFlags()
|
||||
const cellar = useCellar()
|
||||
const pantry = usePantry()
|
||||
|
||||
const pkg = await (async () => {
|
||||
if (magic) {
|
||||
const project = Deno.args[0]
|
||||
const match = project.match(/projects\/(.+)\/package.yml/)
|
||||
const parsable = match ? match[1] : project
|
||||
const i = await cellar.resolve(parsePackageRequirement(parsable))
|
||||
return i.pkg
|
||||
} else {
|
||||
return parsePackage(Deno.args[0])
|
||||
}
|
||||
const project = Deno.args[0]
|
||||
const match = project.match(/projects\/(.+)\/package.yml/)
|
||||
const parsable = match ? match[1] : project
|
||||
const pkg = parse_pkg_requirement(parsable)
|
||||
const installed = await cellar.resolve(pkg)
|
||||
return installed.pkg
|
||||
})()
|
||||
|
||||
const self = {
|
||||
|
@ -101,7 +95,7 @@ async function install_if_needed(deps: PackageRequirement[]) {
|
|||
}
|
||||
const wet = await resolve(needed)
|
||||
for (const pkg of wet) {
|
||||
const installation = install(pkg)
|
||||
const installation = await install(pkg)
|
||||
await link(installation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,43 +10,42 @@ args:
|
|||
- --import-map={{ srcroot }}/import-map.json
|
||||
---*/
|
||||
|
||||
import { S3 } from "s3";
|
||||
import { crypto } from "deno/crypto/mod.ts";
|
||||
import useCache from "hooks/useCache.ts";
|
||||
import { encodeToString } from "encodeToString";
|
||||
import { readAll, readerFromStreamReader } from "deno/streams/mod.ts";
|
||||
import { S3 } from "s3"
|
||||
import { Sha256 } from "deno/hash/sha256.ts"
|
||||
import { useCache } from "hooks"
|
||||
import { readAll, readerFromStreamReader } from "deno/streams/mod.ts"
|
||||
|
||||
const s3 = new S3({
|
||||
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
||||
secretKey: Deno.env.get("AWS_SECRET_ACCESS_KEY")!,
|
||||
region: "us-east-1",
|
||||
});
|
||||
})
|
||||
|
||||
const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!);
|
||||
const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!)
|
||||
|
||||
for (const pkg of await useCache().ls()) {
|
||||
const key = useCache().s3Key(pkg)
|
||||
const bottle = useCache().bottle(pkg)
|
||||
|
||||
console.log({ checking: key });
|
||||
console.log({ checking: key })
|
||||
|
||||
const inRepo = await bucket.headObject(key)
|
||||
const repoChecksum = inRepo ? await checksum(`https://dist.tea.xyz/${key}.sha256sum`) : undefined
|
||||
|
||||
// path.read() returns a string; this is easier to get a UInt8Array
|
||||
const contents = await Deno.readFile(bottle.string);
|
||||
const sha256sum = encodeToString(new Uint8Array(await crypto.subtle.digest("SHA-256", contents)))
|
||||
const contents = await Deno.readFile(bottle.string)
|
||||
const sha256sum = new Sha256().update(contents).toString()
|
||||
|
||||
if (!inRepo || repoChecksum !== sha256sum) {
|
||||
const basename = key.split("/").pop()
|
||||
const body = new TextEncoder().encode(`${sha256sum} ${basename}`)
|
||||
|
||||
console.log({ uploading: key });
|
||||
console.log({ uploading: key })
|
||||
|
||||
await bucket.putObject(key, contents);
|
||||
await bucket.putObject(`${key}.sha256sum`, body);
|
||||
await bucket.putObject(key, contents)
|
||||
await bucket.putObject(`${key}.sha256sum`, body)
|
||||
|
||||
console.log({ uploaded: key });
|
||||
console.log({ uploaded: key })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ args:
|
|||
---*/
|
||||
|
||||
import { S3 } from "s3"
|
||||
import { parsePackage, Path } from "types"
|
||||
import useCache from "hooks/useCache.ts"
|
||||
import { Package, SemVer, semver } from "types"
|
||||
import useFlags from "hooks/useFlags.ts"
|
||||
import { parse_pkg } from "utils"
|
||||
import { useCache, useFlags } from "hooks"
|
||||
import { Package } from "types"
|
||||
import SemVer, * as semver from "semver"
|
||||
import { dirname, basename } from "deno/path/mod.ts"
|
||||
|
||||
useFlags()
|
||||
|
@ -31,7 +31,7 @@ const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!)
|
|||
|
||||
const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })()
|
||||
|
||||
const pkgs = args_get("pkgs").map(parsePackage)
|
||||
const pkgs = args_get("pkgs").map(parse_pkg)
|
||||
const bottles = args_get("bottles")
|
||||
const checksums = args_get("checksums")
|
||||
|
||||
|
@ -80,9 +80,9 @@ async function get_versions(pkg: Package): Promise<SemVer[]> {
|
|||
//NOTE if this is a new package then some empty results is expected
|
||||
const got = rsp
|
||||
?.contents
|
||||
?.compactMap(x => x.key)
|
||||
?.compact_map(x => x.key)
|
||||
.map(x => basename(x))
|
||||
.compactMap(semver.coerce) //FIXME coerce is too loose
|
||||
.compact_map(semver.coerce) //FIXME coerce is too loose
|
||||
?? []
|
||||
|
||||
// have to add pkg.version as put and get are not atomic
|
||||
|
|
Loading…
Reference in a new issue