do not flock until reify

This commit is contained in:
Dax Raad
2026-04-17 14:18:48 -04:00
parent 2f73e73e9d
commit 992435aaf8
+9 -12
View File
@@ -63,8 +63,17 @@ interface ArboristTree {
edgesOut: Map<string, { to?: ArboristNode }> edgesOut: Map<string, { to?: ArboristNode }>
} }
export const layer = Layer.effect(
Service,
Effect.gen(function* () {
const afs = yield* AppFileSystem.Service
const global = yield* Global.Service
const fs = yield* FileSystem.FileSystem
const flock = yield* EffectFlock.Service
const directory = (pkg: string) => path.join(global.cache, "packages", sanitize(pkg))
const reify = (input: { dir: string; add?: string[] }) => const reify = (input: { dir: string; add?: string[] }) =>
Effect.gen(function* () { Effect.gen(function* () {
yield* flock.acquire(`npm-install:${input.dir}`)
const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist")) const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist"))
const arborist = new Arborist({ const arborist = new Arborist({
path: input.dir, path: input.dir,
@@ -93,15 +102,6 @@ const reify = (input: { dir: string; add?: string[] }) =>
}), }),
) )
export const layer = Layer.effect(
Service,
Effect.gen(function* () {
const afs = yield* AppFileSystem.Service
const global = yield* Global.Service
const fs = yield* FileSystem.FileSystem
const flock = yield* EffectFlock.Service
const directory = (pkg: string) => path.join(global.cache, "packages", sanitize(pkg))
const outdated = Effect.fn("Npm.outdated")(function* (pkg: string, cachedVersion: string) { const outdated = Effect.fn("Npm.outdated")(function* (pkg: string, cachedVersion: string) {
const response = yield* Effect.tryPromise({ const response = yield* Effect.tryPromise({
try: () => fetch(`https://registry.npmjs.org/${pkg}`), try: () => fetch(`https://registry.npmjs.org/${pkg}`),
@@ -130,7 +130,6 @@ export const layer = Layer.effect(
const add = Effect.fn("Npm.add")(function* (pkg: string) { const add = Effect.fn("Npm.add")(function* (pkg: string) {
const dir = directory(pkg) const dir = directory(pkg)
yield* flock.acquire(`npm-install:${dir}`)
const tree = yield* reify({ dir, add: [pkg] }) const tree = yield* reify({ dir, add: [pkg] })
const first = tree.edgesOut.values().next().value?.to const first = tree.edgesOut.values().next().value?.to
@@ -145,8 +144,6 @@ export const layer = Layer.effect(
) )
if (!canWrite) return if (!canWrite) return
yield* flock.acquire(`npm-install:${dir}`)
yield* Effect.gen(function* () { yield* Effect.gen(function* () {
const nodeModulesExists = yield* afs.existsSafe(path.join(dir, "node_modules")) const nodeModulesExists = yield* afs.existsSafe(path.join(dir, "node_modules"))
if (!nodeModulesExists) { if (!nodeModulesExists) {