From 992435aaf8371dc784f9f3489e998e5c93451d18 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 17 Apr 2026 14:18:48 -0400 Subject: [PATCH] do not flock until reify --- packages/opencode/src/npm/effect.ts | 63 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/packages/opencode/src/npm/effect.ts b/packages/opencode/src/npm/effect.ts index 10b5ff179c..5968f14519 100644 --- a/packages/opencode/src/npm/effect.ts +++ b/packages/opencode/src/npm/effect.ts @@ -63,36 +63,6 @@ interface ArboristTree { edgesOut: Map } -const reify = (input: { dir: string; add?: string[] }) => - Effect.gen(function* () { - const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist")) - const arborist = new Arborist({ - path: input.dir, - binLinks: true, - progress: false, - savePrefix: "", - ignoreScripts: true, - }) - return yield* Effect.tryPromise({ - try: () => - arborist.reify({ - add: input?.add || [], - save: true, - saveType: "prod", - }), - catch: (cause) => - new InstallFailedError({ - cause, - add: input?.add, - dir: input.dir, - }), - }) as Effect.Effect - }).pipe( - Effect.withSpan("Npm.reify", { - attributes: input, - }), - ) - export const layer = Layer.effect( Service, Effect.gen(function* () { @@ -101,6 +71,36 @@ export const layer = Layer.effect( 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[] }) => + Effect.gen(function* () { + yield* flock.acquire(`npm-install:${input.dir}`) + const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist")) + const arborist = new Arborist({ + path: input.dir, + binLinks: true, + progress: false, + savePrefix: "", + ignoreScripts: true, + }) + return yield* Effect.tryPromise({ + try: () => + arborist.reify({ + add: input?.add || [], + save: true, + saveType: "prod", + }), + catch: (cause) => + new InstallFailedError({ + cause, + add: input?.add, + dir: input.dir, + }), + }) as Effect.Effect + }).pipe( + Effect.withSpan("Npm.reify", { + attributes: input, + }), + ) const outdated = Effect.fn("Npm.outdated")(function* (pkg: string, cachedVersion: string) { const response = yield* Effect.tryPromise({ @@ -130,7 +130,6 @@ export const layer = Layer.effect( const add = Effect.fn("Npm.add")(function* (pkg: string) { const dir = directory(pkg) - yield* flock.acquire(`npm-install:${dir}`) const tree = yield* reify({ dir, add: [pkg] }) const first = tree.edgesOut.values().next().value?.to @@ -145,8 +144,6 @@ export const layer = Layer.effect( ) if (!canWrite) return - yield* flock.acquire(`npm-install:${dir}`) - yield* Effect.gen(function* () { const nodeModulesExists = yield* afs.existsSafe(path.join(dir, "node_modules")) if (!nodeModulesExists) {