From 10e1d9093e49e98a9b62487f8a8b69aaa156ac29 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 4 Nov 2019 12:46:28 +0000 Subject: [PATCH] transform-async-to-promises: get rid of bluebird --- .babelrc | 2 +- package.json | 3 +- src/vector/getconfig.js | 1 - src/vector/index.js | 5 ---- src/vector/platform/ElectronPlatform.js | 1 - src/vector/platform/WebPlatform.js | 1 - test/app-tests/joining.js | 13 ++++---- test/app-tests/loading.js | 40 ++++++++++++------------- test/test-utils.js | 4 +-- yarn.lock | 23 ++++++-------- 10 files changed, 38 insertions(+), 55 deletions(-) diff --git a/.babelrc b/.babelrc index 3fb847ad..790e92a3 100644 --- a/.babelrc +++ b/.babelrc @@ -13,7 +13,7 @@ ], "transform-class-properties", "transform-object-rest-spread", - "transform-async-to-bluebird", + "transform-async-to-promises", "transform-runtime", "add-module-exports", "syntax-dynamic-import" diff --git a/package.json b/package.json index 84f18a80..538e187b 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "dependencies": { "babel-polyfill": "^6.26.0", "babel-runtime": "^6.26.0", - "bluebird": "^3.5.2", "browser-request": "^0.3.3", "draft-js": "^0.11.0-alpha", "extract-text-webpack-plugin": "^4.0.0-beta.0", @@ -93,7 +92,7 @@ "babel-loader": "^7.1.5", "babel-plugin-add-module-exports": "^0.2.1", "babel-plugin-syntax-dynamic-import": "^6.18.0", - "babel-plugin-transform-async-to-bluebird": "^1.1.1", + "babel-plugin-transform-async-to-promises": "^0.8.15", "babel-plugin-transform-builtin-extend": "^1.1.2", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.26.0", diff --git a/src/vector/getconfig.js b/src/vector/getconfig.js index 984b1051..6fb74d38 100644 --- a/src/vector/getconfig.js +++ b/src/vector/getconfig.js @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import Promise from 'bluebird'; import request from 'browser-request'; // Load the config file. First try to load up a domain-specific config of the diff --git a/src/vector/index.js b/src/vector/index.js index afdad64f..82b6f394 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -40,7 +40,6 @@ import sdk from 'matrix-react-sdk'; import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg'; sdk.loadSkin(require('../component-index')); import VectorConferenceHandler from 'matrix-react-sdk/lib/VectorConferenceHandler'; -import Promise from 'bluebird'; import * as languageHandler from 'matrix-react-sdk/lib/languageHandler'; import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler'; import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils'; @@ -65,10 +64,6 @@ import CallHandler from 'matrix-react-sdk/lib/CallHandler'; let lastLocationHashSet = null; -// Disable warnings for now: we use deprecated bluebird functions -// and need to migrate, but they spam the console with warnings. -Promise.config({warnings: false}); - function checkBrowserFeatures(featureList) { if (!window.Modernizr) { console.error("Cannot check features - Modernizr global is missing."); diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index dd4df4e6..13e9f9fc 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -22,7 +22,6 @@ limitations under the License. import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform'; import dis from 'matrix-react-sdk/lib/dispatcher'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; -import Promise from 'bluebird'; import rageshake from 'matrix-react-sdk/lib/rageshake/rageshake'; const ipcRenderer = window.ipcRenderer; diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index 984aa8da..c9ccef5b 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -21,7 +21,6 @@ import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform'; import request from 'browser-request'; import dis from 'matrix-react-sdk/lib/dispatcher.js'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; -import Promise from 'bluebird'; import url from 'url'; import UAParser from 'ua-parser-js'; diff --git a/test/app-tests/joining.js b/test/app-tests/joining.js index 9c546399..95a917e3 100644 --- a/test/app-tests/joining.js +++ b/test/app-tests/joining.js @@ -24,9 +24,6 @@ require('skin-sdk'); const jssdk = require('matrix-js-sdk'); const sdk = require('matrix-react-sdk'); -const peg = require('matrix-react-sdk/lib/MatrixClientPeg'); -const dis = require('matrix-react-sdk/lib/dispatcher'); -const PageTypes = require('matrix-react-sdk/lib/PageTypes'); const MatrixChat = sdk.getComponent('structures.MatrixChat'); const RoomDirectory = sdk.getComponent('structures.RoomDirectory'); const RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar'); @@ -36,9 +33,9 @@ const React = require('react'); const ReactDOM = require('react-dom'); const ReactTestUtils = require('react-dom/test-utils'); const expect = require('expect'); -import Promise from 'bluebird'; import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils"; import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils"; +import {sleep} from "../test-utils"; const test_utils = require('../test-utils'); const MockHttpBackend = require('matrix-mock-request'); @@ -173,7 +170,7 @@ describe('joining a room', function() { matrixChat, RoomView); // the preview bar may take a tick to be displayed - return Promise.delay(1); + return sleep(1); }).then(() => { const previewBar = ReactTestUtils.findRenderedComponentWithType( roomView, RoomPreviewBar); @@ -187,14 +184,14 @@ describe('joining a room', function() { .respond(200, {room_id: ROOM_ID}); }).then(() => { // wait for the join request to be made - return Promise.delay(1); + return sleep(1); }).then(() => { // and again, because the state update has to go to the store and // then one dispatch within the store, then to the view // XXX: This is *super flaky*: a better way would be to declare // that we expect a certain state transition to happen, then wait // for that transition to occur. - return Promise.delay(1); + return sleep(1); }).then(() => { // the roomview should now be loading expect(roomView.state.room).toBe(null); @@ -209,7 +206,7 @@ describe('joining a room', function() { }).then(() => { httpBackend.verifyNoOutstandingExpectation(); - return Promise.delay(1); + return sleep(1); }).then(() => { // NB. we don't expect the 'joining' flag to reset at any point: // it will stay set and we observe whether we have Room object for diff --git a/test/app-tests/loading.js b/test/app-tests/loading.js index 92549893..4d820e66 100644 --- a/test/app-tests/loading.js +++ b/test/app-tests/loading.js @@ -25,7 +25,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import ReactTestUtils from 'react-dom/test-utils'; import expect from 'expect'; -import Promise from 'bluebird'; import MatrixReactTestUtils from 'matrix-react-test-utils'; import jssdk from 'matrix-js-sdk'; @@ -41,6 +40,7 @@ import MockHttpBackend from 'matrix-mock-request'; import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils'; import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils"; import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils"; +import {sleep} from "../test-utils"; const DEFAULT_HS_URL='http://my_server'; const DEFAULT_IS_URL='http://my_is'; @@ -216,7 +216,7 @@ describe('loading:', function() { it('gives a welcome page by default', function(done) { loadApp(); - Promise.delay(1).then(() => { + sleep(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner assertAtLoadingSpinner(matrixChat); @@ -231,7 +231,7 @@ describe('loading:', function() { return awaitWelcomeComponent(matrixChat); }).then(() => { expect(windowLocation.hash).toEqual("#/welcome"); - }).done(done, done); + }).then(done, done); }); it('should follow the original link after successful login', function(done) { @@ -243,7 +243,7 @@ describe('loading:', function() { httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]}); httpBackend.when("GET", "/api/v1").respond(200, {}); - Promise.delay(1).then(() => { + sleep(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner assertAtLoadingSpinner(matrixChat); @@ -255,7 +255,7 @@ describe('loading:', function() { return httpBackend.flush(); }).then(() => { // Wait for another trip around the event loop for the UI to update - return Promise.delay(10); + return sleep(10); }).then(() => { return moveFromWelcomeToLogin(matrixChat); }).then(() => { @@ -272,7 +272,7 @@ describe('loading:', function() { expect(localStorage.getItem('mx_access_token')).toEqual('access_token'); expect(localStorage.getItem('mx_hs_url')).toEqual(DEFAULT_HS_URL); expect(localStorage.getItem('mx_is_url')).toEqual(DEFAULT_IS_URL); - }).done(done, done); + }).then(done, done); }); it('should not register as a guest when using a #/login link', function() { @@ -365,7 +365,7 @@ describe('loading:', function() { ReactTestUtils.findRenderedComponentWithType( matrixChat, sdk.getComponent('structures.EmbeddedPage')); expect(windowLocation.hash).toEqual("#/home"); - }).done(done, done); + }).then(done, done); }); it('shows a room view if we followed a room link', function(done) { @@ -385,7 +385,7 @@ describe('loading:', function() { }).then(() => { httpBackend.verifyNoOutstandingExpectation(); expect(windowLocation.hash).toEqual("#/room/!room:id"); - }).done(done, done); + }).then(done, done); }); describe('/#/login link:', function() { @@ -445,7 +445,7 @@ describe('loading:', function() { it('shows a welcome page by default', function(done) { loadApp(); - Promise.delay(1).then(() => { + sleep(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner assertAtLoadingSpinner(matrixChat); @@ -469,13 +469,13 @@ describe('loading:', function() { ReactTestUtils.findRenderedComponentWithType( matrixChat, sdk.getComponent('auth.Welcome')); expect(windowLocation.hash).toEqual("#/welcome"); - }).done(done, done); + }).then(done, done); }); it('uses the default homeserver to register with', function(done) { loadApp(); - Promise.delay(1).then(() => { + sleep(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner assertAtLoadingSpinner(matrixChat); @@ -503,14 +503,14 @@ describe('loading:', function() { expect(windowLocation.hash).toEqual("#/welcome"); expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL); expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL); - }).done(done, done); + }).then(done, done); }); it('shows a room view if we followed a room link', function(done) { loadApp({ uriFragment: "#/room/!room:id", }); - Promise.delay(1).then(() => { + sleep(1).then(() => { // at this point, we're trying to do a guest registration; // we expect a spinner assertAtLoadingSpinner(matrixChat); @@ -533,7 +533,7 @@ describe('loading:', function() { }).then(() => { httpBackend.verifyNoOutstandingExpectation(); expect(windowLocation.hash).toEqual("#/room/!room:id"); - }).done(done, done); + }).then(done, done); }); describe('Login as user', function() { @@ -600,7 +600,7 @@ describe('loading:', function() { ReactTestUtils.Simulate.click(returnToApp); - return Promise.delay(1).then(() => { + return sleep(1).then(() => { // we should be straight back into the home page ReactTestUtils.findRenderedComponentWithType( matrixChat, sdk.getComponent('structures.EmbeddedPage')); @@ -616,7 +616,7 @@ describe('loading:', function() { queryString: "?loginToken=secretToken&homeserver=https%3A%2F%2Fhomeserver&identityServer=https%3A%2F%2Fidserver", }); - Promise.delay(1).then(() => { + sleep(1).then(() => { // we expect a spinner while we're logging in assertAtLoadingSpinner(matrixChat); @@ -645,7 +645,7 @@ describe('loading:', function() { expect(localStorage.getItem('mx_access_token')).toEqual('access_token'); expect(localStorage.getItem('mx_hs_url')).toEqual('https://homeserver'); expect(localStorage.getItem('mx_is_url')).toEqual('https://idserver'); - }).done(done, done); + }).then(done, done); }); }); @@ -664,7 +664,7 @@ describe('loading:', function() { // Give the component some time to finish processing the login flows before // continuing. - await Promise.delay(100); + await sleep(100); httpBackend.when('POST', '/login').check(function(req) { expect(req.data.type).toEqual('m.login.password'); @@ -680,7 +680,7 @@ describe('loading:', function() { return httpBackend.flush().then(() => { // Wait for another trip around the event loop for the UI to update - return Promise.delay(1); + return sleep(1); }).then(() => { // we expect a spinner ReactTestUtils.findRenderedComponentWithType( @@ -738,7 +738,7 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) { throw new Error("MatrixChat still not ready after " + retryCount + " tries"); } - return Promise.delay(0).then(() => { + return sleep(0).then(() => { return awaitRoomView(matrixChat, retryLimit, retryCount + 1); }); } diff --git a/test/test-utils.js b/test/test-utils.js index 4e07be14..6e6738de 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -1,7 +1,5 @@ "use strict"; -import Promise from 'bluebird'; - /** * Perform common actions before each test case, e.g. printing the test case * name to stdout. @@ -58,3 +56,5 @@ export function deleteIndexedDB(dbName) { throw e; }); } + +export const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }); diff --git a/yarn.lock b/yarn.lock index 9b520a5b..94afdee6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -892,7 +892,7 @@ babel-helper-explode-class@^6.24.1: babel-traverse "^6.24.1" babel-types "^6.24.1" -babel-helper-function-name@^6.24.1, babel-helper-function-name@^6.8.0: +babel-helper-function-name@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" integrity sha1-00dbjAPtmCQqJbSDUasYOZ01gKk= @@ -1054,16 +1054,6 @@ babel-plugin-transform-async-generator-functions@^6.24.1: babel-plugin-syntax-async-generators "^6.5.0" babel-runtime "^6.22.0" -babel-plugin-transform-async-to-bluebird@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-bluebird/-/babel-plugin-transform-async-to-bluebird-1.1.1.tgz#46ea3e7c5af629782ac9f1ed1b7cd38f8425afd4" - integrity sha1-Ruo+fFr2KXgqyfHtG3zTj4Qlr9Q= - dependencies: - babel-helper-function-name "^6.8.0" - babel-plugin-syntax-async-functions "^6.8.0" - babel-template "^6.9.0" - babel-traverse "^6.10.4" - babel-plugin-transform-async-to-generator@^6.24.1: version "6.24.1" 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: babel-plugin-syntax-async-functions "^6.8.0" babel-runtime "^6.22.0" +babel-plugin-transform-async-to-promises@^0.8.15: + version "0.8.15" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-promises/-/babel-plugin-transform-async-to-promises-0.8.15.tgz#13b6d8ef13676b4e3c576d3600b85344bb1ba346" + integrity sha512-fDXP68ZqcinZO2WCiimCL9zhGjGXOnn3D33zvbh+yheZ/qOrNVVDDIBtAaM3Faz8TRvQzHiRKsu3hfrBAhEncQ== + babel-plugin-transform-builtin-extend@^1.1.2: version "1.1.2" 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 core-js "^2.4.0" regenerator-runtime "^0.11.0" -babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0, babel-template@^6.9.0: +babel-template@^6.24.1, babel-template@^6.26.0, babel-template@^6.3.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" 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 babylon "^6.18.0" lodash "^4.17.4" -babel-traverse@^6.10.4, babel-traverse@^6.24.1, babel-traverse@^6.26.0: +babel-traverse@^6.24.1, babel-traverse@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4= @@ -1630,7 +1625,7 @@ bluebird-lst@^1.0.9: dependencies: bluebird "^3.5.5" -bluebird@3.5.5, bluebird@^3.3.0, bluebird@^3.5.0, bluebird@^3.5.2, bluebird@^3.5.5: +bluebird@3.5.5, bluebird@^3.3.0, bluebird@^3.5.0, bluebird@^3.5.5: version "3.5.5" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==