Merge pull request #2835 from balena-io/reduce-bluebird

Remove Bluebird as a direct dependency
This commit is contained in:
Thodoris Greasidis 2024-09-18 19:38:06 +03:00 committed by GitHub
commit ca6eea4371
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 32 additions and 31 deletions

View File

@ -19,7 +19,6 @@ import type { JsonVersions } from '../src/commands/version/index';
import { run as oclifRun } from '@oclif/core';
import * as archiver from 'archiver';
import * as Bluebird from 'bluebird';
import { exec, execFile } from 'child_process';
import * as filehound from 'filehound';
import type { Stats } from 'fs';
@ -42,6 +41,7 @@ import {
const execFileAsync = promisify(execFile);
const execAsync = promisify(exec);
const rimrafAsync = promisify(rimraf);
export const packageJSON = loadPackageJson();
export const version = 'v' + packageJSON.version;
@ -517,7 +517,7 @@ export async function buildOclifInstaller() {
}
for (const dir of dirs) {
console.log(`rimraf(${dir})`);
await Bluebird.fromCallback((cb) => rimraf(dir, cb));
await rimrafAsync(dir);
}
console.log('=======================================================');
console.log(`oclif ${packCmd} ${packOpts.join(' ')}`);

1
npm-shrinkwrap.json generated
View File

@ -26,7 +26,6 @@
"balena-semver": "^2.3.0",
"balena-settings-client": "^5.0.2",
"balena-settings-storage": "^8.1.0",
"bluebird": "^3.7.2",
"body-parser": "^1.19.1",
"bonjour-service": "^1.2.1",
"chalk": "^3.0.0",

View File

@ -207,7 +207,6 @@
"balena-semver": "^2.3.0",
"balena-settings-client": "^5.0.2",
"balena-settings-storage": "^8.1.0",
"bluebird": "^3.7.2",
"body-parser": "^1.19.1",
"bonjour-service": "^1.2.1",
"chalk": "^3.0.0",

View File

@ -309,7 +309,6 @@ function connectToDocker(host: string, port: number): Docker {
return new Docker({
host,
port,
Promise: require('bluebird'),
});
}

View File

@ -1,4 +1,3 @@
import * as Bluebird from 'bluebird';
import { expect } from 'chai';
import * as sinon from 'sinon';
import * as url from 'url';
@ -19,28 +18,28 @@ describe('Utils:', async function () {
));
it('should eventually contain an https protocol', () =>
Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'),
}).then(function ({ dashboardUrl, loginUrl }) {
Promise.all([
balena.settings.get('dashboardUrl'),
utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'),
]).then(function ([dashboardUrl, loginUrl]) {
const { protocol } = url.parse(loginUrl);
return expect(protocol).to.equal(url.parse(dashboardUrl).protocol);
}));
it('should correctly escape a callback url without a path', () =>
Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000'),
}).then(function ({ dashboardUrl, loginUrl }) {
Promise.all([
balena.settings.get('dashboardUrl'),
utils.getDashboardLoginURL('http://127.0.0.1:3000'),
]).then(function ([dashboardUrl, loginUrl]) {
const expectedUrl = `${dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000`;
return expect(loginUrl).to.equal(expectedUrl);
}));
return it('should correctly escape a callback url with a path', () =>
Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'),
}).then(function ({ dashboardUrl, loginUrl }) {
Promise.all([
balena.settings.get('dashboardUrl'),
utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'),
]).then(function ([dashboardUrl, loginUrl]) {
const expectedUrl = `${dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000%252Fcallback`;
return expect(loginUrl).to.equal(expectedUrl);
}));

View File

@ -15,11 +15,13 @@
* limitations under the License.
*/
import * as Bluebird from 'bluebird';
import * as path from 'path';
import * as zlib from 'zlib';
import { NockMock } from './nock-mock';
import { promisify } from 'util';
const gunzipAsync = promisify(zlib.gunzip);
export const builderResponsePath = path.normalize(
path.join(__dirname, '..', 'test-data', 'builder-response'),
@ -45,9 +47,7 @@ export class BuilderMock extends NockMock {
await opts.checkURI(uri);
if (typeof requestBody === 'string') {
const gzipped = Buffer.from(requestBody, 'hex');
const gunzipped = await Bluebird.fromCallback<Buffer>((cb) => {
zlib.gunzip(gzipped, cb);
});
const gunzipped = await gunzipAsync(gzipped);
await opts.checkBuildRequestBody(gunzipped);
} else {
throw new Error(

View File

@ -17,7 +17,6 @@
declare module 'balena-device-init' {
import { DeviceTypeJson } from 'balena-sdk';
import type * as Bluebird from 'bluebird';
interface OperationState {
operation:
@ -78,25 +77,29 @@ declare module 'balena-device-init' {
on(event: 'error', callback: (error: Error) => void): void;
}
// As of writing this, these are Bluebird promises, but we are typing then
// as normal Promises so that we do not rely on Bluebird specific methods,
// so that the CLI will not require any change once the package drops Bluebird.
export function configure(
image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
config: object,
options?: object,
): Bluebird<InitializeEmitter>;
): Promise<InitializeEmitter>;
export function initialize(
image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
config: object,
): Bluebird<InitializeEmitter>;
): Promise<InitializeEmitter>;
export function getImageOsVersion(
image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
): Bluebird<string | null>;
): Promise<string | null>;
export function getImageManifest(
image: string,
): Bluebird<BalenaSdk.DeviceTypeJson.DeviceType.DeviceType | null>;
): Promise<BalenaSdk.DeviceTypeJson.DeviceType.DeviceType | null>;
}

View File

@ -16,8 +16,6 @@
*/
declare module 'resin-cli-form' {
import Bluebird = require('bluebird');
export type TypeOrPromiseLike<T> = T | PromiseLike<T>;
export type Validate = (
@ -43,9 +41,13 @@ declare module 'resin-cli-form' {
validate?: Validate;
}
export const ask: <T = string>(options: AskOptions<T>) => Bluebird<T>;
// As of writing this, these are Bluebird promises, but we are typing then
// as normal Promises so that we do not rely on Bluebird specific methods,
// so that the CLI will not require any change once the package drops Bluebird.
export const ask: <T = string>(options: AskOptions<T>) => Promise<T>;
export const run: <T = any>(
questions?: RunQuestion[],
extraOptions?: { override?: object },
) => Bluebird<T>;
) => Promise<T>;
}