refactor: migrate src/bun/index.ts from Bun.file()/Bun.write() to Filesystem module (#14147)
This commit is contained in:
@@ -66,14 +66,14 @@ export namespace BunProc {
|
|||||||
using _ = await Lock.write("bun-install")
|
using _ = await Lock.write("bun-install")
|
||||||
|
|
||||||
const mod = path.join(Global.Path.cache, "node_modules", pkg)
|
const mod = path.join(Global.Path.cache, "node_modules", pkg)
|
||||||
const pkgjson = Bun.file(path.join(Global.Path.cache, "package.json"))
|
const pkgjsonPath = path.join(Global.Path.cache, "package.json")
|
||||||
const parsed = await pkgjson.json().catch(async () => {
|
const parsed = await Filesystem.readJson<{ dependencies: Record<string, string> }>(pkgjsonPath).catch(async () => {
|
||||||
const result = { dependencies: {} }
|
const result = { dependencies: {} as Record<string, string> }
|
||||||
await Bun.write(pkgjson.name!, JSON.stringify(result, null, 2))
|
await Filesystem.writeJson(pkgjsonPath, result)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
const dependencies = parsed.dependencies ?? {}
|
if (!parsed.dependencies) parsed.dependencies = {} as Record<string, string>
|
||||||
if (!parsed.dependencies) parsed.dependencies = dependencies
|
const dependencies = parsed.dependencies
|
||||||
const modExists = await Filesystem.exists(mod)
|
const modExists = await Filesystem.exists(mod)
|
||||||
const cachedVersion = dependencies[pkg]
|
const cachedVersion = dependencies[pkg]
|
||||||
|
|
||||||
@@ -123,15 +123,16 @@ export namespace BunProc {
|
|||||||
// This ensures subsequent starts use the cached version until explicitly updated
|
// This ensures subsequent starts use the cached version until explicitly updated
|
||||||
let resolvedVersion = version
|
let resolvedVersion = version
|
||||||
if (version === "latest") {
|
if (version === "latest") {
|
||||||
const installedPkgJson = Bun.file(path.join(mod, "package.json"))
|
const installedPkg = await Filesystem.readJson<{ version?: string }>(path.join(mod, "package.json")).catch(
|
||||||
const installedPkg = await installedPkgJson.json().catch(() => null)
|
() => null,
|
||||||
|
)
|
||||||
if (installedPkg?.version) {
|
if (installedPkg?.version) {
|
||||||
resolvedVersion = installedPkg.version
|
resolvedVersion = installedPkg.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed.dependencies[pkg] = resolvedVersion
|
parsed.dependencies[pkg] = resolvedVersion
|
||||||
await Bun.write(pkgjson.name!, JSON.stringify(parsed, null, 2))
|
await Filesystem.writeJson(pkgjsonPath, parsed)
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user