Skip to content

Commit

Permalink
Merge pull request #2835 from balena-io/reduce-bluebird
Browse files Browse the repository at this point in the history
Remove Bluebird as a direct dependency
  • Loading branch information
thgreasi authored Sep 18, 2024
2 parents 1699419 + d39dc5a commit ca6eea4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions automation/build-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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(' ')}`);
Expand Down
1 change: 0 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/utils/device/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ function connectToDocker(host: string, port: number): Docker {
return new Docker({
host,
port,
Promise: require('bluebird'),
});
}

Expand Down
25 changes: 12 additions & 13 deletions tests/auth/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Bluebird from 'bluebird';
import { expect } from 'chai';
import * as sinon from 'sinon';
import * as url from 'url';
Expand All @@ -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);
}));
Expand Down
8 changes: 4 additions & 4 deletions tests/nock/builder-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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(
Expand Down
13 changes: 8 additions & 5 deletions typings/balena-device-init/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

declare module 'balena-device-init' {
import { DeviceTypeJson } from 'balena-sdk';
import type * as Bluebird from 'bluebird';

interface OperationState {
operation:
Expand Down Expand Up @@ -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>;
}
10 changes: 6 additions & 4 deletions typings/resin-cli-form/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/

declare module 'resin-cli-form' {
import Bluebird = require('bluebird');

export type TypeOrPromiseLike<T> = T | PromiseLike<T>;

export type Validate = (
Expand All @@ -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>;
}

0 comments on commit ca6eea4

Please sign in to comment.