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 from deps #95191

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
"apollo-server-hapi": "^1.3.6",
"archiver": "^5.2.0",
"axios": "^0.21.1",
"bluebird": "3.5.5",
"brace": "0.11.1",
"chalk": "^4.1.0",
"check-disk-space": "^2.1.0",
Expand Down Expand Up @@ -408,7 +407,6 @@
"@types/archiver": "^5.1.0",
"@types/babel__core": "^7.1.12",
"@types/base64-js": "^1.2.5",
"@types/bluebird": "^3.1.1",
"@types/chance": "^1.0.0",
"@types/cheerio": "^0.22.10",
"@types/chroma-js": "^1.4.2",
Expand Down
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('.'));
}
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';

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 timer(10).toPromise();
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 timer(10).toPromise();
log.info('testHookFailureAfterDelay %s %s', err.message, test.fullTitle());
});
},
Expand Down
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
93 changes: 46 additions & 47 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 @@ -57,25 +56,26 @@ 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().mockResolvedValue(mockDocResponse);
savedObjectsClientStub.update = jest.fn().mockResolvedValue(mockDocResponse);

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

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

function stubSavedObjectsClientCreate(
resp: SimpleSavedObject<SavedObjectAttributes> | string,
resolve = true
) {
savedObjectsClientStub.create = jest
.fn()
.mockReturnValue(resolve ? Bluebird.resolve(resp) : Bluebird.reject(resp));
savedObjectsClientStub.create = jest.fn().mockImplementation(async () => {
if (resolve) {
return resp;
}
throw resp;
});
}

/**
Expand Down Expand Up @@ -257,21 +257,20 @@ describe('Saved Object', () => {
);
});

it('as false does not create a copy', () => {
it('as false does not create a copy', async () => {
const myId = 'myId';
stubESResponse(getMockedDocResponse(myId));
const savedObject = await createInitializedSavedObject({ type: 'dashboard', id: myId });

return createInitializedSavedObject({ type: 'dashboard', id: myId }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.id).toBe(myId);
return Bluebird.resolve({ id: myId });
});
savedObject.copyOnSave = false;

return savedObject.save(saveOptionsMock).then((id) => {
expect(id).toBe(myId);
});
savedObjectsClientStub.create = jest.fn().mockImplementation(async () => {
expect(savedObject.id).toBe(myId);
return { id: myId };
});

savedObject.copyOnSave = false;
const id = await savedObject.save(saveOptionsMock);
expect(id).toBe(myId);
expect(savedObjectsClientStub.create).toBeCalled();
});
});

Expand All @@ -291,40 +290,40 @@ describe('Saved Object', () => {
});

describe('updates isSaving variable', () => {
it('on success', () => {
it('on success', async () => {
const id = 'id';
stubESResponse(getMockedDocResponse(id));

return createInitializedSavedObject({ type: 'dashboard', id }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.resolve({
type: 'dashboard',
id,
_version: 'foo',
});
});
const savedObject = await createInitializedSavedObject({ type: 'dashboard', id });

expect(savedObject.isSaving).toBe(false);
return savedObject.save(saveOptionsMock).then(() => {
expect(savedObject.isSaving).toBe(false);
});
savedObjectsClientStub.create = jest.fn().mockImplementation(async () => {
expect(savedObject.isSaving).toBe(true);
return {
type: 'dashboard',
id,
_version: 'foo',
};
});

expect(savedObject.isSaving).toBe(false);
await savedObject.save(saveOptionsMock);
expect(savedObjectsClientStub.create).toBeCalled();
expect(savedObject.isSaving).toBe(false);
});

it('on failure', () => {
it('on failure', async () => {
stubESResponse(getMockedDocResponse('id'));
return createInitializedSavedObject({ type: 'dashboard' }).then((savedObject) => {
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
return Bluebird.reject('');
});
const savedObject = await createInitializedSavedObject({ type: 'dashboard' });

expect(savedObject.isSaving).toBe(false);
return savedObject.save(saveOptionsMock).catch(() => {
expect(savedObject.isSaving).toBe(false);
});
savedObjectsClientStub.create = jest.fn().mockImplementation(() => {
expect(savedObject.isSaving).toBe(true);
throw new Error('some error');
});

expect(savedObject.isSaving).toBe(false);
await expect(() => savedObject.save(saveOptionsMock)).rejects.toThrowError('some error');
expect(savedObjectsClientStub.create).toBeCalled();
expect(savedObject.isSaving).toBe(false);
});
});

Expand Down Expand Up @@ -745,7 +744,7 @@ describe('Saved Object', () => {
);

const savedObject = new SavedObjectClass(config);
savedObject.hydrateIndexPattern = jest.fn().mockImplementation(() => {
savedObject.hydrateIndexPattern = jest.fn().mockImplementation(async () => {
const indexPattern = getStubIndexPattern(
indexPatternId,
getConfig,
Expand All @@ -755,7 +754,7 @@ describe('Saved Object', () => {
);
indexPattern.title = indexPattern.id!;
savedObject.searchSource!.setField('index', indexPattern);
return Bluebird.resolve(indexPattern);
return indexPattern;
});
expect(!!savedObject.searchSource!.getField('index')).toBe(false);

Expand Down
Loading