Skip to content

Commit

Permalink
Drop async (#116)
Browse files Browse the repository at this point in the history
* Drop async from addExtensions

* Drop async from deleteParallel

The callbacks were't followed anyway, so the code was unnecessary

* Drop async from _addonDetails

* Completely drop async
  • Loading branch information
fregante authored Jan 19, 2021
1 parent 60c1f61 commit 3429330
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 73 deletions.
98 changes: 27 additions & 71 deletions lib/firefox_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

var os = require('os'),
path = require('path'),
util = require('util'),
fs = require('fs-extra'),
// third-party
parseString = require('xml2js').parseString,
AdmZip = require('adm-zip'),
archiver = require('archiver'),
uuid = require('uuid'),
async = require('async'),
getID = require('jetpack-id'),
Finder = require('./profile_finder');

Expand Down Expand Up @@ -150,19 +150,6 @@ function FirefoxProfile(options) {
process.addListener('SIGINT', self.onSigInt);
}

function deleteParallel(files, cb) {
async.parallel(
files.map(function (file) {
return function (next) {
fs.remove(file, next);
};
}),
function () {
cb && cb();
}
);
}

FirefoxProfile.prototype._copy = function (profileDirectory, cb) {
fs.copy(
profileDirectory,
Expand Down Expand Up @@ -349,13 +336,11 @@ FirefoxProfile.prototype.addExtension = function (extension, cb) {
*/

FirefoxProfile.prototype.addExtensions = function (extensions, cb) {
var self = this,
functions = extensions.map(function (extension) {
return function (callback) {
self.addExtension(path.normalize(extension), callback);
};
});
async.parallel(functions, cb);
var addExtension = util.promisify(this.addExtension.bind(this));
var promises = extensions.map(extension =>
addExtension(path.normalize(extension))
);
util.callbackify(() => Promise.all(promises))(cb);
};

/**
Expand Down Expand Up @@ -467,7 +452,8 @@ FirefoxProfile.prototype.encoded = function (cb) {
zipStream.on('close', function () {
fs.readFile(path.join(tmpFolder, 'profile.zip'), function (err, content) {
cb(null, content.toString('base64'));
deleteParallel([path.join(tmpFolder, 'profile.zip'), tmpFolder]);
fs.remove(path.join(tmpFolder, 'profile.zip'));
fs.remove(tmpFolder);
});
});
archive.pipe(zipStream);
Expand Down Expand Up @@ -603,57 +589,27 @@ FirefoxProfile.prototype._installExtension = function (addon, cb) {
cb(new Error('FirefoxProfile: the addon id could not be found!'));
}
var addonPath = path.join(self.extensionsDir, path.sep, addonId);
async.series(
[
// creates extensionsDir
function (next) {
fs.exists(self.extensionsDir, function (exists) {
if (!exists) {
fs.mkdir(self.extensionsDir, function () {
next();
});
return;
}
// already exists
next();
});
},
function (next) {
if (!unpack && xpiFile) {
fs.copy(xpiFile, addonPath + '.xpi', function () {
next();
});
} else {
// copy it!
fs.mkdir(addonPath, function () {
fs.copy(
addon,
addonPath,
{
clobber: true,
},
function () {
next();
}
);
});
}
},
function (next) {
if (tmpDir) {
fs.remove(tmpDir, function () {
next();
});
} else {
next();
util.callbackify(async function run() {
await fs.mkdirp(self.extensionsDir);
if (!unpack && xpiFile) {
await fs.copy(xpiFile, addonPath + '.xpi');
} else {
await fs.mkdir(addonPath);
await fs.copy(
addon,
addonPath,
{
clobber: true,
}
},
],
function () {
// done!
cb && cb(null, addonDetails);
);
}
);

if (tmpDir) {
await fs.remove(tmpDir);
}

return addonDetails;
})(cb)
});
};

Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"dependencies": {
"adm-zip": "~0.4.x",
"archiver": "~5.0.2",
"async": "~2.5.0",
"fs-extra": "~4.0.2",
"ini": "~1.3.3",
"jetpack-id": "1.0.0",
Expand Down

0 comments on commit 3429330

Please sign in to comment.