Remove Bluebird as a direct dependency

Change-type: patch
This commit is contained in:
Thodoris Greasidis 2024-09-18 18:07:33 +03:00
parent 1699419788
commit d39dc5a39a
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 { run as oclifRun } from '@oclif/core';
import * as archiver from 'archiver'; import * as archiver from 'archiver';
import * as Bluebird from 'bluebird';
import { exec, execFile } from 'child_process'; import { exec, execFile } from 'child_process';
import * as filehound from 'filehound'; import * as filehound from 'filehound';
import type { Stats } from 'fs'; import type { Stats } from 'fs';
@ -42,6 +41,7 @@ import {
const execFileAsync = promisify(execFile); const execFileAsync = promisify(execFile);
const execAsync = promisify(exec); const execAsync = promisify(exec);
const rimrafAsync = promisify(rimraf);
export const packageJSON = loadPackageJson(); export const packageJSON = loadPackageJson();
export const version = 'v' + packageJSON.version; export const version = 'v' + packageJSON.version;
@ -517,7 +517,7 @@ export async function buildOclifInstaller() {
} }
for (const dir of dirs) { for (const dir of dirs) {
console.log(`rimraf(${dir})`); console.log(`rimraf(${dir})`);
await Bluebird.fromCallback((cb) => rimraf(dir, cb)); await rimrafAsync(dir);
} }
console.log('======================================================='); console.log('=======================================================');
console.log(`oclif ${packCmd} ${packOpts.join(' ')}`); console.log(`oclif ${packCmd} ${packOpts.join(' ')}`);

1
npm-shrinkwrap.json generated
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@
declare module 'balena-device-init' { declare module 'balena-device-init' {
import { DeviceTypeJson } from 'balena-sdk'; import { DeviceTypeJson } from 'balena-sdk';
import type * as Bluebird from 'bluebird';
interface OperationState { interface OperationState {
operation: operation:
@ -78,25 +77,29 @@ declare module 'balena-device-init' {
on(event: 'error', callback: (error: Error) => void): void; 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( export function configure(
image: string, image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType, manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
config: object, config: object,
options?: object, options?: object,
): Bluebird<InitializeEmitter>; ): Promise<InitializeEmitter>;
export function initialize( export function initialize(
image: string, image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType, manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
config: object, config: object,
): Bluebird<InitializeEmitter>; ): Promise<InitializeEmitter>;
export function getImageOsVersion( export function getImageOsVersion(
image: string, image: string,
manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType, manifest: BalenaSdk.DeviceTypeJson.DeviceType.DeviceType,
): Bluebird<string | null>; ): Promise<string | null>;
export function getImageManifest( export function getImageManifest(
image: string, 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' { declare module 'resin-cli-form' {
import Bluebird = require('bluebird');
export type TypeOrPromiseLike<T> = T | PromiseLike<T>; export type TypeOrPromiseLike<T> = T | PromiseLike<T>;
export type Validate = ( export type Validate = (
@ -43,9 +41,13 @@ declare module 'resin-cli-form' {
validate?: Validate; 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>( export const run: <T = any>(
questions?: RunQuestion[], questions?: RunQuestion[],
extraOptions?: { override?: object }, extraOptions?: { override?: object },
) => Bluebird<T>; ) => Promise<T>;
} }