wip: fix type errors
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { Session } from "../../../session"
|
|
||||||
import { Snapshot } from "../../../snapshot"
|
import { Snapshot } from "../../../snapshot"
|
||||||
import { bootstrap } from "../../bootstrap"
|
import { bootstrap } from "../../bootstrap"
|
||||||
import { cmd } from "../cmd"
|
import { cmd } from "../cmd"
|
||||||
|
|||||||
@@ -123,15 +123,11 @@ export namespace Ripgrep {
|
|||||||
const state = lazy(async () => {
|
const state = lazy(async () => {
|
||||||
let filepath = Bun.which("rg")
|
let filepath = Bun.which("rg")
|
||||||
if (filepath) return { filepath }
|
if (filepath) return { filepath }
|
||||||
filepath = path.join(
|
filepath = path.join(Global.Path.bin, "rg" + (process.platform === "win32" ? ".exe" : ""))
|
||||||
Global.Path.bin,
|
|
||||||
"rg" + (process.platform === "win32" ? ".exe" : ""),
|
|
||||||
)
|
|
||||||
|
|
||||||
const file = Bun.file(filepath)
|
const file = Bun.file(filepath)
|
||||||
if (!(await file.exists())) {
|
if (!(await file.exists())) {
|
||||||
const platformKey =
|
const platformKey = `${process.arch}-${process.platform}` as keyof typeof PLATFORM
|
||||||
`${process.arch}-${process.platform}` as keyof typeof PLATFORM
|
|
||||||
const config = PLATFORM[platformKey]
|
const config = PLATFORM[platformKey]
|
||||||
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
|
if (!config) throw new UnsupportedPlatformError({ platform: platformKey })
|
||||||
|
|
||||||
@@ -140,8 +136,7 @@ export namespace Ripgrep {
|
|||||||
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
|
const url = `https://github.com/BurntSushi/ripgrep/releases/download/${version}/${filename}`
|
||||||
|
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
if (!response.ok)
|
if (!response.ok) throw new DownloadFailedError({ url, status: response.status })
|
||||||
throw new DownloadFailedError({ url, status: response.status })
|
|
||||||
|
|
||||||
const buffer = await response.arrayBuffer()
|
const buffer = await response.arrayBuffer()
|
||||||
const archivePath = path.join(Global.Path.bin, filename)
|
const archivePath = path.join(Global.Path.bin, filename)
|
||||||
@@ -166,33 +161,33 @@ export namespace Ripgrep {
|
|||||||
}
|
}
|
||||||
if (config.extension === "zip") {
|
if (config.extension === "zip") {
|
||||||
if (config.extension === "zip") {
|
if (config.extension === "zip") {
|
||||||
const zipFileReader = new ZipReader(new BlobReader(new Blob([await Bun.file(archivePath).arrayBuffer()])));
|
const zipFileReader = new ZipReader(new BlobReader(new Blob([await Bun.file(archivePath).arrayBuffer()])))
|
||||||
const entries = await zipFileReader.getEntries();
|
const entries = await zipFileReader.getEntries()
|
||||||
let rgEntry: any;
|
let rgEntry: any
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.filename.endsWith("rg.exe")) {
|
if (entry.filename.endsWith("rg.exe")) {
|
||||||
rgEntry = entry;
|
rgEntry = entry
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rgEntry) {
|
if (!rgEntry) {
|
||||||
throw new ExtractionFailedError({
|
throw new ExtractionFailedError({
|
||||||
filepath: archivePath,
|
filepath: archivePath,
|
||||||
stderr: "rg.exe not found in zip archive",
|
stderr: "rg.exe not found in zip archive",
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const rgBlob = await rgEntry.getData(new BlobWriter());
|
const rgBlob = await rgEntry.getData(new BlobWriter())
|
||||||
if (!rgBlob) {
|
if (!rgBlob) {
|
||||||
throw new ExtractionFailedError({
|
throw new ExtractionFailedError({
|
||||||
filepath: archivePath,
|
filepath: archivePath,
|
||||||
stderr: "Failed to extract rg.exe from zip archive",
|
stderr: "Failed to extract rg.exe from zip archive",
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
await Bun.write(filepath, await rgBlob.arrayBuffer())
|
||||||
|
await zipFileReader.close()
|
||||||
}
|
}
|
||||||
await Bun.write(filepath, await rgBlob.arrayBuffer());
|
|
||||||
await zipFileReader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await fs.unlink(archivePath)
|
await fs.unlink(archivePath)
|
||||||
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
|
if (!platformKey.endsWith("-win32")) await fs.chmod(filepath, 0o755)
|
||||||
@@ -208,17 +203,16 @@ export namespace Ripgrep {
|
|||||||
return filepath
|
return filepath
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function files(input: {
|
export async function files(input: { cwd: string; query?: string; glob?: string[]; limit?: number }) {
|
||||||
cwd: string
|
const commands = [`${$.escape(await filepath())} --files --follow --hidden --glob='!.git/*'`]
|
||||||
query?: string
|
|
||||||
glob?: string
|
if (input.glob) {
|
||||||
limit?: number
|
for (const g of input.glob) {
|
||||||
}) {
|
commands[0] += ` --glob='${g}'`
|
||||||
const commands = [
|
}
|
||||||
`${await filepath()} --files --hidden --glob='!.git/*' ${input.glob ? `--glob='${input.glob}'` : ``}`,
|
}
|
||||||
]
|
|
||||||
if (input.query)
|
if (input.query) commands.push(`${await Fzf.filepath()} --filter=${input.query}`)
|
||||||
commands.push(`${await Fzf.filepath()} --filter=${input.query}`)
|
|
||||||
if (input.limit) commands.push(`head -n ${input.limit}`)
|
if (input.limit) commands.push(`head -n ${input.limit}`)
|
||||||
const joined = commands.join(" | ")
|
const joined = commands.join(" | ")
|
||||||
const result = await $`${{ raw: joined }}`.cwd(input.cwd).nothrow().text()
|
const result = await $`${{ raw: joined }}`.cwd(input.cwd).nothrow().text()
|
||||||
@@ -325,18 +319,8 @@ export namespace Ripgrep {
|
|||||||
return lines.join("\n")
|
return lines.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function search(input: {
|
export async function search(input: { cwd: string; pattern: string; glob?: string[]; limit?: number }) {
|
||||||
cwd: string
|
const args = [`${await filepath()}`, "--json", "--hidden", "--glob='!.git/*'"]
|
||||||
pattern: string
|
|
||||||
glob?: string[]
|
|
||||||
limit?: number
|
|
||||||
}) {
|
|
||||||
const args = [
|
|
||||||
`${await filepath()}`,
|
|
||||||
"--json",
|
|
||||||
"--hidden",
|
|
||||||
"--glob='!.git/*'",
|
|
||||||
]
|
|
||||||
|
|
||||||
if (input.glob) {
|
if (input.glob) {
|
||||||
for (const g of input.glob) {
|
for (const g of input.glob) {
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ import { App } from "../app/app"
|
|||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import { Ripgrep } from "../file/ripgrep"
|
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import { Installation } from "../installation"
|
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export namespace Snapshot {
|
export namespace Snapshot {
|
||||||
|
|||||||
Reference in New Issue
Block a user