Skip to content

Commit

Permalink
remove remaining bluebird imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Mar 23, 2021
1 parent c37d35f commit 6323b41
Show file tree
Hide file tree
Showing 32 changed files with 348 additions and 323 deletions.
10 changes: 5 additions & 5 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, dirname, relative } from 'path';
import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs';
import { createReadStream, createWriteStream } from 'fs';
import { stat, rename } from 'fs/promises';
import { Readable, Writable } from 'stream';
import { fromNode } from 'bluebird';
import { ToolingLog } from '@kbn/dev-utils';
import { createPromiseFromStreams } from '@kbn/utils';
import {
Expand All @@ -21,8 +21,8 @@ import {
} from '../lib';

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

export async function rebuildAllAction({
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function rebuildAllAction({
createWriteStream(tempFile),
] as [Readable, ...Writable[]]);

await fromNode((cb) => rename(tempFile, childPath, cb));
await rename(tempFile, childPath);
log.info(`${archiveName} Rebuilt ${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: string[] = await readdir(path);
return allNames.filter((name) => !name.startsWith('.'));
}
6 changes: 3 additions & 3 deletions packages/kbn-test/src/functional_tests/lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import util from 'util';
import { format as formatUrl } from 'url';

import request from 'request';
import { delay } from 'bluebird';
import { timer } from 'rxjs';

export const DEFAULT_SUPERUSER_PASS = 'changeme';

Expand Down Expand Up @@ -56,7 +56,7 @@ async function updateCredentials({
}

if (retries > 0) {
await delay(2500);
await timer(2500).toPromise();
return await updateCredentials({
port,
auth,
Expand Down Expand Up @@ -134,7 +134,7 @@ async function insertUser({
}

if (retries > 0) {
await delay(2500);
await timer(2500).toPromise();
return await insertUser({
port,
auth,
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
5 changes: 3 additions & 2 deletions packages/kbn-test/src/mocha/junit_report_generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

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

import { fromNode as fcb } from 'bluebird';
import { parseString } from 'xml2js';
import del from 'del';
import Mocha from 'mocha';
import { getUniqueJunitReportPath } from '../report_path';

import { setupJUnitReportGeneration } from './junit_report_generation';

const parseStringAsync = promisify(parseString);
const PROJECT_DIR = resolve(__dirname, '__fixtures__/project');
const DURATION_REGEX = /^\d+\.\d{3}$/;
const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
Expand All @@ -39,7 +40,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(readFileSync(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 { timer } from 'rxjs';

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 timer(n).toPromise();
return n * i;
}),
createConcatStream([]),
Expand Down
10 changes: 5 additions & 5 deletions src/dev/notice/bundled_notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
*/

import { resolve } from 'path';
import { readFile } from 'fs';

import { fromNode as fcb } from 'bluebird';
import { readFile } from 'fs/promises';
import { promisify } from 'util';
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'),
}))
);
}
8 changes: 4 additions & 4 deletions src/dev/precommit_hook/get_files_for_commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
*/

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

import { REPO_ROOT } from '@kbn/utils';
import { File } from '../file';

import { promisify } from 'util';
/**
* Get the files that are staged for commit (excluding deleted files)
* as `File` objects that are aware of their commit status.
Expand All @@ -21,8 +19,10 @@ import { File } from '../file';
*/
export async function getFilesForCommit(gitRef) {
const simpleGit = new SimpleGit(REPO_ROOT);
const diffAsync = promisify(simpleGit.diff).bind(simpleGit);

const gitRefForDiff = gitRef ? gitRef : '--cached';
const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb));
const output = await diffAsync(['--name-status', gitRefForDiff]);

return (
output
Expand Down
27 changes: 13 additions & 14 deletions src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Side Public License, v 1.
*/

import { once } from 'events';
import _ from 'lodash';
import d3 from 'd3';
import 'jest-canvas-mock';

import { fromNode, delay } from 'bluebird';
import { TagCloud } from './tag_cloud';
import { setHTMLElementOffset, setSVGElementGetBBox } from '@kbn/test/jest';

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('tag cloud tests', () => {
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(currentTest.data);
tagCloud.setOptions(currentTest.options);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('tag cloud tests', () => {
//this timeout modifies the settings before the cloud is rendered.
//the cloud needs to use the correct options
setTimeout(() => tagCloud.setOptions(logScaleTest.options), timeout);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('tag cloud tests', () => {
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
tagCloud.setOptions(logScaleTest.options);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand All @@ -216,7 +216,7 @@ describe('tag cloud tests', () => {
tagCloud.setOptions(baseTest.options);
tagCloud.setData(trimDataTest.data);

await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand Down Expand Up @@ -290,8 +290,7 @@ describe('tag cloud tests', () => {
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(logScaleTest.data);
tagCloud.setOptions(logScaleTest.options);

await delay(1000); //let layout run
await once(tagCloud, 'renderComplete'); //let layout run

SVGElementGetBBoxSpyInstance.mockRestore();
SVGElementGetBBoxSpyInstance = setSVGElementGetBBox(600, 600);
Expand All @@ -302,7 +301,7 @@ describe('tag cloud tests', () => {
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
}, 200);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand All @@ -327,7 +326,7 @@ describe('tag cloud tests', () => {
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand All @@ -349,12 +348,12 @@ describe('tag cloud tests', () => {
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');

//make bigger
tagCloud._size = [600, 600];
tagCloud.resize();
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand All @@ -372,12 +371,12 @@ describe('tag cloud tests', () => {
tagCloud = new TagCloud(domNode, colorScale);
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');

//make smaller
tagCloud._size = [];
tagCloud.resize();
await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');
});

afterEach(teardownDOM);
Expand All @@ -395,7 +394,7 @@ describe('tag cloud tests', () => {
tagCloud.setData(baseTest.data);
tagCloud.setOptions(baseTest.options);

await fromNode((cb) => tagCloud.once('renderComplete', cb));
await once(tagCloud, 'renderComplete');

expect(domNode.innerHTML).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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';

export default new Datasource('quandl', {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/common_page.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 { timer } from 'rxjs';
import expect from '@kbn/expect';
// @ts-ignore
import fetch from 'node-fetch';
Expand Down Expand Up @@ -198,7 +198,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo

async sleep(sleepMilliseconds: number) {
log.debug(`... sleep(${sleepMilliseconds}) start`);
await delay(sleepMilliseconds);
await timer(sleepMilliseconds).toPromise();
log.debug(`... sleep(${sleepMilliseconds}) end`);
}

Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/login_page.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 { timer } from 'rxjs';
import { FtrProviderContext } from '../ftr_provider_context';

export function LoginPageProvider({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -62,7 +62,7 @@ export function LoginPageProvider({ getService }: FtrProviderContext) {

async sleep(sleepMilliseconds: number) {
log.debug(`... sleep(${sleepMilliseconds}) start`);
await delay(sleepMilliseconds);
await timer(sleepMilliseconds).toPromise();
log.debug(`... sleep(${sleepMilliseconds}) end`);
}
}
Expand Down
Loading

0 comments on commit 6323b41

Please sign in to comment.