소스 검색

fix: work around Bun/Windows UV_FS_O_FILEMAP incompatibility in tar (#16853)

Luke Parker 5 달 전
부모
커밋
4f82248a68
1개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 14 3
      packages/opencode/src/npm/index.ts

+ 14 - 3
packages/opencode/src/npm/index.ts

@@ -1,3 +1,14 @@
+// Workaround: Bun on Windows does not support the UV_FS_O_FILEMAP flag that
+// the `tar` package uses for files < 512KB (fs.open returns EINVAL).
+// tar silently swallows the error and skips writing files, leaving only empty
+// directories. Setting __FAKE_PLATFORM__ makes tar fall back to the plain 'w'
+// flag. See tar's get-write-flag.js.
+// Must be set before @npmcli/arborist is imported since tar caches the flag
+// at module evaluation time — so we use a dynamic import() below.
+if (process.platform === "win32") {
+  process.env.__FAKE_PLATFORM__ = "linux"
+}
+
 import semver from "semver"
 import semver from "semver"
 import z from "zod"
 import z from "zod"
 import { NamedError } from "@opencode-ai/util/error"
 import { NamedError } from "@opencode-ai/util/error"
@@ -6,7 +17,6 @@ import { Lock } from "../util/lock"
 import { Log } from "../util/log"
 import { Log } from "../util/log"
 import path from "path"
 import path from "path"
 import { readdir } from "fs/promises"
 import { readdir } from "fs/promises"
-import { Arborist } from "@npmcli/arborist"
 
 
 export namespace Npm {
 export namespace Npm {
   const log = Log.create({ service: "npm" })
   const log = Log.create({ service: "npm" })
@@ -50,6 +60,7 @@ export namespace Npm {
     const hash = pkg
     const hash = pkg
     const dir = directory(hash)
     const dir = directory(hash)
 
 
+    const { Arborist } = await import("@npmcli/arborist")
     const arborist = new Arborist({
     const arborist = new Arborist({
       path: dir,
       path: dir,
       binLinks: true,
       binLinks: true,
@@ -84,14 +95,14 @@ export namespace Npm {
 
 
   export async function install(dir: string) {
   export async function install(dir: string) {
     log.info("installing dependencies", { dir })
     log.info("installing dependencies", { dir })
+    const { Arborist } = await import("@npmcli/arborist")
     const arb = new Arborist({
     const arb = new Arborist({
       path: dir,
       path: dir,
       binLinks: true,
       binLinks: true,
       progress: false,
       progress: false,
       savePrefix: "",
       savePrefix: "",
     })
     })
-    const result = await arb.reify()
-    console.log(result)
+    await arb.reify()
   }
   }
 
 
   export async function which(pkg: string) {
   export async function which(pkg: string) {