diff --git a/lib/actions/build.js b/lib/actions/build.js index 0954e031..f8b38519 100644 --- a/lib/actions/build.js +++ b/lib/actions/build.js @@ -17,7 +17,7 @@ // Imported here because it's needed for the setup // of this action -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as dockerUtils from '../utils/docker'; 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 { loadProject } = require('../utils/compose_ts'); - return Promise.resolve(loadProject(logger, composeOpts)) + return Bluebird.resolve(loadProject(logger, composeOpts)) .then(function (project) { const appType = opts.app?.application_type?.[0]; if ( @@ -154,7 +154,7 @@ Examples: const { application, arch, deviceType } = options; - return Promise.try(function () { + return Bluebird.try(function () { if ( (application == null && (arch == null || deviceType == null)) || (application != null && (arch != null || deviceType != null)) @@ -189,7 +189,7 @@ Examples: }) .then(function ([app, resolvedArch, resolvedDeviceType]) { - return Promise.join( + return Bluebird.join( dockerUtils.getDocker(options), dockerUtils.generateBuildOpts(options), compose.generateOpts(options), diff --git a/lib/actions/config.js b/lib/actions/config.js index 91070509..3d2c96f1 100644 --- a/lib/actions/config.js +++ b/lib/actions/config.js @@ -49,12 +49,12 @@ Examples: permission: 'user', root: true, action(_params, options) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const config = require('balena-config-json'); - const umountAsync = Promise.promisify(require('umount').umount); + const umountAsync = Bluebird.promisify(require('umount').umount); const prettyjson = require('prettyjson'); - return Promise.try( + return Bluebird.try( () => options.drive || getVisuals().drive('Select the device drive'), ) .tap(umountAsync) @@ -96,12 +96,12 @@ Examples: permission: 'user', root: true, action(params, options) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const _ = require('lodash'); 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'), ) .tap(umountAsync) @@ -153,13 +153,13 @@ Examples: permission: 'user', root: true, action(params, options) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const util = require('util'); 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); - return Promise.try( + return Bluebird.try( () => options.drive || getVisuals().drive('Select the device drive'), ) .tap(umountAsync) @@ -211,12 +211,12 @@ Examples: permission: 'user', root: true, action(_params, options) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const config = require('balena-config-json'); 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'), ) .tap(umountAsync) @@ -311,8 +311,8 @@ Examples: permission: 'user', action(_params, options) { normalizeUuidProp(options, 'device'); - const Promise = require('bluebird'); - const writeFileAsync = Promise.promisify(require('fs').writeFile); + const Bluebird = require('bluebird'); + const writeFileAsync = Bluebird.promisify(require('fs').writeFile); const balena = getBalenaSdk(); const form = require('resin-cli-form'); const prettyjson = require('prettyjson'); @@ -348,7 +348,7 @@ See the help page for examples: `); } - return Promise.try( + return Bluebird.try( /** @returns {Promise} */ function () { if (options.device != null) { return balena.models.device.get(options.device); diff --git a/lib/actions/deploy.js b/lib/actions/deploy.js index 7cada2dc..bd194ab7 100644 --- a/lib/actions/deploy.js +++ b/lib/actions/deploy.js @@ -17,7 +17,7 @@ // Imported here because it's needed for the setup // of this action -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as dockerUtils from '../utils/docker'; import * as compose from '../utils/compose'; @@ -45,7 +45,7 @@ const deployProject = function (docker, logger, composeOpts, opts) { loadProject, } = require('../utils/compose_ts'); - return Promise.resolve(loadProject(logger, composeOpts, opts.image)) + return Bluebird.resolve(loadProject(logger, composeOpts, opts.image)) .then(function (project) { if ( project.descriptors.length > 1 && @@ -58,7 +58,7 @@ const deployProject = function (docker, logger, composeOpts, opts) { // find which services use images that already exist locally return ( - Promise.map(project.descriptors, function (d) { + Bluebird.map(project.descriptors, function (d) { // unconditionally build (or pull) if explicitly requested if (opts.shouldPerformBuild) { return d; @@ -124,7 +124,7 @@ const deployProject = function (docker, logger, composeOpts, opts) { ); logger.logWarn(msg); - return Promise.join( + return Bluebird.join( docker, logger, sdk.auth.getToken(), @@ -145,7 +145,7 @@ const deployProject = function (docker, logger, composeOpts, opts) { sdk.models.release.get(releaseId, { $select: ['commit'] }), ); } - return Promise.join( + return Bluebird.join( sdk.auth.getUserId(), sdk.auth.getToken(), sdk.settings.get('apiUrl'), @@ -263,7 +263,7 @@ Examples: appName = appName_raw || appName || options.application; delete options.application; - return Promise.try(function () { + return Bluebird.try(function () { if (appName == null) { throw new ExpectedError( 'Please specify the name of the application to deploy', @@ -297,7 +297,7 @@ Examples: }) .then(() => helpers.getAppWithArch(appName)) .then(function (app) { - return Promise.join( + return Bluebird.join( dockerUtils.getDocker(options), dockerUtils.generateBuildOpts(options), compose.generateOpts(options), diff --git a/lib/actions/device.js b/lib/actions/device.js index 471453bc..0cec6b04 100644 --- a/lib/actions/device.js +++ b/lib/actions/device.js @@ -50,17 +50,17 @@ Examples: ], permission: 'user', action(_params, options) { - const Promise = require('bluebird'); - const rimraf = Promise.promisify(require('rimraf')); + const Bluebird = require('bluebird'); + const rimraf = Bluebird.promisify(require('rimraf')); const tmp = require('tmp'); - const tmpNameAsync = Promise.promisify(tmp.tmpName); + const tmpNameAsync = Bluebird.promisify(tmp.tmpName); tmp.setGracefulCleanup(); const balena = getBalenaSdk(); const patterns = require('../utils/patterns'); const { runCommand } = require('../utils/helpers'); - return Promise.try(function () { + return Bluebird.try(function () { if (options.application != null) { return options.application; } @@ -78,7 +78,7 @@ Examples: }) .disposer((tempPath) => rimraf(tempPath)); - return Promise.using(download(), (tempPath) => + return Bluebird.using(download(), (tempPath) => runCommand(`device register ${application.app_name}`) .then(balena.models.device.get) .tap(function (device) { diff --git a/lib/actions/local/common.js b/lib/actions/local/common.js index 11d1d644..7bf3d50c 100644 --- a/lib/actions/local/common.js +++ b/lib/actions/local/common.js @@ -1,4 +1,4 @@ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as _ from 'lodash'; import * as dockerUtils from '../../utils/docker'; import { exitWithExpectedError } from '../../errors'; @@ -19,7 +19,7 @@ export const filterOutSupervisorContainer = function (container) { return true; }; -export const selectContainerFromDevice = Promise.method(function ( +export const selectContainerFromDevice = Bluebird.method(function ( deviceIp, filterSupervisor, ) { @@ -61,7 +61,7 @@ export const selectContainerFromDevice = Promise.method(function ( }); }); -export const pipeContainerStream = Promise.method(function ({ +export const pipeContainerStream = Bluebird.method(function ({ deviceIp, name, outStream, diff --git a/lib/actions/local/configure.js b/lib/actions/local/configure.js index 4a565e0e..de656ef0 100644 --- a/lib/actions/local/configure.js +++ b/lib/actions/local/configure.js @@ -234,13 +234,13 @@ Examples: `, root: true, action(params) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const path = require('path'); const umount = require('umount'); - const umountAsync = Promise.promisify(umount.umount); - const isMountedAsync = Promise.promisify(umount.isMounted); + const umountAsync = Bluebird.promisify(umount.umount); + const isMountedAsync = Bluebird.promisify(umount.isMounted); const reconfix = require('reconfix'); - const denymount = Promise.promisify(require('denymount')); + const denymount = Bluebird.promisify(require('denymount')); return prepareConnectionFile(params.target) .tap(() => diff --git a/lib/actions/os.js b/lib/actions/os.js index c9d7a250..7fd790b3 100644 --- a/lib/actions/os.js +++ b/lib/actions/os.js @@ -114,7 +114,7 @@ Examples: commandOptions.osVersionOrSemver, ], action(params, options) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const unzip = require('node-unzip-2'); const fs = require('fs'); const rindle = require('rindle'); @@ -123,7 +123,7 @@ Examples: console.info(`Getting device operating system for ${params.type}`); let displayVersion = ''; - return Promise.try(function () { + return Bluebird.try(function () { if (!options.version) { console.warn(`OS version is not specified, using the default version: \ the newest stable (non-pre-release) version if available, \ @@ -205,10 +205,10 @@ const $buildConfig = function (image, deviceTypeSlug, advanced) { if (advanced == null) { advanced = false; } - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const helpers = require('../utils/helpers'); - return Promise.resolve( + return Bluebird.resolve( helpers.getManifest(image, deviceTypeSlug), ).then((deviceTypeManifest) => buildConfigForDeviceType(deviceTypeManifest, advanced), @@ -239,8 +239,8 @@ Example: ], action(params, options) { const fs = require('fs'); - const Promise = require('bluebird'); - const writeFileAsync = Promise.promisify(fs.writeFile); + const Bluebird = require('bluebird'); + const writeFileAsync = Bluebird.promisify(fs.writeFile); return $buildConfig( params.image, @@ -283,8 +283,8 @@ Examples: commandOptions.drive, ], action(params, options) { - const Promise = require('bluebird'); - const umountAsync = Promise.promisify(require('umount').umount); + const Bluebird = require('bluebird'); + const umountAsync = Bluebird.promisify(require('umount').umount); const form = require('resin-cli-form'); const patterns = require('../utils/patterns'); const helpers = require('../utils/helpers'); @@ -294,7 +294,7 @@ Initializing device ${INIT_WARNING_MESSAGE}\ `); - return Promise.resolve(helpers.getManifest(params.image, options.type)) + return Bluebird.resolve(helpers.getManifest(params.image, options.type)) .then((manifest) => form.run(manifest.initialization?.options, { override: { diff --git a/lib/actions/preload.js b/lib/actions/preload.js index 4abd2da3..48ca0e11 100644 --- a/lib/actions/preload.js +++ b/lib/actions/preload.js @@ -138,7 +138,7 @@ const offerToDisableAutomaticUpdates = function ( commit, pinDevice, ) { - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const balena = getBalenaSdk(); const form = require('resin-cli-form'); @@ -147,7 +147,7 @@ const offerToDisableAutomaticUpdates = function ( !application.should_track_latest_release || pinDevice ) { - return Promise.resolve(); + return Bluebird.resolve(); } const message = `\ @@ -256,7 +256,7 @@ Examples: options: preloadOptions, action(params, options, done) { let certificates; - const Promise = require('bluebird'); + const Bluebird = require('bluebird'); const balena = getBalenaSdk(); const balenaPreload = require('balena-preload'); const visuals = getVisuals(); @@ -358,7 +358,7 @@ Examples: preloader.on('progress', progressHandler); preloader.on('spinner', spinnerHandler); - return new Promise(function (resolve, reject) { + return new Bluebird(function (resolve, reject) { preloader.on('error', reject); return preloader diff --git a/lib/app-capitano.js b/lib/app-capitano.js index da72f08a..c095e8bb 100644 --- a/lib/app-capitano.js +++ b/lib/app-capitano.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as capitano from 'capitano'; import * as actions from './actions'; @@ -92,7 +92,7 @@ capitano.command(actions.push.push); export function run(argv) { const cli = capitano.parse(argv.slice(2)); const runCommand = function () { - const capitanoExecuteAsync = Promise.promisify(capitano.execute); + const capitanoExecuteAsync = Bluebird.promisify(capitano.execute); if (cli.global?.help) { return capitanoExecuteAsync({ command: `help ${cli.command ?? ''}`, @@ -103,7 +103,7 @@ export function run(argv) { }; const trackCommand = function () { - const getMatchCommandAsync = Promise.promisify( + const getMatchCommandAsync = Bluebird.promisify( capitano.state.getMatchCommand, ); 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, ); } diff --git a/lib/auth/server.ts b/lib/auth/server.ts index 2d37c1b7..79121588 100644 --- a/lib/auth/server.ts +++ b/lib/auth/server.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as bodyParser from 'body-parser'; import * as express from 'express'; import { Socket } from 'net'; @@ -78,10 +78,10 @@ export function shutdownServer() { export const awaitForToken = (options: { path: string; port: number; -}): Promise => { +}): Bluebird => { const { app, server } = createServer({ port: options.port }); - return new Promise((resolve, reject) => { + return new Bluebird((resolve, reject) => { app.post(options.path, async (request, response) => { server.close(); // stop listening for new connections try { diff --git a/lib/auth/utils.ts b/lib/auth/utils.ts index 82bcb6be..7fc862c1 100644 --- a/lib/auth/utils.ts +++ b/lib/auth/utils.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as _ from 'lodash'; import * as url from 'url'; import { getBalenaSdk } from '../utils/lazy'; @@ -26,7 +26,7 @@ import { getBalenaSdk } from '../utils/lazy'; * * @param {String} callbackUrl - callback url * @fulfil {String} - dashboard login url - * @returns {Promise} + * @returns {Bluebird} * * @example * 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 * @fulfil {Boolean} - whether the login was successful or not - * @returns {Promise} + * @returns {Bluebird} * * utils.loginIfTokenValid('...').then (loggedIn) -> * if loggedIn @@ -66,7 +66,7 @@ export const getDashboardLoginURL = (callbackUrl: string) => { */ export const loginIfTokenValid = (token: string) => { if (_.isEmpty(token?.trim())) { - return Promise.resolve(false); + return Bluebird.resolve(false); } const balena = getBalenaSdk(); diff --git a/lib/utils/compose.js b/lib/utils/compose.js index 64c9dd1a..53da8aa7 100644 --- a/lib/utils/compose.js +++ b/lib/utils/compose.js @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import { stripIndent } from 'common-tags'; 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). * @param {string} dir Source directory * @param {import('./compose-types').TarDirectoryOptions} param - * @returns {Promise} + * @returns {Bluebird} */ export function tarDirectory(dir, param) { let { nogitignore = false } = param; if (nogitignore) { - return Promise.resolve(require('./compose_ts').tarDirectory(dir, param)); + return Bluebird.resolve(require('./compose_ts').tarDirectory(dir, param)); } else { return originalTarDirectory(dir, param); } @@ -199,7 +199,7 @@ export function tarDirectory(dir, param) { * deleted in CLI v13. * @param {string} dir Source directory * @param {import('./compose-types').TarDirectoryOptions} param - * @returns {Promise} + * @returns {Bluebird} */ function originalTarDirectory(dir, param) { let { @@ -228,7 +228,7 @@ function originalTarDirectory(dir, param) { const getFiles = () => // @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()) .map((item) => item.path); @@ -255,7 +255,7 @@ function originalTarDirectory(dir, param) { .filter(ignore.filter) .map(function (file) { const relPath = path.relative(path.resolve(dir), file); - return Promise.join( + return Bluebird.join( relPath, fs.stat(file), readFile(file), @@ -344,7 +344,7 @@ export function buildProject( } renderer.start(); - return Promise.resolve(checkBuildSecretsRequirements(docker, projectPath)) + return Bluebird.resolve(checkBuildSecretsRequirements(docker, projectPath)) .then(() => qemu.installQemuIfNeeded(emulated, logger, arch, docker)) .tap(function (needsQemu) { if (!needsQemu) { @@ -352,7 +352,7 @@ export function buildProject( } logger.logInfo('Emulation is enabled'); // 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) { return; } @@ -468,7 +468,7 @@ export function buildProject( }) .then(function (tasks) { logger.logDebug('Prepared tasks; building...'); - return Promise.map( + return Bluebird.map( builder.performBuilds(tasks, docker, BALENA_ENGINE_TMP_PATH), function (builtImage) { if (!builtImage.successful) { @@ -529,7 +529,7 @@ export function buildProject( * @param {number} userId * @param {number} appId * @param {import('resin-compose-parse').Composition} composition - * @returns {Promise} + * @returns {Bluebird} */ export const createRelease = function ( apiEndpoint, @@ -578,10 +578,10 @@ export const createRelease = function ( * @param {import('docker-toolbelt')} docker * @param {Array} images * @param {Partial} serviceImages - * @returns {Promise>} + * @returns {Bluebird>} */ export const tagServiceImages = (docker, images, serviceImages) => - Promise.map(images, function (d) { + Bluebird.map(images, function (d) { const serviceImage = serviceImages[d.serviceName]; const imageName = serviceImage.is_stored_at__image_location; const match = /(.*?)\/(.*?)(?::([^/]*))?$/.exec(imageName); @@ -610,7 +610,7 @@ export const tagServiceImages = (docker, images, serviceImages) => * @param {import('docker-toolbelt')} docker * @param {import('./logger')} logger * @param {number} appID - * @returns {Promise} + * @returns {Bluebird} */ export const getPreviousRepos = (sdk, docker, logger, appID) => 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 if (release.length > 0) { 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; return docker.getRegistryAndName(imageName).then(function (registry) { logger.logDebug( @@ -659,7 +659,7 @@ export const getPreviousRepos = (sdk, docker, logger, appID) => * @param {string} registry * @param {string[]} images * @param {string[]} previousRepos - * @returns {Promise} + * @returns {Bluebird} */ export const authorizePush = function ( sdk, @@ -712,9 +712,9 @@ export const pushAndUpdateServiceImages = function ( ); const reporters = progress.aggregateProgress(images.length, renderer); - return Promise.using(tty.cursorHidden(), () => - Promise.map(images, ({ serviceImage, localImage, props, logs }, index) => - Promise.join( + return Bluebird.using(tty.cursorHidden(), () => + Bluebird.map(images, ({ serviceImage, localImage, props, logs }, index) => + Bluebird.join( // @ts-ignore localImage.inspect().get('Size'), retry( diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 53dd0d43..974c1e43 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -15,7 +15,7 @@ limitations under the License. */ import BalenaSdk = require('balena-sdk'); import * as semver from 'balena-semver'; -import Promise = require('bluebird'); +import Bluebird = require('bluebird'); import { getBalenaSdk } from './lazy'; export interface ImgConfig { @@ -62,7 +62,7 @@ export function generateBaseConfig( sshKeys?: string[]; }; }, -): Promise { +): Bluebird { options = { ...options, appUpdatePollInterval: options.appUpdatePollInterval || 10, @@ -71,7 +71,7 @@ export function generateBaseConfig( const promise = getBalenaSdk().models.os.getConfig( application.app_name, options, - ) as Promise; + ) as Bluebird; return promise.tap((config) => { // os.getConfig always returns a config for an app delete config.apiKey; @@ -155,7 +155,7 @@ function addDeviceKey( uuid: string, customDeviceApiKey: string | true, ) { - return Promise.try(() => { + return Bluebird.try(() => { if (customDeviceApiKey === true) { return getBalenaSdk().models.device.generateDeviceKey(uuid); } else { diff --git a/lib/utils/deploy-legacy.js b/lib/utils/deploy-legacy.js index ef3e4d58..f96e58f0 100644 --- a/lib/utils/deploy-legacy.js +++ b/lib/utils/deploy-legacy.js @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import { getVisuals } from './lazy'; const getBuilderPushEndpoint = function (baseUrl, owner, app) { @@ -36,7 +36,7 @@ const bufferImage = function (docker, imageId, bufferFile) { const image = docker.getImage(imageId); const imageMetadata = image.inspect(); - return Promise.join( + return Bluebird.join( image.get(), imageMetadata.get('Size'), (imageStream, imageSize) => @@ -55,7 +55,7 @@ const showPushProgress = function (message) { }; const uploadToPromise = (uploadRequest, logger) => - new Promise(function (resolve, reject) { + new Bluebird(function (resolve, reject) { const handleMessage = function (data) { let obj; data = data.toString(); @@ -88,7 +88,7 @@ const uploadToPromise = (uploadRequest, logger) => }); /** - * @returns {Promise<{ buildId: number }>} + * @returns {Bluebird<{ buildId: number }>} */ const uploadImage = function ( imageStream, @@ -168,7 +168,7 @@ export const deployLegacy = function ( opts, ) { const tmp = require('tmp'); - const tmpNameAsync = Promise.promisify(tmp.tmpName); + const tmpNameAsync = Bluebird.promisify(tmp.tmpName); // Ensure the tmp files gets deleted tmp.setGracefulCleanup(); @@ -187,7 +187,7 @@ export const deployLegacy = function ( // If the file was never written to (for instance because an error // has occured before any data was written) this call will throw an // ugly error, just suppress it - Promise.try(() => require('mz/fs').unlink(bufferFile)).catchReturn( + Bluebird.try(() => require('mz/fs').unlink(bufferFile)).catchReturn( undefined, ), ); @@ -198,7 +198,7 @@ export const deployLegacy = function ( } logger.logInfo('Uploading logs...'); - return Promise.join( + return Bluebird.join( logs, token, url, diff --git a/lib/utils/docker-js.js b/lib/utils/docker-js.js index 287e3abc..8ffbdd2b 100644 --- a/lib/utils/docker-js.js +++ b/lib/utils/docker-js.js @@ -17,7 +17,7 @@ // Functions to help actions which rely on using docker -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import * as _ from 'lodash'; // 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 fs = require('mz/fs'); - return Promise.try(function () { + return Bluebird.try(function () { const connectOpts = {}; // Firsly need to decide between a local docker socket // and a host available over a host:port combo @@ -152,7 +152,7 @@ const generateConnectOpts = function (opts) { cert: fs.readFile(opts.cert, 'utf-8'), key: fs.readFile(opts.key, 'utf-8'), }; - return Promise.props(certBodies).then((toMerge) => + return Bluebird.props(certBodies).then((toMerge) => _.merge(connectOpts, toMerge), ); } @@ -212,7 +212,7 @@ export function generateBuildOpts(options) { * port?: number; * timeout?: number; * }} options - * @returns {Promise} + * @returns {Bluebird} */ export function getDocker(options) { return generateConnectOpts(options) @@ -222,17 +222,17 @@ export function getDocker(options) { const getDockerToolbelt = _.once(function () { const Docker = require('docker-toolbelt'); - Promise.promisifyAll(Docker.prototype, { + Bluebird.promisifyAll(Docker.prototype, { filter(name) { return name === 'run'; }, 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 - 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 - Promise.promisifyAll(new Docker({}).getContainer().constructor.prototype); + Bluebird.promisifyAll(new Docker({}).getContainer().constructor.prototype); return Docker; }); diff --git a/lib/utils/streams.ts b/lib/utils/streams.ts index 6f197868..0f589208 100644 --- a/lib/utils/streams.ts +++ b/lib/utils/streams.ts @@ -14,20 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Promise = require('bluebird'); +import Bluebird = require('bluebird'); import fs = require('fs'); export function buffer( stream: NodeJS.ReadableStream, bufferFile: string, -): Promise { +): Bluebird { 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); }).then( () => - new Promise(function (resolve, reject) { + new Bluebird(function (resolve, reject) { const fstream = fs.createReadStream(bufferFile); fstream.on('open', () => resolve(fstream)).on('error', reject); diff --git a/lib/utils/tty.ts b/lib/utils/tty.ts index 2efc0237..a3d85614 100644 --- a/lib/utils/tty.ts +++ b/lib/utils/tty.ts @@ -1,5 +1,3 @@ -import * as Bluebird from 'bluebird'; - const windowSize: { width?: number; height?: number } = {}; const updateWindowSize = () => { @@ -32,8 +30,8 @@ export = (stream: NodeJS.WriteStream = process.stdout) => { const cursorDown = (rows: number = 0) => stream.write(`\u001B[${rows}B`); const cursorHidden = () => { - const Promise = require('bluebird') as typeof Bluebird; - return Promise.try(hideCursor).disposer(() => { + const Bluebird = require('bluebird') as typeof import('bluebird'); + return Bluebird.try(hideCursor).disposer(() => { showCursor(); }); }; diff --git a/tests/auth/utils.spec.ts b/tests/auth/utils.spec.ts index 8536bac6..918cc2e8 100644 --- a/tests/auth/utils.spec.ts +++ b/tests/auth/utils.spec.ts @@ -1,4 +1,4 @@ -import * as Promise from 'bluebird'; +import * as Bluebird from 'bluebird'; import { expect } from 'chai'; import rewire = require('rewire'); import * as sinon from 'sinon'; @@ -19,7 +19,7 @@ describe('Utils:', function () { )); it('should eventually contain an https protocol', () => - Promise.props({ + Bluebird.props({ dashboardUrl: balena.settings.get('dashboardUrl'), loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'), }).then(function ({ dashboardUrl, loginUrl }) { @@ -28,7 +28,7 @@ describe('Utils:', function () { })); it('should correctly escape a callback url without a path', () => - Promise.props({ + Bluebird.props({ dashboardUrl: balena.settings.get('dashboardUrl'), loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000'), }).then(function ({ dashboardUrl, loginUrl }) { @@ -37,7 +37,7 @@ describe('Utils:', function () { })); return it('should correctly escape a callback url with a path', () => - Promise.props({ + Bluebird.props({ dashboardUrl: balena.settings.get('dashboardUrl'), loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'), }).then(function ({ dashboardUrl, loginUrl }) { @@ -70,7 +70,7 @@ describe('Utils:', function () { describe('given the token does not authenticate with the server', function () { beforeEach(function () { this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn'); - return this.balenaAuthIsLoggedInStub.returns(Promise.resolve(false)); + return this.balenaAuthIsLoggedInStub.returns(Bluebird.resolve(false)); }); afterEach(function () { @@ -112,7 +112,7 @@ describe('Utils:', function () { return describe('given the token does authenticate with the server', function () { beforeEach(function () { this.balenaAuthIsLoggedInStub = sinon.stub(balena.auth, 'isLoggedIn'); - return this.balenaAuthIsLoggedInStub.returns(Promise.resolve(true)); + return this.balenaAuthIsLoggedInStub.returns(Bluebird.resolve(true)); }); afterEach(function () { diff --git a/typings/balena-device-init/index.d.ts b/typings/balena-device-init/index.d.ts index 91cdc81e..e7bffde4 100644 --- a/typings/balena-device-init/index.d.ts +++ b/typings/balena-device-init/index.d.ts @@ -17,7 +17,7 @@ declare module 'balena-device-init' { import { DeviceType } from 'balena-sdk'; - import * as Promise from 'bluebird'; + import * as Bluebird from 'bluebird'; import { EventEmitter } from 'events'; interface OperationState { @@ -84,18 +84,18 @@ declare module 'balena-device-init' { manifest: DeviceType, config: {}, options?: {}, - ): Promise; + ): Bluebird; export function initialize( image: string, manifest: DeviceType, config: {}, - ): Promise; + ): Bluebird; export function getImageOsVersion( image: string, manifest: DeviceType, - ): Promise; + ): Bluebird; - export function getImageManifest(image: string): Promise; + export function getImageManifest(image: string): Bluebird; } diff --git a/typings/nplugm/index.d.ts b/typings/nplugm/index.d.ts index 39f2e452..05a32edb 100644 --- a/typings/nplugm/index.d.ts +++ b/typings/nplugm/index.d.ts @@ -16,6 +16,6 @@ */ declare module 'nplugm' { - import Promise = require('bluebird'); - export function list(regexp: RegExp): Promise; + import Bluebird = require('bluebird'); + export function list(regexp: RegExp): Bluebird; } diff --git a/typings/resin-image-fs/index.d.ts b/typings/resin-image-fs/index.d.ts index 820cdd92..c8da0ed3 100644 --- a/typings/resin-image-fs/index.d.ts +++ b/typings/resin-image-fs/index.d.ts @@ -16,7 +16,7 @@ */ declare module 'resin-image-fs' { - import Promise = require('bluebird'); + import Bluebird = require('bluebird'); export interface ImageDefinition { image: string; @@ -24,14 +24,16 @@ declare module 'resin-image-fs' { path: string; } - export function readFile(options: {}): Promise; + export function readFile(options: {}): Bluebird; export function writeFile( definition: ImageDefinition, contents: string, - ): Promise; + ): Bluebird; export function copy( input: ImageDefinition, output: ImageDefinition, - ): Promise; - export function listDirectory(definition: ImageDefinition): Promise; + ): Bluebird; + export function listDirectory( + definition: ImageDefinition, + ): Bluebird; }