diff --git a/package-lock.json b/package-lock.json index 8ee50e5dc83..61581dd338e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48348,7 +48348,6 @@ "@npmcli/arborist": "^6.2.0", "@octokit/rest": "^18.6.2", "asar": "^3.0.3", - "async": "^3.2.2", "chalk": "^4.1.2", "cli-table": "^0.3.1", "debug": "^4.3.4", @@ -74210,7 +74209,6 @@ "@npmcli/arborist": "^6.2.0", "@octokit/rest": "^18.6.2", "asar": "^3.0.3", - "async": "^3.2.2", "chai": "^4.2.0", "chalk": "^4.1.2", "cli-table": "^0.3.1", diff --git a/packages/hadron-build/commands/release.js b/packages/hadron-build/commands/release.js index 9c5fbf1b4cf..b09aefb461d 100644 --- a/packages/hadron-build/commands/release.js +++ b/packages/hadron-build/commands/release.js @@ -502,7 +502,7 @@ _.assign(exports.builder, verify.builder); * @param {Function} done Callback * @returns {any} */ -exports.run = (argv, done) => { +exports.run = async (argv, done) => { cli.argv = argv; verifyDistro(argv); @@ -557,19 +557,21 @@ exports.run = (argv, done) => { task('store build configuration as json', writeConfigToJson) ].filter(Boolean)); - return tasks.reduce((promise, task) => { - return promise.then(task); - }, Promise.resolve()).then(() => { + try { + for (const task of tasks) { + await task(); + } + done(null, target); + } catch (err) { + done(err); + } finally { // clean up copied npmrc fs.rm(path.resolve(target.dir, '.npmrc'), (err) => { if (err) { cli.warn(err.message); } }); - done(null, target); - }).catch((err) => { - done(err); - }); + } }; exports.handler = (argv) => { diff --git a/packages/hadron-build/lib/zip.js b/packages/hadron-build/lib/zip.js index 05b89c5de5e..6dd42d8c0b5 100644 --- a/packages/hadron-build/lib/zip.js +++ b/packages/hadron-build/lib/zip.js @@ -4,8 +4,9 @@ const { execFileSync } = require('child_process'); const fs = require('fs-extra'); const path = require('path'); const zipFolder = require('zip-folder'); +const { promisify } = require('util'); -function zip(_opts, done) { +async function zip(_opts, done) { const opts = Object.assign({}, _opts); opts.dir = path.resolve(opts.dir); opts.out = path.resolve(opts.out); @@ -18,50 +19,43 @@ function zip(_opts, done) { opts.outPath = path.resolve(opts.out, path.basename(opts.dir, '.app')) + '.zip'; } - const runZip = () => { - return new Promise((resolve, reject) => { - if (opts.platform !== 'darwin') { - zipFolder(opts.dir, opts.outPath, (err) => { - if (err) return reject(err); - return resolve(opts.outPath); - }); - } else { - try { - const args = ['-r', '--symlinks', opts.outPath, './']; - execFileSync('zip', args, { - env: process.env, - cwd: path.join(opts.dir, '..'), - stdio: 'inherit' - }); - return resolve(opts.outPath); - } catch (err) { - return reject(err); - } - } - }); + const runZip = async () => { + if (opts.platform !== 'darwin') { + await promisify(zipFolder)(opts.dir, opts.outPath); + } else { + const args = ['-r', '--symlinks', opts.outPath, './']; + execFileSync('zip', args, { + env: process.env, + cwd: path.join(opts.dir, '..'), + stdio: 'inherit' + }); + } } - + const removeZipIfExists = async () => { try { const stats = await fs.stat(opts.outPath); if (!stats.isFile()) { throw new Error('Refusing to wipe path "' + opts.outPath + '" as it is ' + (stats.isDirectory() ? 'a directory' : 'not a file')); } - return await fs.unlink(opts.outPath); + await fs.unlink(opts.outPath); } catch (err) { if (err.code !== 'ENOENT') { throw err; } } } - + debug('creating zip', opts); - - removeZipIfExists() - .then(() => fs.mkdirs(opts.out)) - .then(() => runZip()) - .then(result => done(null, result)) - .catch(err => done(err)); + + try { + await removeZipIfExists(); + await fs.mkdirs(opts.out); + await runZip(); + done(null, opts.outPath); + } catch (err) { + done(err); + } } /**