Skip to content

Commit a7a85c9

Browse files
authored
fix(core): fix Windows managed install and bump ripgrep to 15.1.0 for ARM64 support (#23477)
1 parent 6e01786 commit a7a85c9

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

packages/opencode/src/file/ripgrep.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import { sanitizedProcessEnv } from "@/util/opencode-process"
1414
import { which } from "@/util/which"
1515

1616
const log = Log.create({ service: "ripgrep" })
17-
const VERSION = "14.1.1"
17+
const VERSION = "15.1.0"
1818
const PLATFORM = {
1919
"arm64-darwin": { platform: "aarch64-apple-darwin", extension: "tar.gz" },
2020
"arm64-linux": { platform: "aarch64-unknown-linux-gnu", extension: "tar.gz" },
2121
"x64-darwin": { platform: "x86_64-apple-darwin", extension: "tar.gz" },
2222
"x64-linux": { platform: "x86_64-unknown-linux-musl", extension: "tar.gz" },
2323
"arm64-win32": { platform: "aarch64-pc-windows-msvc", extension: "zip" },
24+
"ia32-win32": { platform: "i686-pc-windows-msvc", extension: "zip" },
2425
"x64-win32": { platform: "x86_64-pc-windows-msvc", extension: "zip" },
2526
} as const
2627

@@ -247,17 +248,20 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | ChildPro
247248
return { stdout, stderr, code }
248249
}, Effect.scoped)
249250

250-
const extract = Effect.fnUntraced(function* (archive: string, config: (typeof PLATFORM)[keyof typeof PLATFORM]) {
251+
const extract = Effect.fnUntraced(function* (
252+
archive: string,
253+
config: (typeof PLATFORM)[keyof typeof PLATFORM],
254+
target: string,
255+
) {
251256
const dir = yield* fs.makeTempDirectoryScoped({ directory: Global.Path.bin, prefix: "ripgrep-" })
252257

253258
if (config.extension === "zip") {
254259
const shell = (yield* Effect.sync(() => which("powershell.exe") ?? which("pwsh.exe"))) ?? "powershell.exe"
255260
const result = yield* run(shell, [
256261
"-NoProfile",
262+
"-NonInteractive",
257263
"-Command",
258-
"Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force",
259-
archive,
260-
dir,
264+
`$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -LiteralPath '${archive.replaceAll("'", "''")}' -DestinationPath '${dir.replaceAll("'", "''")}' -Force`,
261265
])
262266
if (result.code !== 0) {
263267
return yield* Effect.fail(error(result.stderr || result.stdout, result.code))
@@ -271,12 +275,19 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | ChildPro
271275
}
272276
}
273277

274-
return path.join(dir, `ripgrep-${VERSION}-${config.platform}`, process.platform === "win32" ? "rg.exe" : "rg")
278+
const extracted = path.join(dir, `ripgrep-${VERSION}-${config.platform}`, process.platform === "win32" ? "rg.exe" : "rg")
279+
if (!(yield* fs.isFile(extracted))) {
280+
return yield* Effect.fail(new Error(`ripgrep archive did not contain executable: ${extracted}`))
281+
}
282+
283+
yield* fs.copyFile(extracted, target)
284+
if (process.platform === "win32") return
285+
yield* fs.chmod(target, 0o755)
275286
}, Effect.scoped)
276287

277288
const filepath = yield* Effect.cached(
278289
Effect.gen(function* () {
279-
const system = yield* Effect.sync(() => which("rg"))
290+
const system = yield* Effect.sync(() => which(process.platform === "win32" ? "rg.exe" : "rg"))
280291
if (system && (yield* fs.isFile(system).pipe(Effect.orDie))) return system
281292

282293
const target = path.join(Global.Path.bin, `rg${process.platform === "win32" ? ".exe" : ""}`)
@@ -304,17 +315,8 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | ChildPro
304315
return yield* Effect.fail(new Error(`failed to download ripgrep from ${url}`))
305316
}
306317

307-
yield* fs.writeWithDirs(archive, new Uint8Array(bytes)).pipe(Effect.orDie)
308-
const extracted = yield* extract(archive, config)
309-
const exists = yield* fs.exists(extracted).pipe(Effect.orDie)
310-
if (!exists) {
311-
return yield* Effect.fail(new Error(`ripgrep archive did not contain executable: ${extracted}`))
312-
}
313-
314-
yield* fs.copyFile(extracted, target).pipe(Effect.orDie)
315-
if (process.platform !== "win32") {
316-
yield* fs.chmod(target, 0o755).pipe(Effect.orDie)
317-
}
318+
yield* fs.writeWithDirs(archive, new Uint8Array(bytes))
319+
yield* extract(archive, config, target)
318320
yield* fs.remove(archive, { force: true }).pipe(Effect.ignore)
319321
return target
320322
}),

0 commit comments

Comments
 (0)