@@ -167,8 +167,6 @@ class Packages {
167
167
168
168
const userRoot = options . root ;
169
169
const target = await realpath ( `${ userRoot } /${ name } ` , user ) ;
170
- const root = await realpath ( userRoot , user ) ;
171
- const manifest = await realpath ( `${ userRoot } /metadata.json` , user ) ;
172
170
173
171
if ( await fs . exists ( target ) ) {
174
172
throw new Error ( 'Target already exists' ) ;
@@ -192,18 +190,58 @@ class Packages {
192
190
throw new Error ( 'Invalid package' ) ;
193
191
}
194
192
195
- // TODO: Check conflicts ?
193
+ await this . writeUserManifest ( userRoot , user ) ;
196
194
197
- const filenames = await fg ( root + '/*/metadata.json' ) ; // FIXME: Windows!
198
- const metadatas = await Promise . all ( filenames . map ( f => fs . readJson ( f ) ) ) ;
195
+ return {
196
+ reload : ! options . system
197
+ } ;
198
+ }
199
199
200
- await fs . writeJson ( manifest , metadatas ) ;
200
+ /**
201
+ * Uninstalls a package by name
202
+ * @param {string } name
203
+ * @param {InstallPackageOptions } options
204
+ * @param {object } user
205
+ */
206
+ async uninstallPackage ( name , options , user ) {
207
+ const { realpath} = this . core . make ( 'osjs/vfs' ) ;
208
+
209
+ if ( ! options . root ) {
210
+ throw new Error ( 'Missing package installation root path' ) ;
211
+ }
212
+
213
+ const userRoot = options . root ;
214
+ const target = await realpath ( `${ userRoot } /${ name } ` , user ) ;
215
+
216
+ if ( await fs . exists ( target ) ) {
217
+ await fs . remove ( target ) ;
218
+ await this . writeUserManifest ( userRoot , user ) ;
219
+ } else {
220
+ throw new Error ( 'Package not found in root directory' ) ;
221
+ }
201
222
202
223
return {
203
224
reload : ! options . system
204
225
} ;
205
226
}
206
227
228
+ /**
229
+ * Writes user installed package manifest
230
+ * @param {string } userRoot
231
+ * @param {object } user
232
+ */
233
+ async writeUserManifest ( userRoot , user ) {
234
+ const { realpath} = this . core . make ( 'osjs/vfs' ) ;
235
+
236
+ // TODO: Check conflicts ?
237
+ const root = await realpath ( userRoot , user ) ;
238
+ const manifest = await realpath ( `${ userRoot } /metadata.json` , user ) ;
239
+ const filenames = await fg ( root + '/*/metadata.json' ) ; // FIXME: Windows!
240
+ const metadatas = await Promise . all ( filenames . map ( f => fs . readJson ( f ) ) ) ;
241
+
242
+ await fs . writeJson ( manifest , metadatas ) ;
243
+ }
244
+
207
245
/**
208
246
* Reads package manifests
209
247
* @param {string[] } paths
0 commit comments