Standardize all references to Bluebird

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-06-23 11:29:03 +01:00 committed by Balena CI
parent cfbf00f543
commit 420a282bea
21 changed files with 125 additions and 125 deletions

View File

@ -17,7 +17,7 @@
// Imported here because it's needed for the setup // Imported here because it's needed for the setup
// of this action // of this action
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as dockerUtils from '../utils/docker'; import * as dockerUtils from '../utils/docker';
import * as compose from '../utils/compose'; import * as compose from '../utils/compose';
@ -35,7 +35,7 @@ Opts must be an object with the following keys:
*/ */
const buildProject = function (docker, logger, composeOpts, opts) { const buildProject = function (docker, logger, composeOpts, opts) {
const { loadProject } = require('../utils/compose_ts'); const { loadProject } = require('../utils/compose_ts');
return Promise.resolve(loadProject(logger, composeOpts)) return Bluebird.resolve(loadProject(logger, composeOpts))
.then(function (project) { .then(function (project) {
const appType = opts.app?.application_type?.[0]; const appType = opts.app?.application_type?.[0];
if ( if (
@ -154,7 +154,7 @@ Examples:
const { application, arch, deviceType } = options; const { application, arch, deviceType } = options;
return Promise.try(function () { return Bluebird.try(function () {
if ( if (
(application == null && (arch == null || deviceType == null)) || (application == null && (arch == null || deviceType == null)) ||
(application != null && (arch != null || deviceType != null)) (application != null && (arch != null || deviceType != null))
@ -189,7 +189,7 @@ Examples:
}) })
.then(function ([app, resolvedArch, resolvedDeviceType]) { .then(function ([app, resolvedArch, resolvedDeviceType]) {
return Promise.join( return Bluebird.join(
dockerUtils.getDocker(options), dockerUtils.getDocker(options),
dockerUtils.generateBuildOpts(options), dockerUtils.generateBuildOpts(options),
compose.generateOpts(options), compose.generateOpts(options),

View File

@ -49,12 +49,12 @@ Examples:
permission: 'user', permission: 'user',
root: true, root: true,
action(_params, options) { action(_params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const config = require('balena-config-json'); const config = require('balena-config-json');
const umountAsync = Promise.promisify(require('umount').umount); const umountAsync = Bluebird.promisify(require('umount').umount);
const prettyjson = require('prettyjson'); const prettyjson = require('prettyjson');
return Promise.try( return Bluebird.try(
() => options.drive || getVisuals().drive('Select the device drive'), () => options.drive || getVisuals().drive('Select the device drive'),
) )
.tap(umountAsync) .tap(umountAsync)
@ -96,12 +96,12 @@ Examples:
permission: 'user', permission: 'user',
root: true, root: true,
action(params, options) { action(params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const _ = require('lodash'); const _ = require('lodash');
const config = require('balena-config-json'); const config = require('balena-config-json');
const umountAsync = Promise.promisify(require('umount').umount); const umountAsync = Bluebird.promisify(require('umount').umount);
return Promise.try( return Bluebird.try(
() => options.drive || getVisuals().drive('Select the device drive'), () => options.drive || getVisuals().drive('Select the device drive'),
) )
.tap(umountAsync) .tap(umountAsync)
@ -153,13 +153,13 @@ Examples:
permission: 'user', permission: 'user',
root: true, root: true,
action(params, options) { action(params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const util = require('util'); const util = require('util');
const config = require('balena-config-json'); const config = require('balena-config-json');
const umountAsync = Promise.promisify(require('umount').umount); const umountAsync = Bluebird.promisify(require('umount').umount);
const readFileAsync = util.promisify(require('fs').readFile); const readFileAsync = util.promisify(require('fs').readFile);
return Promise.try( return Bluebird.try(
() => options.drive || getVisuals().drive('Select the device drive'), () => options.drive || getVisuals().drive('Select the device drive'),
) )
.tap(umountAsync) .tap(umountAsync)
@ -211,12 +211,12 @@ Examples:
permission: 'user', permission: 'user',
root: true, root: true,
action(_params, options) { action(_params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const config = require('balena-config-json'); const config = require('balena-config-json');
const { runCommand } = require('../utils/helpers'); const { runCommand } = require('../utils/helpers');
const umountAsync = Promise.promisify(require('umount').umount); const umountAsync = Bluebird.promisify(require('umount').umount);
return Promise.try( return Bluebird.try(
() => options.drive || getVisuals().drive('Select the device drive'), () => options.drive || getVisuals().drive('Select the device drive'),
) )
.tap(umountAsync) .tap(umountAsync)
@ -311,8 +311,8 @@ Examples:
permission: 'user', permission: 'user',
action(_params, options) { action(_params, options) {
normalizeUuidProp(options, 'device'); normalizeUuidProp(options, 'device');
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const writeFileAsync = Promise.promisify(require('fs').writeFile); const writeFileAsync = Bluebird.promisify(require('fs').writeFile);
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const form = require('resin-cli-form'); const form = require('resin-cli-form');
const prettyjson = require('prettyjson'); const prettyjson = require('prettyjson');
@ -348,7 +348,7 @@ See the help page for examples:
`); `);
} }
return Promise.try( return Bluebird.try(
/** @returns {Promise<any>} */ function () { /** @returns {Promise<any>} */ function () {
if (options.device != null) { if (options.device != null) {
return balena.models.device.get(options.device); return balena.models.device.get(options.device);

View File

@ -17,7 +17,7 @@
// Imported here because it's needed for the setup // Imported here because it's needed for the setup
// of this action // of this action
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as dockerUtils from '../utils/docker'; import * as dockerUtils from '../utils/docker';
import * as compose from '../utils/compose'; import * as compose from '../utils/compose';
@ -45,7 +45,7 @@ const deployProject = function (docker, logger, composeOpts, opts) {
loadProject, loadProject,
} = require('../utils/compose_ts'); } = require('../utils/compose_ts');
return Promise.resolve(loadProject(logger, composeOpts, opts.image)) return Bluebird.resolve(loadProject(logger, composeOpts, opts.image))
.then(function (project) { .then(function (project) {
if ( if (
project.descriptors.length > 1 && project.descriptors.length > 1 &&
@ -58,7 +58,7 @@ const deployProject = function (docker, logger, composeOpts, opts) {
// find which services use images that already exist locally // find which services use images that already exist locally
return ( return (
Promise.map(project.descriptors, function (d) { Bluebird.map(project.descriptors, function (d) {
// unconditionally build (or pull) if explicitly requested // unconditionally build (or pull) if explicitly requested
if (opts.shouldPerformBuild) { if (opts.shouldPerformBuild) {
return d; return d;
@ -124,7 +124,7 @@ const deployProject = function (docker, logger, composeOpts, opts) {
); );
logger.logWarn(msg); logger.logWarn(msg);
return Promise.join( return Bluebird.join(
docker, docker,
logger, logger,
sdk.auth.getToken(), sdk.auth.getToken(),
@ -145,7 +145,7 @@ const deployProject = function (docker, logger, composeOpts, opts) {
sdk.models.release.get(releaseId, { $select: ['commit'] }), sdk.models.release.get(releaseId, { $select: ['commit'] }),
); );
} }
return Promise.join( return Bluebird.join(
sdk.auth.getUserId(), sdk.auth.getUserId(),
sdk.auth.getToken(), sdk.auth.getToken(),
sdk.settings.get('apiUrl'), sdk.settings.get('apiUrl'),
@ -263,7 +263,7 @@ Examples:
appName = appName_raw || appName || options.application; appName = appName_raw || appName || options.application;
delete options.application; delete options.application;
return Promise.try(function () { return Bluebird.try(function () {
if (appName == null) { if (appName == null) {
throw new ExpectedError( throw new ExpectedError(
'Please specify the name of the application to deploy', 'Please specify the name of the application to deploy',
@ -297,7 +297,7 @@ Examples:
}) })
.then(() => helpers.getAppWithArch(appName)) .then(() => helpers.getAppWithArch(appName))
.then(function (app) { .then(function (app) {
return Promise.join( return Bluebird.join(
dockerUtils.getDocker(options), dockerUtils.getDocker(options),
dockerUtils.generateBuildOpts(options), dockerUtils.generateBuildOpts(options),
compose.generateOpts(options), compose.generateOpts(options),

View File

@ -50,17 +50,17 @@ Examples:
], ],
permission: 'user', permission: 'user',
action(_params, options) { action(_params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const rimraf = Promise.promisify(require('rimraf')); const rimraf = Bluebird.promisify(require('rimraf'));
const tmp = require('tmp'); const tmp = require('tmp');
const tmpNameAsync = Promise.promisify(tmp.tmpName); const tmpNameAsync = Bluebird.promisify(tmp.tmpName);
tmp.setGracefulCleanup(); tmp.setGracefulCleanup();
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const patterns = require('../utils/patterns'); const patterns = require('../utils/patterns');
const { runCommand } = require('../utils/helpers'); const { runCommand } = require('../utils/helpers');
return Promise.try(function () { return Bluebird.try(function () {
if (options.application != null) { if (options.application != null) {
return options.application; return options.application;
} }
@ -78,7 +78,7 @@ Examples:
}) })
.disposer((tempPath) => rimraf(tempPath)); .disposer((tempPath) => rimraf(tempPath));
return Promise.using(download(), (tempPath) => return Bluebird.using(download(), (tempPath) =>
runCommand(`device register ${application.app_name}`) runCommand(`device register ${application.app_name}`)
.then(balena.models.device.get) .then(balena.models.device.get)
.tap(function (device) { .tap(function (device) {

View File

@ -1,4 +1,4 @@
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as dockerUtils from '../../utils/docker'; import * as dockerUtils from '../../utils/docker';
import { exitWithExpectedError } from '../../errors'; import { exitWithExpectedError } from '../../errors';
@ -19,7 +19,7 @@ export const filterOutSupervisorContainer = function (container) {
return true; return true;
}; };
export const selectContainerFromDevice = Promise.method(function ( export const selectContainerFromDevice = Bluebird.method(function (
deviceIp, deviceIp,
filterSupervisor, filterSupervisor,
) { ) {
@ -61,7 +61,7 @@ export const selectContainerFromDevice = Promise.method(function (
}); });
}); });
export const pipeContainerStream = Promise.method(function ({ export const pipeContainerStream = Bluebird.method(function ({
deviceIp, deviceIp,
name, name,
outStream, outStream,

View File

@ -234,13 +234,13 @@ Examples:
`, `,
root: true, root: true,
action(params) { action(params) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const path = require('path'); const path = require('path');
const umount = require('umount'); const umount = require('umount');
const umountAsync = Promise.promisify(umount.umount); const umountAsync = Bluebird.promisify(umount.umount);
const isMountedAsync = Promise.promisify(umount.isMounted); const isMountedAsync = Bluebird.promisify(umount.isMounted);
const reconfix = require('reconfix'); const reconfix = require('reconfix');
const denymount = Promise.promisify(require('denymount')); const denymount = Bluebird.promisify(require('denymount'));
return prepareConnectionFile(params.target) return prepareConnectionFile(params.target)
.tap(() => .tap(() =>

View File

@ -114,7 +114,7 @@ Examples:
commandOptions.osVersionOrSemver, commandOptions.osVersionOrSemver,
], ],
action(params, options) { action(params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const unzip = require('node-unzip-2'); const unzip = require('node-unzip-2');
const fs = require('fs'); const fs = require('fs');
const rindle = require('rindle'); const rindle = require('rindle');
@ -123,7 +123,7 @@ Examples:
console.info(`Getting device operating system for ${params.type}`); console.info(`Getting device operating system for ${params.type}`);
let displayVersion = ''; let displayVersion = '';
return Promise.try(function () { return Bluebird.try(function () {
if (!options.version) { if (!options.version) {
console.warn(`OS version is not specified, using the default version: \ console.warn(`OS version is not specified, using the default version: \
the newest stable (non-pre-release) version if available, \ the newest stable (non-pre-release) version if available, \
@ -205,10 +205,10 @@ const $buildConfig = function (image, deviceTypeSlug, advanced) {
if (advanced == null) { if (advanced == null) {
advanced = false; advanced = false;
} }
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const helpers = require('../utils/helpers'); const helpers = require('../utils/helpers');
return Promise.resolve( return Bluebird.resolve(
helpers.getManifest(image, deviceTypeSlug), helpers.getManifest(image, deviceTypeSlug),
).then((deviceTypeManifest) => ).then((deviceTypeManifest) =>
buildConfigForDeviceType(deviceTypeManifest, advanced), buildConfigForDeviceType(deviceTypeManifest, advanced),
@ -239,8 +239,8 @@ Example:
], ],
action(params, options) { action(params, options) {
const fs = require('fs'); const fs = require('fs');
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const writeFileAsync = Promise.promisify(fs.writeFile); const writeFileAsync = Bluebird.promisify(fs.writeFile);
return $buildConfig( return $buildConfig(
params.image, params.image,
@ -283,8 +283,8 @@ Examples:
commandOptions.drive, commandOptions.drive,
], ],
action(params, options) { action(params, options) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const umountAsync = Promise.promisify(require('umount').umount); const umountAsync = Bluebird.promisify(require('umount').umount);
const form = require('resin-cli-form'); const form = require('resin-cli-form');
const patterns = require('../utils/patterns'); const patterns = require('../utils/patterns');
const helpers = require('../utils/helpers'); const helpers = require('../utils/helpers');
@ -294,7 +294,7 @@ Initializing device
${INIT_WARNING_MESSAGE}\ ${INIT_WARNING_MESSAGE}\
`); `);
return Promise.resolve(helpers.getManifest(params.image, options.type)) return Bluebird.resolve(helpers.getManifest(params.image, options.type))
.then((manifest) => .then((manifest) =>
form.run(manifest.initialization?.options, { form.run(manifest.initialization?.options, {
override: { override: {

View File

@ -138,7 +138,7 @@ const offerToDisableAutomaticUpdates = function (
commit, commit,
pinDevice, pinDevice,
) { ) {
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const form = require('resin-cli-form'); const form = require('resin-cli-form');
@ -147,7 +147,7 @@ const offerToDisableAutomaticUpdates = function (
!application.should_track_latest_release || !application.should_track_latest_release ||
pinDevice pinDevice
) { ) {
return Promise.resolve(); return Bluebird.resolve();
} }
const message = `\ const message = `\
@ -256,7 +256,7 @@ Examples:
options: preloadOptions, options: preloadOptions,
action(params, options, done) { action(params, options, done) {
let certificates; let certificates;
const Promise = require('bluebird'); const Bluebird = require('bluebird');
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const balenaPreload = require('balena-preload'); const balenaPreload = require('balena-preload');
const visuals = getVisuals(); const visuals = getVisuals();
@ -358,7 +358,7 @@ Examples:
preloader.on('progress', progressHandler); preloader.on('progress', progressHandler);
preloader.on('spinner', spinnerHandler); preloader.on('spinner', spinnerHandler);
return new Promise(function (resolve, reject) { return new Bluebird(function (resolve, reject) {
preloader.on('error', reject); preloader.on('error', reject);
return preloader return preloader

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as capitano from 'capitano'; import * as capitano from 'capitano';
import * as actions from './actions'; import * as actions from './actions';
@ -92,7 +92,7 @@ capitano.command(actions.push.push);
export function run(argv) { export function run(argv) {
const cli = capitano.parse(argv.slice(2)); const cli = capitano.parse(argv.slice(2));
const runCommand = function () { const runCommand = function () {
const capitanoExecuteAsync = Promise.promisify(capitano.execute); const capitanoExecuteAsync = Bluebird.promisify(capitano.execute);
if (cli.global?.help) { if (cli.global?.help) {
return capitanoExecuteAsync({ return capitanoExecuteAsync({
command: `help ${cli.command ?? ''}`, command: `help ${cli.command ?? ''}`,
@ -103,7 +103,7 @@ export function run(argv) {
}; };
const trackCommand = function () { const trackCommand = function () {
const getMatchCommandAsync = Promise.promisify( const getMatchCommandAsync = Bluebird.promisify(
capitano.state.getMatchCommand, capitano.state.getMatchCommand,
); );
return getMatchCommandAsync(cli.command).then(function (command) { return getMatchCommandAsync(cli.command).then(function (command) {
@ -117,7 +117,7 @@ export function run(argv) {
}); });
}; };
return Promise.all([trackCommand(), runCommand()]).catch( return Bluebird.all([trackCommand(), runCommand()]).catch(
require('./errors').handleError, require('./errors').handleError,
); );
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as bodyParser from 'body-parser'; import * as bodyParser from 'body-parser';
import * as express from 'express'; import * as express from 'express';
import { Socket } from 'net'; import { Socket } from 'net';
@ -78,10 +78,10 @@ export function shutdownServer() {
export const awaitForToken = (options: { export const awaitForToken = (options: {
path: string; path: string;
port: number; port: number;
}): Promise<string> => { }): Bluebird<string> => {
const { app, server } = createServer({ port: options.port }); const { app, server } = createServer({ port: options.port });
return new Promise<string>((resolve, reject) => { return new Bluebird<string>((resolve, reject) => {
app.post(options.path, async (request, response) => { app.post(options.path, async (request, response) => {
server.close(); // stop listening for new connections server.close(); // stop listening for new connections
try { try {

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as url from 'url'; import * as url from 'url';
import { getBalenaSdk } from '../utils/lazy'; import { getBalenaSdk } from '../utils/lazy';
@ -26,7 +26,7 @@ import { getBalenaSdk } from '../utils/lazy';
* *
* @param {String} callbackUrl - callback url * @param {String} callbackUrl - callback url
* @fulfil {String} - dashboard login url * @fulfil {String} - dashboard login url
* @returns {Promise} * @returns {Bluebird}
* *
* @example * @example
* utils.getDashboardLoginURL('http://127.0.0.1:3000').then (url) -> * utils.getDashboardLoginURL('http://127.0.0.1:3000').then (url) ->
@ -58,7 +58,7 @@ export const getDashboardLoginURL = (callbackUrl: string) => {
* *
* @param {String} token - session token or api key * @param {String} token - session token or api key
* @fulfil {Boolean} - whether the login was successful or not * @fulfil {Boolean} - whether the login was successful or not
* @returns {Promise} * @returns {Bluebird}
* *
* utils.loginIfTokenValid('...').then (loggedIn) -> * utils.loginIfTokenValid('...').then (loggedIn) ->
* if loggedIn * if loggedIn
@ -66,7 +66,7 @@ export const getDashboardLoginURL = (callbackUrl: string) => {
*/ */
export const loginIfTokenValid = (token: string) => { export const loginIfTokenValid = (token: string) => {
if (_.isEmpty(token?.trim())) { if (_.isEmpty(token?.trim())) {
return Promise.resolve(false); return Bluebird.resolve(false);
} }
const balena = getBalenaSdk(); const balena = getBalenaSdk();

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import { stripIndent } from 'common-tags'; import { stripIndent } from 'common-tags';
import * as path from 'path'; import * as path from 'path';
@ -182,12 +182,12 @@ export function createProject(composePath, composeStr, projectName = null) {
* optionally converting text file line endings (CRLF to LF). * optionally converting text file line endings (CRLF to LF).
* @param {string} dir Source directory * @param {string} dir Source directory
* @param {import('./compose-types').TarDirectoryOptions} param * @param {import('./compose-types').TarDirectoryOptions} param
* @returns {Promise<import('stream').Readable>} * @returns {Bluebird<import('stream').Readable>}
*/ */
export function tarDirectory(dir, param) { export function tarDirectory(dir, param) {
let { nogitignore = false } = param; let { nogitignore = false } = param;
if (nogitignore) { if (nogitignore) {
return Promise.resolve(require('./compose_ts').tarDirectory(dir, param)); return Bluebird.resolve(require('./compose_ts').tarDirectory(dir, param));
} else { } else {
return originalTarDirectory(dir, param); return originalTarDirectory(dir, param);
} }
@ -199,7 +199,7 @@ export function tarDirectory(dir, param) {
* deleted in CLI v13. * deleted in CLI v13.
* @param {string} dir Source directory * @param {string} dir Source directory
* @param {import('./compose-types').TarDirectoryOptions} param * @param {import('./compose-types').TarDirectoryOptions} param
* @returns {Promise<import('stream').Readable>} * @returns {Bluebird<import('stream').Readable>}
*/ */
function originalTarDirectory(dir, param) { function originalTarDirectory(dir, param) {
let { let {
@ -228,7 +228,7 @@ function originalTarDirectory(dir, param) {
const getFiles = () => const getFiles = () =>
// @ts-ignore `klaw` returns a `Walker` which is close enough to a stream to work but ts complains // @ts-ignore `klaw` returns a `Walker` which is close enough to a stream to work but ts complains
Promise.resolve(streamToPromise(klaw(dir))) Bluebird.resolve(streamToPromise(klaw(dir)))
.filter((item) => !item.stats.isDirectory()) .filter((item) => !item.stats.isDirectory())
.map((item) => item.path); .map((item) => item.path);
@ -255,7 +255,7 @@ function originalTarDirectory(dir, param) {
.filter(ignore.filter) .filter(ignore.filter)
.map(function (file) { .map(function (file) {
const relPath = path.relative(path.resolve(dir), file); const relPath = path.relative(path.resolve(dir), file);
return Promise.join( return Bluebird.join(
relPath, relPath,
fs.stat(file), fs.stat(file),
readFile(file), readFile(file),
@ -344,7 +344,7 @@ export function buildProject(
} }
renderer.start(); renderer.start();
return Promise.resolve(checkBuildSecretsRequirements(docker, projectPath)) return Bluebird.resolve(checkBuildSecretsRequirements(docker, projectPath))
.then(() => qemu.installQemuIfNeeded(emulated, logger, arch, docker)) .then(() => qemu.installQemuIfNeeded(emulated, logger, arch, docker))
.tap(function (needsQemu) { .tap(function (needsQemu) {
if (!needsQemu) { if (!needsQemu) {
@ -352,7 +352,7 @@ export function buildProject(
} }
logger.logInfo('Emulation is enabled'); logger.logInfo('Emulation is enabled');
// Copy qemu into all build contexts // Copy qemu into all build contexts
return Promise.map(imageDescriptors, function (d) { return Bluebird.map(imageDescriptors, function (d) {
if (typeof d.image === 'string' || d.image.context == null) { if (typeof d.image === 'string' || d.image.context == null) {
return; return;
} }
@ -468,7 +468,7 @@ export function buildProject(
}) })
.then(function (tasks) { .then(function (tasks) {
logger.logDebug('Prepared tasks; building...'); logger.logDebug('Prepared tasks; building...');
return Promise.map( return Bluebird.map(
builder.performBuilds(tasks, docker, BALENA_ENGINE_TMP_PATH), builder.performBuilds(tasks, docker, BALENA_ENGINE_TMP_PATH),
function (builtImage) { function (builtImage) {
if (!builtImage.successful) { if (!builtImage.successful) {
@ -529,7 +529,7 @@ export function buildProject(
* @param {number} userId * @param {number} userId
* @param {number} appId * @param {number} appId
* @param {import('resin-compose-parse').Composition} composition * @param {import('resin-compose-parse').Composition} composition
* @returns {Promise<import('./compose-types').Release>} * @returns {Bluebird<import('./compose-types').Release>}
*/ */
export const createRelease = function ( export const createRelease = function (
apiEndpoint, apiEndpoint,
@ -578,10 +578,10 @@ export const createRelease = function (
* @param {import('docker-toolbelt')} docker * @param {import('docker-toolbelt')} docker
* @param {Array<import('./compose-types').BuiltImage>} images * @param {Array<import('./compose-types').BuiltImage>} images
* @param {Partial<import('balena-release/build/models').ImageModel>} serviceImages * @param {Partial<import('balena-release/build/models').ImageModel>} serviceImages
* @returns {Promise<Array<import('./compose-types').TaggedImage>>} * @returns {Bluebird<Array<import('./compose-types').TaggedImage>>}
*/ */
export const tagServiceImages = (docker, images, serviceImages) => export const tagServiceImages = (docker, images, serviceImages) =>
Promise.map(images, function (d) { Bluebird.map(images, function (d) {
const serviceImage = serviceImages[d.serviceName]; const serviceImage = serviceImages[d.serviceName];
const imageName = serviceImage.is_stored_at__image_location; const imageName = serviceImage.is_stored_at__image_location;
const match = /(.*?)\/(.*?)(?::([^/]*))?$/.exec(imageName); const match = /(.*?)\/(.*?)(?::([^/]*))?$/.exec(imageName);
@ -610,7 +610,7 @@ export const tagServiceImages = (docker, images, serviceImages) =>
* @param {import('docker-toolbelt')} docker * @param {import('docker-toolbelt')} docker
* @param {import('./logger')} logger * @param {import('./logger')} logger
* @param {number} appID * @param {number} appID
* @returns {Promise<string[]>} * @returns {Bluebird<string[]>}
*/ */
export const getPreviousRepos = (sdk, docker, logger, appID) => export const getPreviousRepos = (sdk, docker, logger, appID) =>
sdk.pine sdk.pine
@ -635,7 +635,7 @@ export const getPreviousRepos = (sdk, docker, logger, appID) =>
// grab all images from the latest release, return all image locations in the registry // grab all images from the latest release, return all image locations in the registry
if (release.length > 0) { if (release.length > 0) {
const images = release[0].contains__image; const images = release[0].contains__image;
return Promise.map(images, function (d) { return Bluebird.map(images, function (d) {
const imageName = d.image[0].is_stored_at__image_location; const imageName = d.image[0].is_stored_at__image_location;
return docker.getRegistryAndName(imageName).then(function (registry) { return docker.getRegistryAndName(imageName).then(function (registry) {
logger.logDebug( logger.logDebug(
@ -659,7 +659,7 @@ export const getPreviousRepos = (sdk, docker, logger, appID) =>
* @param {string} registry * @param {string} registry
* @param {string[]} images * @param {string[]} images
* @param {string[]} previousRepos * @param {string[]} previousRepos
* @returns {Promise<string>} * @returns {Bluebird<string>}
*/ */
export const authorizePush = function ( export const authorizePush = function (
sdk, sdk,
@ -712,9 +712,9 @@ export const pushAndUpdateServiceImages = function (
); );
const reporters = progress.aggregateProgress(images.length, renderer); const reporters = progress.aggregateProgress(images.length, renderer);
return Promise.using(tty.cursorHidden(), () => return Bluebird.using(tty.cursorHidden(), () =>
Promise.map(images, ({ serviceImage, localImage, props, logs }, index) => Bluebird.map(images, ({ serviceImage, localImage, props, logs }, index) =>
Promise.join( Bluebird.join(
// @ts-ignore // @ts-ignore
localImage.inspect().get('Size'), localImage.inspect().get('Size'),
retry( retry(

View File

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import BalenaSdk = require('balena-sdk'); import BalenaSdk = require('balena-sdk');
import * as semver from 'balena-semver'; import * as semver from 'balena-semver';
import Promise = require('bluebird'); import Bluebird = require('bluebird');
import { getBalenaSdk } from './lazy'; import { getBalenaSdk } from './lazy';
export interface ImgConfig { export interface ImgConfig {
@ -62,7 +62,7 @@ export function generateBaseConfig(
sshKeys?: string[]; sshKeys?: string[];
}; };
}, },
): Promise<ImgConfig> { ): Bluebird<ImgConfig> {
options = { options = {
...options, ...options,
appUpdatePollInterval: options.appUpdatePollInterval || 10, appUpdatePollInterval: options.appUpdatePollInterval || 10,
@ -71,7 +71,7 @@ export function generateBaseConfig(
const promise = getBalenaSdk().models.os.getConfig( const promise = getBalenaSdk().models.os.getConfig(
application.app_name, application.app_name,
options, options,
) as Promise<ImgConfig & { apiKey?: string }>; ) as Bluebird<ImgConfig & { apiKey?: string }>;
return promise.tap((config) => { return promise.tap((config) => {
// os.getConfig always returns a config for an app // os.getConfig always returns a config for an app
delete config.apiKey; delete config.apiKey;
@ -155,7 +155,7 @@ function addDeviceKey(
uuid: string, uuid: string,
customDeviceApiKey: string | true, customDeviceApiKey: string | true,
) { ) {
return Promise.try(() => { return Bluebird.try(() => {
if (customDeviceApiKey === true) { if (customDeviceApiKey === true) {
return getBalenaSdk().models.device.generateDeviceKey(uuid); return getBalenaSdk().models.device.generateDeviceKey(uuid);
} else { } else {

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import { getVisuals } from './lazy'; import { getVisuals } from './lazy';
const getBuilderPushEndpoint = function (baseUrl, owner, app) { const getBuilderPushEndpoint = function (baseUrl, owner, app) {
@ -36,7 +36,7 @@ const bufferImage = function (docker, imageId, bufferFile) {
const image = docker.getImage(imageId); const image = docker.getImage(imageId);
const imageMetadata = image.inspect(); const imageMetadata = image.inspect();
return Promise.join( return Bluebird.join(
image.get(), image.get(),
imageMetadata.get('Size'), imageMetadata.get('Size'),
(imageStream, imageSize) => (imageStream, imageSize) =>
@ -55,7 +55,7 @@ const showPushProgress = function (message) {
}; };
const uploadToPromise = (uploadRequest, logger) => const uploadToPromise = (uploadRequest, logger) =>
new Promise(function (resolve, reject) { new Bluebird(function (resolve, reject) {
const handleMessage = function (data) { const handleMessage = function (data) {
let obj; let obj;
data = data.toString(); data = data.toString();
@ -88,7 +88,7 @@ const uploadToPromise = (uploadRequest, logger) =>
}); });
/** /**
* @returns {Promise<{ buildId: number }>} * @returns {Bluebird<{ buildId: number }>}
*/ */
const uploadImage = function ( const uploadImage = function (
imageStream, imageStream,
@ -168,7 +168,7 @@ export const deployLegacy = function (
opts, opts,
) { ) {
const tmp = require('tmp'); const tmp = require('tmp');
const tmpNameAsync = Promise.promisify(tmp.tmpName); const tmpNameAsync = Bluebird.promisify(tmp.tmpName);
// Ensure the tmp files gets deleted // Ensure the tmp files gets deleted
tmp.setGracefulCleanup(); tmp.setGracefulCleanup();
@ -187,7 +187,7 @@ export const deployLegacy = function (
// If the file was never written to (for instance because an error // If the file was never written to (for instance because an error
// has occured before any data was written) this call will throw an // has occured before any data was written) this call will throw an
// ugly error, just suppress it // ugly error, just suppress it
Promise.try(() => require('mz/fs').unlink(bufferFile)).catchReturn( Bluebird.try(() => require('mz/fs').unlink(bufferFile)).catchReturn(
undefined, undefined,
), ),
); );
@ -198,7 +198,7 @@ export const deployLegacy = function (
} }
logger.logInfo('Uploading logs...'); logger.logInfo('Uploading logs...');
return Promise.join( return Bluebird.join(
logs, logs,
token, token,
url, url,

View File

@ -17,7 +17,7 @@
// Functions to help actions which rely on using docker // Functions to help actions which rely on using docker
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import * as _ from 'lodash'; import * as _ from 'lodash';
// Use this function to seed an action's list of capitano options // Use this function to seed an action's list of capitano options
@ -109,7 +109,7 @@ Implements the same feature as the "docker build --cache-from" option.`,
const generateConnectOpts = function (opts) { const generateConnectOpts = function (opts) {
const fs = require('mz/fs'); const fs = require('mz/fs');
return Promise.try(function () { return Bluebird.try(function () {
const connectOpts = {}; const connectOpts = {};
// Firsly need to decide between a local docker socket // Firsly need to decide between a local docker socket
// and a host available over a host:port combo // and a host available over a host:port combo
@ -152,7 +152,7 @@ const generateConnectOpts = function (opts) {
cert: fs.readFile(opts.cert, 'utf-8'), cert: fs.readFile(opts.cert, 'utf-8'),
key: fs.readFile(opts.key, 'utf-8'), key: fs.readFile(opts.key, 'utf-8'),
}; };
return Promise.props(certBodies).then((toMerge) => return Bluebird.props(certBodies).then((toMerge) =>
_.merge(connectOpts, toMerge), _.merge(connectOpts, toMerge),
); );
} }
@ -212,7 +212,7 @@ export function generateBuildOpts(options) {
* port?: number; * port?: number;
* timeout?: number; * timeout?: number;
* }} options * }} options
* @returns {Promise<import('docker-toolbelt')>} * @returns {Bluebird<import('docker-toolbelt')>}
*/ */
export function getDocker(options) { export function getDocker(options) {
return generateConnectOpts(options) return generateConnectOpts(options)
@ -222,17 +222,17 @@ export function getDocker(options) {
const getDockerToolbelt = _.once(function () { const getDockerToolbelt = _.once(function () {
const Docker = require('docker-toolbelt'); const Docker = require('docker-toolbelt');
Promise.promisifyAll(Docker.prototype, { Bluebird.promisifyAll(Docker.prototype, {
filter(name) { filter(name) {
return name === 'run'; return name === 'run';
}, },
multiArgs: true, multiArgs: true,
}); });
Promise.promisifyAll(Docker.prototype); Bluebird.promisifyAll(Docker.prototype);
// @ts-ignore `getImage()` should have a param but this whole thing is a hack that should be removed // @ts-ignore `getImage()` should have a param but this whole thing is a hack that should be removed
Promise.promisifyAll(new Docker({}).getImage().constructor.prototype); Bluebird.promisifyAll(new Docker({}).getImage().constructor.prototype);
// @ts-ignore `getContainer()` should have a param but this whole thing is a hack that should be removed // @ts-ignore `getContainer()` should have a param but this whole thing is a hack that should be removed
Promise.promisifyAll(new Docker({}).getContainer().constructor.prototype); Bluebird.promisifyAll(new Docker({}).getContainer().constructor.prototype);
return Docker; return Docker;
}); });

View File

@ -14,20 +14,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import Promise = require('bluebird'); import Bluebird = require('bluebird');
import fs = require('fs'); import fs = require('fs');
export function buffer( export function buffer(
stream: NodeJS.ReadableStream, stream: NodeJS.ReadableStream,
bufferFile: string, bufferFile: string,
): Promise<NodeJS.ReadableStream> { ): Bluebird<NodeJS.ReadableStream> {
const fileWriteStream = fs.createWriteStream(bufferFile); const fileWriteStream = fs.createWriteStream(bufferFile);
return new Promise(function (resolve, reject) { return new Bluebird(function (resolve, reject) {
stream.on('error', reject).on('end', resolve).pipe(fileWriteStream); stream.on('error', reject).on('end', resolve).pipe(fileWriteStream);
}).then( }).then(
() => () =>
new Promise(function (resolve, reject) { new Bluebird(function (resolve, reject) {
const fstream = fs.createReadStream(bufferFile); const fstream = fs.createReadStream(bufferFile);
fstream.on('open', () => resolve(fstream)).on('error', reject); fstream.on('open', () => resolve(fstream)).on('error', reject);

View File

@ -1,5 +1,3 @@
import * as Bluebird from 'bluebird';
const windowSize: { width?: number; height?: number } = {}; const windowSize: { width?: number; height?: number } = {};
const updateWindowSize = () => { const updateWindowSize = () => {
@ -32,8 +30,8 @@ export = (stream: NodeJS.WriteStream = process.stdout) => {
const cursorDown = (rows: number = 0) => stream.write(`\u001B[${rows}B`); const cursorDown = (rows: number = 0) => stream.write(`\u001B[${rows}B`);
const cursorHidden = () => { const cursorHidden = () => {
const Promise = require('bluebird') as typeof Bluebird; const Bluebird = require('bluebird') as typeof import('bluebird');
return Promise.try(hideCursor).disposer(() => { return Bluebird.try(hideCursor).disposer(() => {
showCursor(); showCursor();
}); });
}; };

View File

@ -1,4 +1,4 @@
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import { expect } from 'chai'; import { expect } from 'chai';
import rewire = require('rewire'); import rewire = require('rewire');
import * as sinon from 'sinon'; import * as sinon from 'sinon';
@ -19,7 +19,7 @@ describe('Utils:', function () {
)); ));
it('should eventually contain an https protocol', () => it('should eventually contain an https protocol', () =>
Promise.props({ Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'), dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'), loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'),
}).then(function ({ dashboardUrl, loginUrl }) { }).then(function ({ dashboardUrl, loginUrl }) {
@ -28,7 +28,7 @@ describe('Utils:', function () {
})); }));
it('should correctly escape a callback url without a path', () => it('should correctly escape a callback url without a path', () =>
Promise.props({ Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'), dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000'), loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000'),
}).then(function ({ dashboardUrl, loginUrl }) { }).then(function ({ dashboardUrl, loginUrl }) {
@ -37,7 +37,7 @@ describe('Utils:', function () {
})); }));
return it('should correctly escape a callback url with a path', () => return it('should correctly escape a callback url with a path', () =>
Promise.props({ Bluebird.props({
dashboardUrl: balena.settings.get('dashboardUrl'), dashboardUrl: balena.settings.get('dashboardUrl'),
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'), loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'),
}).then(function ({ dashboardUrl, loginUrl }) { }).then(function ({ dashboardUrl, loginUrl }) {
@ -70,7 +70,7 @@ describe('Utils:', function () {
describe('given the token does not authenticate with the server', function () { describe('given the token does not authenticate with the server', function () {
beforeEach(function () { beforeEach(function () {
this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn'); this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn');
return this.balenaAuthIsLoggedInStub.returns(Promise.resolve(false)); return this.balenaAuthIsLoggedInStub.returns(Bluebird.resolve(false));
}); });
afterEach(function () { afterEach(function () {
@ -112,7 +112,7 @@ describe('Utils:', function () {
return describe('given the token does authenticate with the server', function () { return describe('given the token does authenticate with the server', function () {
beforeEach(function () { beforeEach(function () {
this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn'); this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn');
return this.balenaAuthIsLoggedInStub.returns(Promise.resolve(true)); return this.balenaAuthIsLoggedInStub.returns(Bluebird.resolve(true));
}); });
afterEach(function () { afterEach(function () {

View File

@ -17,7 +17,7 @@
declare module 'balena-device-init' { declare module 'balena-device-init' {
import { DeviceType } from 'balena-sdk'; import { DeviceType } from 'balena-sdk';
import * as Promise from 'bluebird'; import * as Bluebird from 'bluebird';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
interface OperationState { interface OperationState {
@ -84,18 +84,18 @@ declare module 'balena-device-init' {
manifest: DeviceType, manifest: DeviceType,
config: {}, config: {},
options?: {}, options?: {},
): Promise<InitializeEmitter>; ): Bluebird<InitializeEmitter>;
export function initialize( export function initialize(
image: string, image: string,
manifest: DeviceType, manifest: DeviceType,
config: {}, config: {},
): Promise<InitializeEmitter>; ): Bluebird<InitializeEmitter>;
export function getImageOsVersion( export function getImageOsVersion(
image: string, image: string,
manifest: DeviceType, manifest: DeviceType,
): Promise<string | null>; ): Bluebird<string | null>;
export function getImageManifest(image: string): Promise<DeviceType | null>; export function getImageManifest(image: string): Bluebird<DeviceType | null>;
} }

View File

@ -16,6 +16,6 @@
*/ */
declare module 'nplugm' { declare module 'nplugm' {
import Promise = require('bluebird'); import Bluebird = require('bluebird');
export function list(regexp: RegExp): Promise<string[]>; export function list(regexp: RegExp): Bluebird<string[]>;
} }

View File

@ -16,7 +16,7 @@
*/ */
declare module 'resin-image-fs' { declare module 'resin-image-fs' {
import Promise = require('bluebird'); import Bluebird = require('bluebird');
export interface ImageDefinition { export interface ImageDefinition {
image: string; image: string;
@ -24,14 +24,16 @@ declare module 'resin-image-fs' {
path: string; path: string;
} }
export function readFile(options: {}): Promise<string>; export function readFile(options: {}): Bluebird<string>;
export function writeFile( export function writeFile(
definition: ImageDefinition, definition: ImageDefinition,
contents: string, contents: string,
): Promise<void>; ): Bluebird<void>;
export function copy( export function copy(
input: ImageDefinition, input: ImageDefinition,
output: ImageDefinition, output: ImageDefinition,
): Promise<void>; ): Bluebird<void>;
export function listDirectory(definition: ImageDefinition): Promise<string[]>; export function listDirectory(
definition: ImageDefinition,
): Bluebird<string[]>;
} }