fix(build-node): preserve Bun linker for node-pty install

This commit is contained in:
LukeParkerDev
2026-04-01 08:40:12 +10:00
parent 5079bf863e
commit b870c734d3

View File

@@ -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)
@@ -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",