mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 11:16:39 +00:00
Remove Bluebird
Changelog-entry: Remove Bluebird Change-type: patch
This commit is contained in:
parent
3b105d5a6a
commit
0bf1ec4958
@ -43,10 +43,8 @@ window.addEventListener(
|
|||||||
'unhandledrejection',
|
'unhandledrejection',
|
||||||
(event: PromiseRejectionEvent | any) => {
|
(event: PromiseRejectionEvent | any) => {
|
||||||
// Promise: event.reason
|
// Promise: event.reason
|
||||||
// Bluebird: event.detail.reason
|
|
||||||
// Anything else: event
|
// Anything else: event
|
||||||
const error =
|
const error = event.reason || event;
|
||||||
event.reason || (event.detail && event.detail.reason) || event;
|
|
||||||
analytics.logException(error);
|
analytics.logException(error);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { using } from 'bluebird';
|
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { readFile } from 'fs';
|
import { readFile } from 'fs';
|
||||||
import { chain, trim } from 'lodash';
|
import { chain, trim } from 'lodash';
|
||||||
@ -23,7 +22,7 @@ import { join } from 'path';
|
|||||||
import { env } from 'process';
|
import { env } from 'process';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
import { tmpFileDisposer } from '../../../shared/tmp';
|
import { withTmpFile } from '../../../shared/tmp';
|
||||||
|
|
||||||
const readFileAsync = promisify(readFile);
|
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 ("-")
|
// Wmic fails with "Invalid global switch" when the "/output:" switch filename contains a dash ("-")
|
||||||
prefix: 'tmp',
|
prefix: 'tmp',
|
||||||
};
|
};
|
||||||
return using(tmpFileDisposer(options), async ({ path }) => {
|
return withTmpFile(options, async (path) => {
|
||||||
const command = [
|
const command = [
|
||||||
join(env.SystemRoot as string, 'System32', 'Wbem', 'wmic'),
|
join(env.SystemRoot as string, 'System32', 'Wbem', 'wmic'),
|
||||||
'path',
|
'path',
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -25,14 +24,29 @@ import { promisify } from 'util';
|
|||||||
|
|
||||||
import { sudo as catalinaSudo } from './catalina-sudo/sudo';
|
import { sudo as catalinaSudo } from './catalina-sudo/sudo';
|
||||||
import * as errors from './errors';
|
import * as errors from './errors';
|
||||||
import { tmpFileDisposer } from './tmp';
|
import { withTmpFile } from './tmp';
|
||||||
|
|
||||||
const execAsync = promisify(childProcess.exec);
|
const execAsync = promisify(childProcess.exec);
|
||||||
const execFileAsync = promisify(childProcess.execFile);
|
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, {
|
function sudoExecAsync(
|
||||||
multiArgs: true,
|
cmd: string,
|
||||||
}) as (cmd: string, options: any) => Bluebird<[string, 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"
|
* @summary The user id of the UNIX "superuser"
|
||||||
@ -161,12 +175,12 @@ export async function elevateCommand(
|
|||||||
command.slice(1),
|
command.slice(1),
|
||||||
options.environment,
|
options.environment,
|
||||||
);
|
);
|
||||||
return Bluebird.using(
|
return await withTmpFile(
|
||||||
tmpFileDisposer({
|
{
|
||||||
prefix: 'balena-etcher-electron-',
|
prefix: 'balena-etcher-electron-',
|
||||||
postfix: '.cmd',
|
postfix: '.cmd',
|
||||||
}),
|
},
|
||||||
async ({ path }) => {
|
async (path) => {
|
||||||
await fs.writeFile(path, launchScript);
|
await fs.writeFile(path, launchScript);
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
return elevateScriptWindows(path);
|
return elevateScriptWindows(path);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as tmp from 'tmp';
|
import * as tmp from 'tmp';
|
||||||
|
|
||||||
function tmpFileAsync(
|
function tmpFileAsync(
|
||||||
@ -15,10 +14,14 @@ function tmpFileAsync(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tmpFileDisposer(
|
export async function withTmpFile<T>(
|
||||||
options: tmp.FileOptions,
|
options: tmp.FileOptions,
|
||||||
): Bluebird.Disposer<{ path: string; cleanup: () => void }> {
|
fn: (path: string) => Promise<T>,
|
||||||
return Bluebird.resolve(tmpFileAsync(options)).disposer(({ cleanup }) => {
|
): Promise<T> {
|
||||||
|
const { path, cleanup } = await tmpFileAsync(options);
|
||||||
|
try {
|
||||||
|
return await fn(path);
|
||||||
|
} finally {
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
6
npm-shrinkwrap.json
generated
6
npm-shrinkwrap.json
generated
@ -11085,9 +11085,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lodash": {
|
"lodash": {
|
||||||
"version": "4.17.15",
|
"version": "4.17.19",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"lodash-deep": {
|
"lodash-deep": {
|
||||||
|
@ -64,7 +64,6 @@
|
|||||||
"@types/terser-webpack-plugin": "^3.0.0",
|
"@types/terser-webpack-plugin": "^3.0.0",
|
||||||
"@types/tmp": "^0.2.0",
|
"@types/tmp": "^0.2.0",
|
||||||
"@types/webpack-node-externals": "^1.7.0",
|
"@types/webpack-node-externals": "^1.7.0",
|
||||||
"bluebird": "^3.7.2",
|
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"copy-webpack-plugin": "^6.0.1",
|
"copy-webpack-plugin": "^6.0.1",
|
||||||
"css-loader": "^3.5.3",
|
"css-loader": "^3.5.3",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user