@@ -63,36 +63,6 @@ interface ArboristTree {
6363 edgesOut : Map < string , { to ?: ArboristNode } >
6464}
6565
66- const reify = ( input : { dir : string ; add ?: string [ ] } ) =>
67- Effect . gen ( function * ( ) {
68- const { Arborist } = yield * Effect . promise ( ( ) => import ( "@npmcli/arborist" ) )
69- const arborist = new Arborist ( {
70- path : input . dir ,
71- binLinks : true ,
72- progress : false ,
73- savePrefix : "" ,
74- ignoreScripts : true ,
75- } )
76- return yield * Effect . tryPromise ( {
77- try : ( ) =>
78- arborist . reify ( {
79- add : input ?. add || [ ] ,
80- save : true ,
81- saveType : "prod" ,
82- } ) ,
83- catch : ( cause ) =>
84- new InstallFailedError ( {
85- cause,
86- add : input ?. add ,
87- dir : input . dir ,
88- } ) ,
89- } ) as Effect . Effect < ArboristTree , InstallFailedError >
90- } ) . pipe (
91- Effect . withSpan ( "Npm.reify" , {
92- attributes : input ,
93- } ) ,
94- )
95-
9666export const layer = Layer . effect (
9767 Service ,
9868 Effect . gen ( function * ( ) {
@@ -101,6 +71,36 @@ export const layer = Layer.effect(
10171 const fs = yield * FileSystem . FileSystem
10272 const flock = yield * EffectFlock . Service
10373 const directory = ( pkg : string ) => path . join ( global . cache , "packages" , sanitize ( pkg ) )
74+ const reify = ( input : { dir : string ; add ?: string [ ] } ) =>
75+ Effect . gen ( function * ( ) {
76+ yield * flock . acquire ( `npm-install:${ input . dir } ` )
77+ const { Arborist } = yield * Effect . promise ( ( ) => import ( "@npmcli/arborist" ) )
78+ const arborist = new Arborist ( {
79+ path : input . dir ,
80+ binLinks : true ,
81+ progress : false ,
82+ savePrefix : "" ,
83+ ignoreScripts : true ,
84+ } )
85+ return yield * Effect . tryPromise ( {
86+ try : ( ) =>
87+ arborist . reify ( {
88+ add : input ?. add || [ ] ,
89+ save : true ,
90+ saveType : "prod" ,
91+ } ) ,
92+ catch : ( cause ) =>
93+ new InstallFailedError ( {
94+ cause,
95+ add : input ?. add ,
96+ dir : input . dir ,
97+ } ) ,
98+ } ) as Effect . Effect < ArboristTree , InstallFailedError >
99+ } ) . pipe (
100+ Effect . withSpan ( "Npm.reify" , {
101+ attributes : input ,
102+ } ) ,
103+ )
104104
105105 const outdated = Effect . fn ( "Npm.outdated" ) ( function * ( pkg : string , cachedVersion : string ) {
106106 const response = yield * Effect . tryPromise ( {
@@ -130,7 +130,6 @@ export const layer = Layer.effect(
130130
131131 const add = Effect . fn ( "Npm.add" ) ( function * ( pkg : string ) {
132132 const dir = directory ( pkg )
133- yield * flock . acquire ( `npm-install:${ dir } ` )
134133
135134 const tree = yield * reify ( { dir, add : [ pkg ] } )
136135 const first = tree . edgesOut . values ( ) . next ( ) . value ?. to
@@ -145,8 +144,6 @@ export const layer = Layer.effect(
145144 )
146145 if ( ! canWrite ) return
147146
148- yield * flock . acquire ( `npm-install:${ dir } ` )
149-
150147 yield * Effect . gen ( function * ( ) {
151148 const nodeModulesExists = yield * afs . existsSafe ( path . join ( dir , "node_modules" ) )
152149 if ( ! nodeModulesExists ) {
0 commit comments