Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion packages/opencode/script/build-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@ import { fileURLToPath } from "url"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const dir = path.resolve(__dirname, "..")
const root = path.resolve(dir, "../..")

type Pkg = {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
workspaces?: unknown
}

type Lock = {
configVersion?: number
}

function json<T>(file: string) {
return JSON.parse(fs.readFileSync(file, "utf8")) as T
}

function mod(base: string, name: string) {
return path.join(base, "node_modules", ...name.split("/"))
}

function linker(): "hoisted" | "isolated" {
const rootPkg = json<Pkg>(path.join(root, "package.json"))
const pkg = json<Pkg>(path.join(dir, "package.json"))

for (const [name, ver] of Object.entries(pkg.dependencies ?? {})) {
if (ver.startsWith("workspace:")) continue
if (rootPkg.dependencies?.[name] || rootPkg.devDependencies?.[name]) continue

const inRoot = fs.existsSync(mod(root, name))
const inDir = fs.existsSync(mod(dir, name))

if (inRoot !== inDir) return inRoot ? "hoisted" : "isolated"
}

const lock = json<Lock>(path.join(root, "bun.lock"))
if (lock.configVersion === 0) return "hoisted"
return rootPkg.workspaces ? "isolated" : "hoisted"
}

process.chdir(dir)

Expand Down Expand Up @@ -41,7 +79,9 @@ const migrations = await Promise.all(
)
console.log(`Loaded ${migrations.length} migrations`)

await $`bun install --os="*" --cpu="*" @lydell/node-pty@1.2.0-beta.10`
const link = linker()

await $`bun install --linker=${link} --os="*" --cpu="*" @lydell/node-pty@1.2.0-beta.10`

await Bun.build({
target: "node",
Expand Down
Loading