MCPcopy Create free account
hub / github.com/anomalyco/opencode / pack

Function pack

packages/ui/script/pack.ts:7–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import path from "node:path"
6
7export async function pack() {
8 const original = await Bun.file("package.json").text()
9 const pkg = JSON.parse(original) as {
10 name: string
11 version: string
12 exports: Record<string, string | { types: string; import: string }>
13 }
14 const tarball = path.resolve(`${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`)
15
16 await $`bun run build`
17 pkg.exports = Object.fromEntries(
18 Object.entries(pkg.exports).map(([key, value]) => {
19 if (typeof value !== "string" || (!value.endsWith(".ts") && !value.endsWith(".tsx"))) return [key, value]
20 return [
21 key,
22 {
23 types: value.replace("./src/", "./dist/").replace(/\.tsx?$/, ".d.ts"),
24 import: value,
25 },
26 ]
27 }),
28 )
29
30 await rm(tarball, { force: true })
31 await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n")
32 try {
33 await $`bun pm pack`
34 return tarball
35 } finally {
36 await Bun.write("package.json", original)
37 }
38}
39
40if (import.meta.main) console.log(await pack())

Callers 2

publish.tsFile · 0.90
pack.tsFile · 0.70

Calls 4

fileMethod · 0.80
writeMethod · 0.80
textMethod · 0.65
rmFunction · 0.50

Tested by

no test coverage detected