Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bluebird dependency #118097

Merged
merged 11 commits into from
Nov 11, 2021
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
"archiver": "^5.2.0",
"axios": "^0.21.1",
"base64-js": "^1.3.1",
"bluebird": "3.5.5",
"brace": "0.11.1",
"broadcast-channel": "^4.2.0",
"chalk": "^4.1.0",
Expand Down Expand Up @@ -494,7 +493,6 @@
"@types/archiver": "^5.1.0",
"@types/babel__core": "^7.1.16",
"@types/base64-js": "^1.2.5",
"@types/bluebird": "^3.1.1",
"@types/chance": "^1.0.0",
"@types/chroma-js": "^1.4.2",
"@types/chromedriver": "^81.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-es-archiver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ RUNTIME_DEPS = [
"//packages/kbn-utils",
"@npm//@elastic/elasticsearch",
"@npm//aggregate-error",
"@npm//bluebird",
"@npm//chance",
"@npm//globby",
"@npm//json-stable-stringify",
Expand All @@ -51,7 +50,6 @@ TYPES_DEPS = [
"@npm//aggregate-error",
"@npm//globby",
"@npm//zlib",
"@npm//@types/bluebird",
"@npm//@types/chance",
"@npm//@types/jest",
"@npm//@types/json-stable-stringify",
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-es-archiver/src/actions/rebuild_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import { resolve, relative } from 'path';
import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs';
import { Stats, createReadStream, createWriteStream } from 'fs';
import { stat, rename } from 'fs/promises';
import { Readable, Writable } from 'stream';
import { fromNode } from 'bluebird';
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
import { createPromiseFromStreams } from '@kbn/utils';
import {
Expand All @@ -21,7 +21,7 @@ import {
} from '../lib';

async function isDirectory(path: string): Promise<boolean> {
const stats: Stats = await fromNode((cb) => stat(path, cb));
const stats: Stats = await stat(path);
return stats.isDirectory();
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export async function rebuildAllAction({ dataDir, log }: { dataDir: string; log:
createWriteStream(tempFile),
] as [Readable, ...Writable[]]);

await fromNode((cb) => rename(tempFile, childPath, cb));
await rename(tempFile, childPath);
log.info('[%s] Rebuilt %j', archiveName, childName);
}
}
5 changes: 2 additions & 3 deletions packages/kbn-es-archiver/src/lib/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* Side Public License, v 1.
*/

import { readdir } from 'fs';
import { fromNode } from 'bluebird';
import { readdir } from 'fs/promises';

export async function readDirectory(path: string) {
const allNames = await fromNode<string[]>((cb) => readdir(path, cb));
const allNames = await readdir(path);
return allNames.filter((name) => !name.startsWith('.'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { delay } from 'bluebird';
import { setTimeout as setTimeoutAsync } from 'timers/promises';

export default function () {
return {
Expand All @@ -22,13 +22,13 @@ export default function () {

lifecycle.testFailure.add(async (err, test) => {
log.info('testFailure %s %s', err.message, test.fullTitle());
await delay(10);
await setTimeoutAsync(10);
log.info('testFailureAfterDelay %s %s', err.message, test.fullTitle());
});

lifecycle.testHookFailure.add(async (err, test) => {
log.info('testHookFailure %s %s', err.message, test.fullTitle());
await delay(10);
await setTimeoutAsync(10);
log.info('testHookFailureAfterDelay %s %s', err.message, test.fullTitle());
});
},
Expand Down
7 changes: 0 additions & 7 deletions packages/kbn-test/src/jest/setup/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
* Side Public License, v 1.
*/

// bluebird < v3.3.5 does not work with MutationObserver polyfill
// when MutationObserver exists, bluebird avoids using node's builtin async schedulers
const bluebird = require('bluebird');
bluebird.Promise.setScheduler(function (fn) {
global.setImmediate.call(global, fn);
});

const MutationObserver = require('mutation-observer');
Object.defineProperty(window, 'MutationObserver', { value: MutationObserver });

Expand Down
8 changes: 5 additions & 3 deletions packages/kbn-test/src/mocha/junit_report_generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import { resolve } from 'path';
import { readFileSync } from 'fs';
import { readFile } from 'fs/promises';
import { promisify } from 'util';

import { fromNode as fcb } from 'bluebird';
import { parseString } from 'xml2js';
import del from 'del';
import Mocha from 'mocha';
Expand All @@ -22,6 +22,8 @@ const DURATION_REGEX = /^\d+\.\d{3}$/;
const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
const XML_PATH = getUniqueJunitReportPath(PROJECT_DIR, 'test');

const parseStringAsync = promisify(parseString);

describe('dev/mocha/junit report generation', () => {
afterEach(() => {
del.sync(resolve(PROJECT_DIR, 'target'));
Expand All @@ -39,7 +41,7 @@ describe('dev/mocha/junit report generation', () => {

mocha.addFile(resolve(PROJECT_DIR, 'test.js'));
await new Promise((resolve) => mocha.run(resolve));
const report = await fcb((cb) => parseString(readFileSync(XML_PATH), cb));
const report = await parseStringAsync(await readFile(XML_PATH));

// test case results are wrapped in <testsuites></testsuites>
expect(report).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-utils/src/streams/map_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { delay } from 'bluebird';
import { setTimeout as setTimeoutAsync } from 'timers/promises';

import { createPromiseFromStreams } from './promise_from_streams';
import { createListStream } from './list_stream';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('createMapStream()', () => {
const result = await createPromiseFromStreams([
createListStream([1, 2, 3]),
createMapStream(async (n: number, i: number) => {
await delay(n);
await setTimeoutAsync(n);
return n * i;
}),
createConcatStream([]),
Expand Down
10 changes: 6 additions & 4 deletions src/dev/notice/bundled_notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
*/

import { resolve } from 'path';
import { readFile } from 'fs';
import { readFile } from 'fs/promises';
import { promisify } from 'util';

import { fromNode as fcb } from 'bluebird';
import glob from 'glob';

const globAsync = promisify(glob);

export async function getBundledNotices(packageDirectory) {
const pattern = resolve(packageDirectory, '*{LICENSE,NOTICE}*');
const paths = await fcb((cb) => glob(pattern, cb));
const paths = await globAsync(pattern);
return Promise.all(
paths.map(async (path) => ({
path,
text: await fcb((cb) => readFile(path, 'utf8', cb)),
text: await readFile(path, 'utf8'),
}))
);
}
5 changes: 2 additions & 3 deletions src/dev/precommit_hook/get_files_for_commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* Side Public License, v 1.
*/

import SimpleGit from 'simple-git';
import { fromNode as fcb } from 'bluebird';
import SimpleGit from 'simple-git/promise';

import { REPO_ROOT } from '@kbn/utils';
import { File } from '../file';
Expand All @@ -22,7 +21,7 @@ import { File } from '../file';
export async function getFilesForCommit(gitRef) {
const simpleGit = new SimpleGit(REPO_ROOT);
const gitRefForDiff = gitRef ? gitRef : '--cached';
const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb));
const output = await simpleGit.diff(['--name-status', gitRefForDiff]);

return (
output
Expand Down
19 changes: 9 additions & 10 deletions src/plugins/saved_objects/public/saved_object/saved_object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import Bluebird from 'bluebird';
import { createSavedObjectClass } from './saved_object';
import {
SavedObject,
Expand Down Expand Up @@ -55,16 +54,16 @@ describe('Saved Object', () => {
*/
function stubESResponse(mockDocResponse: SimpleSavedObject<SavedObjectAttributes>) {
// Stub out search for duplicate title:
savedObjectsClientStub.get = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse));
savedObjectsClientStub.update = jest.fn().mockReturnValue(Bluebird.resolve(mockDocResponse));
savedObjectsClientStub.get = jest.fn().mockReturnValue(Promise.resolve(mockDocResponse));
savedObjectsClientStub.update = jest.fn().mockReturnValue(Promise.resolve(mockDocResponse));

savedObjectsClientStub.find = jest
.fn()
.mockReturnValue(Bluebird.resolve({ savedObjects: [], total: 0 }));
.mockReturnValue(Promise.resolve({ savedObjects: [], total: 0 }));

savedObjectsClientStub.bulkGet = jest
.fn()
.mockReturnValue(Bluebird.resolve({ savedObjects: [mockDocResponse] }));
.mockReturnValue(Promise.resolve({ savedObjects: [mockDocResponse] }));
}

function stubSavedObjectsClientCreate(
Expand All @@ -73,7 +72,7 @@ describe('Saved Object', () => {
) {
savedObjectsClientStub.create = jest
.fn()
.mockReturnValue(resolve ? Bluebird.resolve(resp) : Bluebird.reject(resp));
.mockReturnValue(resolve ? Promise.resolve(resp) : Promise.reject(resp));
}

/**
Expand Down Expand Up @@ -262,7 +261,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard', id: myId }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.id).toBe(myId);
return Bluebird.resolve({ id: myId });
return Promise.resolve({ id: myId });
});
savedObject.copyOnSave = false;

Expand Down Expand Up @@ -296,7 +295,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard', id }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.resolve({
return Promise.resolve({
type: 'dashboard',
id,
_version: 'foo',
Expand All @@ -315,7 +314,7 @@ describe('Saved Object', () => {
return createInitializedSavedObject({ type: 'dashboard' }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.reject('');
return Promise.reject('');
});

expect(savedObject.isSaving).toBe(false);
Expand Down Expand Up @@ -745,7 +744,7 @@ describe('Saved Object', () => {
},
});
savedObject.searchSource!.setField('index', indexPattern);
return Bluebird.resolve(indexPattern);
return Promise.resolve(indexPattern);
});
expect(!!savedObject.searchSource!.getField('index')).toBe(false);

Expand Down
21 changes: 10 additions & 11 deletions src/plugins/vis_types/timelion/server/handlers/chain_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import _ from 'lodash';
import Bluebird from 'bluebird';
import { i18n } from '@kbn/i18n';
import moment from 'moment';

Expand Down Expand Up @@ -42,7 +41,7 @@ export default function chainRunner(tlConfig) {

function resolveArgument(item) {
if (Array.isArray(item)) {
return Bluebird.all(_.map(item, resolveArgument));
return Promise.all(_.map(item, resolveArgument));
}

if (_.isObject(item)) {
Expand All @@ -51,7 +50,7 @@ export default function chainRunner(tlConfig) {
const itemFunctionDef = tlConfig.getFunction(item.function);
if (itemFunctionDef.cacheKey && queryCache[itemFunctionDef.cacheKey(item)]) {
stats.queryCount++;
return Bluebird.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)]));
return Promise.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)]));
}
return invoke(item.function, item.arguments);
}
Expand Down Expand Up @@ -94,7 +93,7 @@ export default function chainRunner(tlConfig) {

args = _.map(args, resolveArgument);

return Bluebird.all(args).then(function (args) {
return Promise.all(args).then(function (args) {
args.byName = indexArguments(functionDef, args);
return functionDef.fn(args, tlConfig);
});
Expand Down Expand Up @@ -128,7 +127,7 @@ export default function chainRunner(tlConfig) {
return args;
});
});
return Bluebird.all(seriesList).then(function (args) {
return Promise.all(seriesList).then(function (args) {
const list = _.chain(args).map('list').flatten().value();
const seriesList = _.merge.apply(this, _.flatten([{}, args]));
seriesList.list = list;
Expand Down Expand Up @@ -158,22 +157,22 @@ export default function chainRunner(tlConfig) {
})
.value();

return Bluebird.settle(promises).then(function (resolvedDatasources) {
return Promise.allSettled(promises).then(function (resolvedDatasources) {
stats.queryTime = new Date().getTime();

_.each(queries, function (query, i) {
const functionDef = tlConfig.getFunction(query.function);
const resolvedDatasource = resolvedDatasources[i];

if (resolvedDatasource.isRejected()) {
if (resolvedDatasource.reason().isBoom) {
throw resolvedDatasource.reason();
if (resolvedDatasource.status === 'rejected') {
if (resolvedDatasource.reason.isBoom) {
throw resolvedDatasource.reason;
} else {
throwWithCell(query.cell, resolvedDatasource.reason());
throwWithCell(query.cell, resolvedDatasource.reason);
}
}

queryCache[functionDef.cacheKey(query)] = resolvedDatasource.value();
queryCache[functionDef.cacheKey(query)] = resolvedDatasource.value;
});

stats.cacheCount = _.keys(queryCache).length;
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/vis_types/timelion/server/lib/alter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import Bluebird from 'bluebird';
import _ from 'lodash';

/* @param {Array} args
Expand All @@ -18,7 +17,7 @@ import _ from 'lodash';

export default function alter(args, fn) {
// In theory none of the args should ever be promises. This is probably a waste.
return Bluebird.all(args)
return Promise.all(args)
.then(function (args) {
const seriesList = args.shift();

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/vis_types/timelion/server/routes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { IRouter, Logger, CoreSetup } from 'kibana/server';
import { schema } from '@kbn/config-schema';
import Bluebird from 'bluebird';
import _ from 'lodash';
// @ts-ignore
import chainRunnerFn from '../handlers/chain_runner.js';
Expand Down Expand Up @@ -96,7 +95,7 @@ export function runRoute(
});
try {
const chainRunner = chainRunnerFn(tlConfig);
const sheet = await Bluebird.all(chainRunner.processRequest(request.body));
const sheet = await Promise.all(await chainRunner.processRequest(request.body));
watson marked this conversation as resolved.
Show resolved Hide resolved
return response.ok({
body: {
sheet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { i18n } from '@kbn/i18n';
import _ from 'lodash';
import fetch from 'node-fetch';
import moment from 'moment';
fetch.Promise = require('bluebird');

import Datasource from '../lib/classes/datasource';

Expand Down
Loading