@@ -167,8 +167,6 @@ class Packages {
167167
168168 const userRoot = options . root ;
169169 const target = await realpath ( `${ userRoot } /${ name } ` , user ) ;
170- const root = await realpath ( userRoot , user ) ;
171- const manifest = await realpath ( `${ userRoot } /metadata.json` , user ) ;
172170
173171 if ( await fs . exists ( target ) ) {
174172 throw new Error ( 'Target already exists' ) ;
@@ -192,18 +190,58 @@ class Packages {
192190 throw new Error ( 'Invalid package' ) ;
193191 }
194192
195- // TODO: Check conflicts ?
193+ await this . writeUserManifest ( userRoot , user ) ;
196194
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+ }
199199
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+ }
201222
202223 return {
203224 reload : ! options . system
204225 } ;
205226 }
206227
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+
207245 /**
208246 * Reads package manifests
209247 * @param {string[] } paths
0 commit comments