@@ -24,9 +24,7 @@ const AdmZip = require('adm-zip'),
24
24
path = require ( 'path' ) ,
25
25
xml = require ( 'xml2js' ) ;
26
26
27
- const promise = require ( '../lib/promise' ) ,
28
- checkedCall = promise . checkedNodeCall ,
29
- io = require ( '../io' ) ;
27
+ const io = require ( '../io' ) ;
30
28
31
29
32
30
/**
@@ -48,25 +46,24 @@ class AddonFormatError extends Error {
48
46
* @param {string } extension Path to the extension to install, as either a xpi
49
47
* file or a directory.
50
48
* @param {string } dir Path to the directory to install the extension in.
51
- * @return {!promise. Promise. <string> } A promise for the add-on ID once
49
+ * @return {!Promise<string> } A promise for the add-on ID once
52
50
* installed.
53
51
*/
54
52
function install ( extension , dir ) {
55
53
return getDetails ( extension ) . then ( function ( details ) {
56
- function returnId ( ) { return details . id ; }
57
-
58
54
var dst = path . join ( dir , details . id ) ;
59
55
if ( extension . slice ( - 4 ) === '.xpi' ) {
60
56
if ( ! details . unpack ) {
61
- return io . copy ( extension , dst + '.xpi' ) . then ( returnId ) ;
57
+ return io . copy ( extension , dst + '.xpi' ) . then ( ( ) => details . id ) ;
62
58
} else {
63
- return checkedCall ( fs . readFile , extension ) . then ( function ( buff ) {
59
+ return Promise . resolve ( ) . then ( function ( ) {
64
60
// TODO: find an async library for inflating a zip archive.
65
- new AdmZip ( buff ) . extractAllTo ( dst , true ) ;
66
- } ) . then ( returnId ) ;
61
+ new AdmZip ( extension ) . extractAllTo ( dst , true ) ;
62
+ return details . id ;
63
+ } ) ;
67
64
}
68
65
} else {
69
- return io . copyDir ( extension , dst ) . then ( returnId ) ;
66
+ return io . copyDir ( extension , dst ) . then ( ( ) => details . id ) ;
70
67
}
71
68
} ) ;
72
69
}
@@ -86,7 +83,7 @@ var RdfRoot;
86
83
/**
87
84
* Extracts the details needed to install an add-on.
88
85
* @param {string } addonPath Path to the extension directory.
89
- * @return {!promise. Promise. <!AddonDetails> } A promise for the add-on details.
86
+ * @return {!Promise<!AddonDetails> } A promise for the add-on details.
90
87
*/
91
88
function getDetails ( addonPath ) {
92
89
return readManifest ( addonPath ) . then ( function ( doc ) {
@@ -143,34 +140,43 @@ function getDetails(addonPath) {
143
140
/**
144
141
* Reads the manifest for a Firefox add-on.
145
142
* @param {string } addonPath Path to a Firefox add-on as a xpi or an extension.
146
- * @return {!promise. Promise<!Object> } A promise for the parsed manifest.
143
+ * @return {!Promise<!Object> } A promise for the parsed manifest.
147
144
*/
148
145
function readManifest ( addonPath ) {
149
146
var manifest ;
150
147
151
148
if ( addonPath . slice ( - 4 ) === '.xpi' ) {
152
- manifest = checkedCall ( fs . readFile , addonPath ) . then ( function ( buff ) {
153
- var zip = new AdmZip ( buff ) ;
149
+ manifest = new Promise ( ( resolve , reject ) => {
150
+ let zip = new AdmZip ( addonPath ) ;
151
+
154
152
if ( ! zip . getEntry ( 'install.rdf' ) ) {
155
- throw new AddonFormatError (
156
- 'Could not find install.rdf in ' + addonPath ) ;
153
+ reject ( new AddonFormatError (
154
+ 'Could not find install.rdf in ' + addonPath ) ) ;
155
+ return ;
157
156
}
158
- var done = promise . defer ( ) ;
159
- zip . readAsTextAsync ( 'install.rdf' , done . fulfill ) ;
160
- return done . promise ;
157
+
158
+ zip . readAsTextAsync ( 'install.rdf' , resolve ) ;
161
159
} ) ;
162
160
} else {
163
- manifest = checkedCall ( fs . stat , addonPath ) . then ( function ( stats ) {
161
+ manifest = io . stat ( addonPath ) . then ( function ( stats ) {
164
162
if ( ! stats . isDirectory ( ) ) {
165
163
throw Error (
166
164
'Add-on path is niether a xpi nor a directory: ' + addonPath ) ;
167
165
}
168
- return checkedCall ( fs . readFile , path . join ( addonPath , 'install.rdf' ) ) ;
166
+ return io . read ( path . join ( addonPath , 'install.rdf' ) ) ;
169
167
} ) ;
170
168
}
171
169
172
170
return manifest . then ( function ( content ) {
173
- return checkedCall ( xml . parseString , content ) ;
171
+ return new Promise ( ( resolve , reject ) => {
172
+ xml . parseString ( content , ( err , data ) => {
173
+ if ( err ) {
174
+ reject ( err ) ;
175
+ } else {
176
+ resolve ( data ) ;
177
+ }
178
+ } ) ;
179
+ } ) ;
174
180
} ) ;
175
181
}
176
182
0 commit comments