@@ -161,10 +161,6 @@ class Packages {
161
161
const name = path . basename ( url . split ( '?' ) [ 0 ] )
162
162
. replace ( / \. [ ^ / . ] + $ / , '' ) ;
163
163
164
- const stream = await bent ( ) ( url , null , {
165
- headers : options . headers || { }
166
- } ) ;
167
-
168
164
const userRoot = options . root || 'home:/.packages' ; // FIXME: Client-side
169
165
const target = await realpath ( `${ userRoot } /${ name } ` , user ) ;
170
166
const root = await realpath ( userRoot , user ) ;
@@ -178,10 +174,23 @@ class Packages {
178
174
throw new Error ( 'System packages not yet implemented' ) ;
179
175
}
180
176
177
+ const stream = await bent ( ) ( url , null , {
178
+ headers : options . headers || { }
179
+ } ) ;
180
+
181
181
await fs . mkdir ( target ) ;
182
182
await extract ( stream , target ) ;
183
183
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!
185
194
const metadatas = await Promise . all ( filenames . map ( f => fs . readJson ( f ) ) ) ;
186
195
187
196
await fs . writeJson ( manifest , metadatas ) ;
0 commit comments