@@ -161,10 +161,6 @@ class Packages {
161161 const name = path . basename ( url . split ( '?' ) [ 0 ] )
162162 . replace ( / \. [ ^ / . ] + $ / , '' ) ;
163163
164- const stream = await bent ( ) ( url , null , {
165- headers : options . headers || { }
166- } ) ;
167-
168164 const userRoot = options . root || 'home:/.packages' ; // FIXME: Client-side
169165 const target = await realpath ( `${ userRoot } /${ name } ` , user ) ;
170166 const root = await realpath ( userRoot , user ) ;
@@ -178,10 +174,23 @@ class Packages {
178174 throw new Error ( 'System packages not yet implemented' ) ;
179175 }
180176
177+ const stream = await bent ( ) ( url , null , {
178+ headers : options . headers || { }
179+ } ) ;
180+
181181 await fs . mkdir ( target ) ;
182182 await extract ( stream , target ) ;
183183
184- const filenames = await fg ( root + '/*/metadata.json' ) ;
184+ // FIXME: npm packages have a 'package' subdirectory
185+ if ( ! await fs . exists ( path . resolve ( target , 'metadata.json' ) ) ) {
186+ await fs . unlink ( target ) ;
187+
188+ throw new Error ( 'Invalid package' ) ;
189+ }
190+
191+ // TODO: Check conflicts ?
192+
193+ const filenames = await fg ( root + '/*/metadata.json' ) ; // FIXME: Windows!
185194 const metadatas = await Promise . all ( filenames . map ( f => fs . readJson ( f ) ) ) ;
186195
187196 await fs . writeJson ( manifest , metadatas ) ;
0 commit comments