Remove Bluebird

Changelog-entry: Remove Bluebird
Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-07-31 13:02:23 +02:00
parent 3b105d5a6a
commit 0bf1ec4958
6 changed files with 38 additions and 25 deletions

View File

@ -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();
},

View File

@ -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<string> {
// 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',

View File

@ -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);

View File

@ -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<T>(
options: tmp.FileOptions,
): Bluebird.Disposer<{ path: string; cleanup: () => void }> {
return Bluebird.resolve(tmpFileAsync(options)).disposer(({ cleanup }) => {
fn: (path: string) => Promise<T>,
): Promise<T> {
const { path, cleanup } = await tmpFileAsync(options);
try {
return await fn(path);
} finally {
cleanup();
});
}
}

6
npm-shrinkwrap.json generated
View File

@ -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": {

View File

@ -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",