pantry/scripts/fetch.ts
Max Howell 55eb7dc5e4 fixes not incl runtime deps of build deps
Refactor build a bit. This was causing build failure for GHC on linux as the system perl didn't have something autoconf needed.

TODO: infuser shouldn't have perl installed!
2022-09-19 10:32:57 -04:00

46 lines
1.2 KiB
TypeScript
Executable file

#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-net
- --allow-run
- --allow-read
- --allow-write={{ tea.prefix }}
- --allow-env
- --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 { Command } from "cliffy/command/mod.ts"
import { print } from "utils"
const { args } = await new Command()
.name("tea-fetch-src")
.arguments("<pkgspec:string>")
.parse(Deno.args)
const pantry = usePantry()
const req = parsePackageRequirement(args[0])
const versions = await pantry.getVersions(req)
const version = semver.maxSatisfying(versions, req.constraint)
if (!version) throw "no-version-found"
const pkg = { project: req.project, version }; console.debug(pkg)
const dstdir = useCellar().mkpath(pkg).join("src")
const { url, stripComponents } = await pantry.getDistributable(pkg)
const { download } = useCache()
const zip = await download({ pkg, url, type: 'src' })
await useSourceUnarchiver().unarchive({
dstdir,
zipfile: zip,
stripComponents
})
await print(`${dstdir}\n`)