From 0bf1ec495800f03602be18f73bb8674ef18017b9 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Fri, 31 Jul 2020 13:02:23 +0200 Subject: [PATCH] Remove Bluebird Changelog-entry: Remove Bluebird Change-type: patch --- lib/gui/app/app.ts | 4 +-- lib/gui/app/os/windows-network-drives.ts | 5 ++-- lib/shared/permissions.ts | 34 +++++++++++++++++------- lib/shared/tmp.ts | 13 +++++---- npm-shrinkwrap.json | 6 ++--- package.json | 1 - 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/lib/gui/app/app.ts b/lib/gui/app/app.ts index 471c99ce..6443d943 100644 --- a/lib/gui/app/app.ts +++ b/lib/gui/app/app.ts @@ -43,10 +43,8 @@ window.addEventListener( 'unhandledrejection', (event: PromiseRejectionEvent | any) => { // Promise: event.reason - // Bluebird: event.detail.reason // Anything else: event - const error = - event.reason || (event.detail && event.detail.reason) || event; + const error = event.reason || event; analytics.logException(error); event.preventDefault(); }, diff --git a/lib/gui/app/os/windows-network-drives.ts b/lib/gui/app/os/windows-network-drives.ts index 860e26e9..7dd74620 100755 --- a/lib/gui/app/os/windows-network-drives.ts +++ b/lib/gui/app/os/windows-network-drives.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { using } from 'bluebird'; import { exec } from 'child_process'; import { readFile } from 'fs'; import { chain, trim } from 'lodash'; @@ -23,7 +22,7 @@ import { join } from 'path'; import { env } from 'process'; import { promisify } from 'util'; -import { tmpFileDisposer } from '../../../shared/tmp'; +import { withTmpFile } from '../../../shared/tmp'; const readFileAsync = promisify(readFile); @@ -47,7 +46,7 @@ export async function getWmicNetworkDrivesOutput(): Promise { // Wmic fails with "Invalid global switch" when the "/output:" switch filename contains a dash ("-") prefix: 'tmp', }; - return using(tmpFileDisposer(options), async ({ path }) => { + return withTmpFile(options, async (path) => { const command = [ join(env.SystemRoot as string, 'System32', 'Wbem', 'wmic'), 'path', diff --git a/lib/shared/permissions.ts b/lib/shared/permissions.ts index b152c9d2..663ddba2 100755 --- a/lib/shared/permissions.ts +++ b/lib/shared/permissions.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import * as Bluebird from 'bluebird'; import * as childProcess from 'child_process'; import { promises as fs } from 'fs'; import * as _ from 'lodash'; @@ -25,14 +24,29 @@ import { promisify } from 'util'; import { sudo as catalinaSudo } from './catalina-sudo/sudo'; import * as errors from './errors'; -import { tmpFileDisposer } from './tmp'; +import { withTmpFile } from './tmp'; const execAsync = promisify(childProcess.exec); const execFileAsync = promisify(childProcess.execFile); -// sudo-prompt's exec callback is function(error, stdout, stderr) so we need multiArgs -const sudoExecAsync = Bluebird.promisify(sudoPrompt.exec, { - multiArgs: true, -}) as (cmd: string, options: any) => Bluebird<[string, string]>; + +function sudoExecAsync( + cmd: string, + options: { name: string }, +): Promise<{ stdout: string; stderr: string }> { + return new Promise((resolve, reject) => { + sudoPrompt.exec( + cmd, + options, + (error: Error | null, stdout: string, stderr: string) => { + if (error != null) { + reject(error); + } else { + resolve({ stdout, stderr }); + } + }, + ); + }); +} /** * @summary The user id of the UNIX "superuser" @@ -161,12 +175,12 @@ export async function elevateCommand( command.slice(1), options.environment, ); - return Bluebird.using( - tmpFileDisposer({ + return await withTmpFile( + { prefix: 'balena-etcher-electron-', postfix: '.cmd', - }), - async ({ path }) => { + }, + async (path) => { await fs.writeFile(path, launchScript); if (isWindows) { return elevateScriptWindows(path); diff --git a/lib/shared/tmp.ts b/lib/shared/tmp.ts index 9187f4d9..192ed0a2 100644 --- a/lib/shared/tmp.ts +++ b/lib/shared/tmp.ts @@ -1,4 +1,3 @@ -import * as Bluebird from 'bluebird'; import * as tmp from 'tmp'; function tmpFileAsync( @@ -15,10 +14,14 @@ function tmpFileAsync( }); } -export function tmpFileDisposer( +export async function withTmpFile( options: tmp.FileOptions, -): Bluebird.Disposer<{ path: string; cleanup: () => void }> { - return Bluebird.resolve(tmpFileAsync(options)).disposer(({ cleanup }) => { + fn: (path: string) => Promise, +): Promise { + const { path, cleanup } = await tmpFileAsync(options); + try { + return await fn(path); + } finally { cleanup(); - }); + } } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index a82fe1bf..318a4994 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -11085,9 +11085,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash-deep": { diff --git a/package.json b/package.json index beb1a4cf..dd1b44ef 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "@types/terser-webpack-plugin": "^3.0.0", "@types/tmp": "^0.2.0", "@types/webpack-node-externals": "^1.7.0", - "bluebird": "^3.7.2", "chai": "^4.2.0", "copy-webpack-plugin": "^6.0.1", "css-loader": "^3.5.3",