Skip to content

Commit 10e1d90

Browse files
committed
transform-async-to-promises: get rid of bluebird
1 parent eab6ffe commit 10e1d90

10 files changed

Lines changed: 38 additions & 55 deletions

File tree

‎.babelrc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"transform-class-properties",
1515
"transform-object-rest-spread",
16-
"transform-async-to-bluebird",
16+
"transform-async-to-promises",
1717
"transform-runtime",
1818
"add-module-exports",
1919
"syntax-dynamic-import"

‎package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"dependencies": {
6767
"babel-polyfill": "^6.26.0",
6868
"babel-runtime": "^6.26.0",
69-
"bluebird": "^3.5.2",
7069
"browser-request": "^0.3.3",
7170
"draft-js": "^0.11.0-alpha",
7271
"extract-text-webpack-plugin": "^4.0.0-beta.0",
@@ -93,7 +92,7 @@
9392
"babel-loader": "^7.1.5",
9493
"babel-plugin-add-module-exports": "^0.2.1",
9594
"babel-plugin-syntax-dynamic-import": "^6.18.0",
96-
"babel-plugin-transform-async-to-bluebird": "^1.1.1",
95+
"babel-plugin-transform-async-to-promises": "^0.8.15",
9796
"babel-plugin-transform-builtin-extend": "^1.1.2",
9897
"babel-plugin-transform-class-properties": "^6.24.1",
9998
"babel-plugin-transform-object-rest-spread": "^6.26.0",

‎src/vector/getconfig.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import Promise from 'bluebird';
1817
import request from 'browser-request';
1918

2019
// Load the config file. First try to load up a domain-specific config of the

‎src/vector/index.js‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import sdk from 'matrix-react-sdk';
4040
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
4141
sdk.loadSkin(require('../component-index'));
4242
import VectorConferenceHandler from 'matrix-react-sdk/lib/VectorConferenceHandler';
43-
import Promise from 'bluebird';
4443
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
4544
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler';
4645
import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils';
@@ -65,10 +64,6 @@ import CallHandler from 'matrix-react-sdk/lib/CallHandler';
6564

6665
let lastLocationHashSet = null;
6766

68-
// Disable warnings for now: we use deprecated bluebird functions
69-
// and need to migrate, but they spam the console with warnings.
70-
Promise.config({warnings: false});
71-
7267
function checkBrowserFeatures(featureList) {
7368
if (!window.Modernizr) {
7469
console.error("Cannot check features - Modernizr global is missing.");

‎src/vector/platform/ElectronPlatform.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ limitations under the License.
2222
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
2323
import dis from 'matrix-react-sdk/lib/dispatcher';
2424
import { _t } from 'matrix-react-sdk/lib/languageHandler';
25-
import Promise from 'bluebird';
2625
import rageshake from 'matrix-react-sdk/lib/rageshake/rageshake';
2726

2827
const ipcRenderer = window.ipcRenderer;

‎src/vector/platform/WebPlatform.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
2121
import request from 'browser-request';
2222
import dis from 'matrix-react-sdk/lib/dispatcher.js';
2323
import { _t } from 'matrix-react-sdk/lib/languageHandler';
24-
import Promise from 'bluebird';
2524

2625
import url from 'url';
2726
import UAParser from 'ua-parser-js';

‎test/app-tests/joining.js‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ require('skin-sdk');
2424
const jssdk = require('matrix-js-sdk');
2525

2626
const sdk = require('matrix-react-sdk');
27-
const peg = require('matrix-react-sdk/lib/MatrixClientPeg');
28-
const dis = require('matrix-react-sdk/lib/dispatcher');
29-
const PageTypes = require('matrix-react-sdk/lib/PageTypes');
3027
const MatrixChat = sdk.getComponent('structures.MatrixChat');
3128
const RoomDirectory = sdk.getComponent('structures.RoomDirectory');
3229
const RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar');
@@ -36,9 +33,9 @@ const React = require('react');
3633
const ReactDOM = require('react-dom');
3734
const ReactTestUtils = require('react-dom/test-utils');
3835
const expect = require('expect');
39-
import Promise from 'bluebird';
4036
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
4137
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
38+
import {sleep} from "../test-utils";
4239

4340
const test_utils = require('../test-utils');
4441
const MockHttpBackend = require('matrix-mock-request');
@@ -173,7 +170,7 @@ describe('joining a room', function() {
173170
matrixChat, RoomView);
174171

175172
// the preview bar may take a tick to be displayed
176-
return Promise.delay(1);
173+
return sleep(1);
177174
}).then(() => {
178175
const previewBar = ReactTestUtils.findRenderedComponentWithType(
179176
roomView, RoomPreviewBar);
@@ -187,14 +184,14 @@ describe('joining a room', function() {
187184
.respond(200, {room_id: ROOM_ID});
188185
}).then(() => {
189186
// wait for the join request to be made
190-
return Promise.delay(1);
187+
return sleep(1);
191188
}).then(() => {
192189
// and again, because the state update has to go to the store and
193190
// then one dispatch within the store, then to the view
194191
// XXX: This is *super flaky*: a better way would be to declare
195192
// that we expect a certain state transition to happen, then wait
196193
// for that transition to occur.
197-
return Promise.delay(1);
194+
return sleep(1);
198195
}).then(() => {
199196
// the roomview should now be loading
200197
expect(roomView.state.room).toBe(null);
@@ -209,7 +206,7 @@ describe('joining a room', function() {
209206
}).then(() => {
210207
httpBackend.verifyNoOutstandingExpectation();
211208

212-
return Promise.delay(1);
209+
return sleep(1);
213210
}).then(() => {
214211
// NB. we don't expect the 'joining' flag to reset at any point:
215212
// it will stay set and we observe whether we have Room object for

‎test/app-tests/loading.js‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import React from 'react';
2525
import ReactDOM from 'react-dom';
2626
import ReactTestUtils from 'react-dom/test-utils';
2727
import expect from 'expect';
28-
import Promise from 'bluebird';
2928
import MatrixReactTestUtils from 'matrix-react-test-utils';
3029

3130
import jssdk from 'matrix-js-sdk';
@@ -41,6 +40,7 @@ import MockHttpBackend from 'matrix-mock-request';
4140
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
4241
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
4342
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
43+
import {sleep} from "../test-utils";
4444

4545
const DEFAULT_HS_URL='http://my_server';
4646
const DEFAULT_IS_URL='http://my_is';
@@ -216,7 +216,7 @@ describe('loading:', function() {
216216
it('gives a welcome page by default', function(done) {
217217
loadApp();
218218

219-
Promise.delay(1).then(() => {
219+
sleep(1).then(() => {
220220
// at this point, we're trying to do a guest registration;
221221
// we expect a spinner
222222
assertAtLoadingSpinner(matrixChat);
@@ -231,7 +231,7 @@ describe('loading:', function() {
231231
return awaitWelcomeComponent(matrixChat);
232232
}).then(() => {
233233
expect(windowLocation.hash).toEqual("#/welcome");
234-
}).done(done, done);
234+
}).then(done, done);
235235
});
236236

237237
it('should follow the original link after successful login', function(done) {
@@ -243,7 +243,7 @@ describe('loading:', function() {
243243
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
244244
httpBackend.when("GET", "/api/v1").respond(200, {});
245245

246-
Promise.delay(1).then(() => {
246+
sleep(1).then(() => {
247247
// at this point, we're trying to do a guest registration;
248248
// we expect a spinner
249249
assertAtLoadingSpinner(matrixChat);
@@ -255,7 +255,7 @@ describe('loading:', function() {
255255
return httpBackend.flush();
256256
}).then(() => {
257257
// Wait for another trip around the event loop for the UI to update
258-
return Promise.delay(10);
258+
return sleep(10);
259259
}).then(() => {
260260
return moveFromWelcomeToLogin(matrixChat);
261261
}).then(() => {
@@ -272,7 +272,7 @@ describe('loading:', function() {
272272
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
273273
expect(localStorage.getItem('mx_hs_url')).toEqual(DEFAULT_HS_URL);
274274
expect(localStorage.getItem('mx_is_url')).toEqual(DEFAULT_IS_URL);
275-
}).done(done, done);
275+
}).then(done, done);
276276
});
277277

278278
it('should not register as a guest when using a #/login link', function() {
@@ -365,7 +365,7 @@ describe('loading:', function() {
365365
ReactTestUtils.findRenderedComponentWithType(
366366
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
367367
expect(windowLocation.hash).toEqual("#/home");
368-
}).done(done, done);
368+
}).then(done, done);
369369
});
370370

371371
it('shows a room view if we followed a room link', function(done) {
@@ -385,7 +385,7 @@ describe('loading:', function() {
385385
}).then(() => {
386386
httpBackend.verifyNoOutstandingExpectation();
387387
expect(windowLocation.hash).toEqual("#/room/!room:id");
388-
}).done(done, done);
388+
}).then(done, done);
389389
});
390390

391391
describe('/#/login link:', function() {
@@ -445,7 +445,7 @@ describe('loading:', function() {
445445
it('shows a welcome page by default', function(done) {
446446
loadApp();
447447

448-
Promise.delay(1).then(() => {
448+
sleep(1).then(() => {
449449
// at this point, we're trying to do a guest registration;
450450
// we expect a spinner
451451
assertAtLoadingSpinner(matrixChat);
@@ -469,13 +469,13 @@ describe('loading:', function() {
469469
ReactTestUtils.findRenderedComponentWithType(
470470
matrixChat, sdk.getComponent('auth.Welcome'));
471471
expect(windowLocation.hash).toEqual("#/welcome");
472-
}).done(done, done);
472+
}).then(done, done);
473473
});
474474

475475
it('uses the default homeserver to register with', function(done) {
476476
loadApp();
477477

478-
Promise.delay(1).then(() => {
478+
sleep(1).then(() => {
479479
// at this point, we're trying to do a guest registration;
480480
// we expect a spinner
481481
assertAtLoadingSpinner(matrixChat);
@@ -503,14 +503,14 @@ describe('loading:', function() {
503503
expect(windowLocation.hash).toEqual("#/welcome");
504504
expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL);
505505
expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL);
506-
}).done(done, done);
506+
}).then(done, done);
507507
});
508508

509509
it('shows a room view if we followed a room link', function(done) {
510510
loadApp({
511511
uriFragment: "#/room/!room:id",
512512
});
513-
Promise.delay(1).then(() => {
513+
sleep(1).then(() => {
514514
// at this point, we're trying to do a guest registration;
515515
// we expect a spinner
516516
assertAtLoadingSpinner(matrixChat);
@@ -533,7 +533,7 @@ describe('loading:', function() {
533533
}).then(() => {
534534
httpBackend.verifyNoOutstandingExpectation();
535535
expect(windowLocation.hash).toEqual("#/room/!room:id");
536-
}).done(done, done);
536+
}).then(done, done);
537537
});
538538

539539
describe('Login as user', function() {
@@ -600,7 +600,7 @@ describe('loading:', function() {
600600
601601
ReactTestUtils.Simulate.click(returnToApp);
602602
603-
return Promise.delay(1).then(() => {
603+
return sleep(1).then(() => {
604604
// we should be straight back into the home page
605605
ReactTestUtils.findRenderedComponentWithType(
606606
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
@@ -616,7 +616,7 @@ describe('loading:', function() {
616616
queryString: "?loginToken=secretToken&homeserver=https%3A%2F%2Fhomeserver&identityServer=https%3A%2F%2Fidserver",
617617
});
618618

619-
Promise.delay(1).then(() => {
619+
sleep(1).then(() => {
620620
// we expect a spinner while we're logging in
621621
assertAtLoadingSpinner(matrixChat);
622622

@@ -645,7 +645,7 @@ describe('loading:', function() {
645645
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
646646
expect(localStorage.getItem('mx_hs_url')).toEqual('https://homeserver');
647647
expect(localStorage.getItem('mx_is_url')).toEqual('https://idserver');
648-
}).done(done, done);
648+
}).then(done, done);
649649
});
650650
});
651651

@@ -664,7 +664,7 @@ describe('loading:', function() {
664664

665665
// Give the component some time to finish processing the login flows before
666666
// continuing.
667-
await Promise.delay(100);
667+
await sleep(100);
668668

669669
httpBackend.when('POST', '/login').check(function(req) {
670670
expect(req.data.type).toEqual('m.login.password');
@@ -680,7 +680,7 @@ describe('loading:', function() {
680680

681681
return httpBackend.flush().then(() => {
682682
// Wait for another trip around the event loop for the UI to update
683-
return Promise.delay(1);
683+
return sleep(1);
684684
}).then(() => {
685685
// we expect a spinner
686686
ReactTestUtils.findRenderedComponentWithType(
@@ -738,7 +738,7 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {
738738
throw new Error("MatrixChat still not ready after " +
739739
retryCount + " tries");
740740
}
741-
return Promise.delay(0).then(() => {
741+
return sleep(0).then(() => {
742742
return awaitRoomView(matrixChat, retryLimit, retryCount + 1);
743743
});
744744
}

‎test/test-utils.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use strict";
22

3-
import Promise from 'bluebird';
4-
53
/**
64
* Perform common actions before each test case, e.g. printing the test case
75
* name to stdout.
@@ -58,3 +56,5 @@ export function deleteIndexedDB(dbName) {
5856
throw e;
5957
});
6058
}
59+
60+
export const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });

‎yarn.lock‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ babel-helper-explode-class@^6.24.1:
892892
babel-traverse "^6.24.1"
893893
babel-types "^6.24.1"
894894

895-
babel-helper-function-name@^6.24.1, babel-helper-function-name@^6.8.0:
895+
babel-helper-function-name@^6.24.1:
896896
version "6.24.1"
897897
resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9"
898898
integrity sha1-00dbjAPtmCQqJbSDUasYOZ01gKk=
@@ -1054,16 +1054,6 @@ babel-plugin-transform-async-generator-functions@^6.24.1:
10541054
babel-plugin-syntax-async-generators "^6.5.0"
10551055
babel-runtime "^6.22.0"
10561056

1057-
babel-plugin-transform-async-to-bluebird@^1.1.1:
1058-
version "1.1.1"
1059-
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-bluebird/-/babel-plugin-transform-async-to-bluebird-1.1.1.tgz#46ea3e7c5af629782ac9f1ed1b7cd38f8425afd4"
1060-
integrity sha1-Ruo+fFr2KXgqyfHtG3zTj4Qlr9Q=
1061-
dependencies:
1062-
babel-helper-function-name "^6.8.0"
1063-
babel-plugin-syntax-async-functions "^6.8.0"
1064-
babel-template "^6.9.0"
1065-
babel-traverse "^6.10.4"
1066-
10671057
babel-plugin-transform-async-to-generator@^6.24.1:
10681058
version "6.24.1"
10691059
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761"
@@ -1073,6 +1063,11 @@ babel-plugin-transform-async-to-generator@^6.24.1:
10731063
babel-plugin-syntax-async-functions "^6.8.0"
10741064
babel-runtime "^6.22.0"
10751065

1066+
babel-plugin-transform-async-to-promises@^0.8.15:
1067+
version "0.8.15"
1068+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-promises/-/babel-plugin-transform-async-to-promises-0.8.15.tgz#13b6d8ef13676b4e3c576d3600b85344bb1ba346"
1069+
integrity sha512-fDXP68ZqcinZO2WCiimCL9zhGjGXOnn3D33zvbh+yheZ/qOrNVVDDIBtAaM3Faz8TRvQzHiRKsu3hfrBAhEncQ==
1070+
10761071
babel-plugin-transform-builtin-extend@^1.1.2:
10771072
version "1.1.2"
10781073
resolved "https://registry.yarnpkg.com/babel-plugin-transform-builtin-extend/-/babel-plugin-transform-builtin-extend-1.1.2.tgz#5e96fecf58b8fa1ed74efcad88475b2af3c9116e"
@@ -1486,7 +1481,7 @@ babel-runtime@^6.0.0, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime
14861481
core-js "^2.4.0"
14871482
regenerator-runtime "^0.11.0"
14881483

1489-
babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0, babel-template@^6.9.0:
1484+
babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0:
14901485
version "6.26.0"
14911486
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02"
14921487
integrity sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=
@@ -1497,7 +1492,7 @@ babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0, babel-tem
14971492
babylon "^6.18.0"
14981493
lodash "^4.17.4"
14991494

1500-
babel-traverse@^6.10.4, babel-traverse@^6.24.1, babel-traverse@^6.26.0:
1495+
babel-traverse@^6.24.1, babel-traverse@^6.26.0:
15011496
version "6.26.0"
15021497
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
15031498
integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=
@@ -1630,7 +1625,7 @@ bluebird-lst@^1.0.9:
16301625
dependencies:
16311626
bluebird "^3.5.5"
16321627

1633-
bluebird@3.5.5, bluebird@^3.3.0, bluebird@^3.5.0, bluebird@^3.5.2, bluebird@^3.5.5:
1628+
bluebird@3.5.5, bluebird@^3.3.0, bluebird@^3.5.0, bluebird@^3.5.5:
16341629
version "3.5.5"
16351630
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
16361631
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==

0 commit comments

Comments
 (0)