You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/04/02 10:02:42 UTC

[cordova-serve] branch master updated: refactor: transform arrow & arrow-returns (#33)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-serve.git


The following commit(s) were added to refs/heads/master by this push:
     new d4ccbaf  refactor: transform arrow & arrow-returns (#33)
d4ccbaf is described below

commit d4ccbaf7542cece29c5a8738db048fb49268b893
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Apr 2 19:02:34 2020 +0900

    refactor: transform arrow & arrow-returns (#33)
    
    * refactor: transform arrow
    * refactor: transform arrow-return
    * chore: applied review suggestions
      * Remove unnecessary promise wrapping
    
    Co-Authored-By: Raphael von der Grün <ra...@gmail.com>
---
 spec/browser.spec.js | 14 +++++++-------
 spec/main.spec.js    |  6 +++---
 spec/server.spec.js  |  6 +++---
 src/browser.js       | 26 ++++++++++++--------------
 src/exec.js          |  6 +++---
 src/main.js          |  2 +-
 src/platform.js      |  2 +-
 src/server.js        |  8 ++++----
 8 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/spec/browser.spec.js b/spec/browser.spec.js
index 124f8ed..ba077a0 100644
--- a/spec/browser.spec.js
+++ b/spec/browser.spec.js
@@ -24,19 +24,19 @@ function expectPromise (obj) {
     expect(obj).toBe(Promise.resolve(obj));
 }
 
-describe('browser', function () {
+describe('browser', () => {
     let browser;
     beforeEach(() => {
         browser = rewire('../src/browser');
         browser.__set__('open', jasmine.createSpy('mockOpen'));
     });
 
-    it('exists and has expected properties', function () {
+    it('exists and has expected properties', () => {
         expect(browser).toBeDefined();
         expect(typeof browser).toBe('function');
     });
 
-    it('should return a promise', function () {
+    it('should return a promise', () => {
         const result = browser();
         expect(result).toBeDefined();
         expectPromise(result);
@@ -44,7 +44,7 @@ describe('browser', function () {
         return result;
     });
 
-    it('should call open() when target is `default`', function () {
+    it('should call open() when target is `default`', () => {
         const mockUrl = 'this is the freakin url';
 
         const result = browser({ target: 'default', url: mockUrl });
@@ -68,15 +68,15 @@ describe('browser', function () {
             expect(regItemPattern.exec(input)[2]).toBe(appPath);
         }
 
-        it('should recognize browser from registry with key "Default" on English Windows 10', function () {
+        it('should recognize browser from registry with key "Default" on English Windows 10', () => {
             expectPatternToExtractPathFrom(`${regPath} (Default)    REG_SZ    ${appPath}`);
         });
 
-        it('should recognize browser from registry with key "Standard" on non-English Windows 10', function () {
+        it('should recognize browser from registry with key "Standard" on non-English Windows 10', () => {
             expectPatternToExtractPathFrom(`${regPath} (Standard)    REG_SZ    ${appPath}`);
         });
 
-        it('should recognize browser with non-Latin registry key on Russian Windows 10', function () {
+        it('should recognize browser with non-Latin registry key on Russian Windows 10', () => {
             expectPatternToExtractPathFrom(`${regPath} (�� 㬮�砭��)    REG_SZ    ${appPath}`);
         });
     });
diff --git a/spec/main.spec.js b/spec/main.spec.js
index 502fe8a..ffbe217 100644
--- a/spec/main.spec.js
+++ b/spec/main.spec.js
@@ -17,14 +17,14 @@
 
 const main = require('..');
 
-describe('main', function () {
-    it('exists and has expected properties', function () {
+describe('main', () => {
+    it('exists and has expected properties', () => {
         expect(main).toBeDefined();
         expect(main.Router).toBeDefined();
         expect(main.static).toBeDefined();
     });
 
-    it('is creatable', function () {
+    it('is creatable', () => {
         const instance = main();
         expect(instance.servePlatform).toBeDefined();
         expect(typeof instance.servePlatform).toBe('function');
diff --git a/spec/server.spec.js b/spec/server.spec.js
index 1ff8633..23cf4f3 100644
--- a/spec/server.spec.js
+++ b/spec/server.spec.js
@@ -24,13 +24,13 @@ function expectPromise (obj) {
     expect(obj).toBe(Promise.resolve(obj));
 }
 
-describe('server', function () {
-    it('exists and has expected properties', function () {
+describe('server', () => {
+    it('exists and has expected properties', () => {
         expect(server).toBeDefined();
         expect(typeof server).toBe('function');
     });
 
-    it('should return a promise', function () {
+    it('should return a promise', () => {
         const result = server({ port: 8008, noServerInfo: 1 });
         expect(result).toBeDefined();
         expectPromise(result);
diff --git a/src/browser.js b/src/browser.js
index 1499910..1b4faef 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -47,7 +47,7 @@ module.exports = function (opts) {
         open(url);
         return Promise.resolve();
     } else {
-        return getBrowser(target, opts.dataDir).then(function (browser) {
+        return getBrowser(target, opts.dataDir).then(browser => {
             let args;
             let urlAdded = false;
 
@@ -87,7 +87,7 @@ module.exports = function (opts) {
             }
             const command = args.join(' ');
             const result = exec(command);
-            result.catch(function () {
+            result.catch(() => {
                 // Assume any error means that the browser is not installed and display that as a more friendly error.
                 throw new Error(NOT_INSTALLED.replace('%target%', target));
             });
@@ -130,9 +130,7 @@ function getBrowser (target, dataDir) {
 
     if (target in browsers[process.platform]) {
         const browser = browsers[process.platform][target];
-        return checkBrowserExistsWindows(browser, target).then(function () {
-            return Promise.resolve(browser);
-        });
+        return checkBrowserExistsWindows(browser, target).then(() => browser);
     } else {
         return Promise.reject(NOT_SUPPORTED.replace('%target%', target));
     }
@@ -151,22 +149,22 @@ function getErrorMessage (err, target, defaultMsg) {
 }
 
 function checkBrowserExistsWindows (browser, target) {
-    const promise = new Promise(function (resolve, reject) {
+    const promise = new Promise((resolve, reject) => {
         // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
         if (process.platform === 'win32') {
             if (target === 'edge') {
-                edgeSupported().then(function () {
+                edgeSupported().then(() => {
                     resolve();
                 })
-                    .catch(function (err) {
+                    .catch(err => {
                         const errMessage = getErrorMessage(err, target, NOT_INSTALLED);
                         reject(errMessage);
                     });
             } else {
-                browserInstalled(browser).then(function () {
+                browserInstalled(browser).then(() => {
                     resolve();
                 })
-                    .catch(function (err) {
+                    .catch(err => {
                         const errMessage = getErrorMessage(err, target, NOT_INSTALLED);
                         reject(errMessage);
                     });
@@ -179,8 +177,8 @@ function checkBrowserExistsWindows (browser, target) {
 }
 
 function edgeSupported () {
-    const prom = new Promise(function (resolve, reject) {
-        child_process.exec('ver', function (err, stdout, stderr) {
+    const prom = new Promise((resolve, reject) => {
+        child_process.exec('ver', (err, stdout, stderr) => {
             if (err || stderr) {
                 reject(err || stderr);
             } else {
@@ -203,7 +201,7 @@ function browserInstalled (browser) {
     // for the list of extensions to use if no extension is provided. We simplify that to just '.EXE'
     // since that is what all the supported browsers use. Check path (simple but usually won't get a hit)
 
-    const promise = new Promise(function (resolve, reject) {
+    const promise = new Promise((resolve, reject) => {
         if (which.sync(browser, { nothrow: true })) {
             return resolve();
         } else {
@@ -211,7 +209,7 @@ function browserInstalled (browser) {
             const regQPost = '.EXE" /v ""';
             const regQuery = regQPre + browser.split(' ')[0] + regQPost;
 
-            child_process.exec(regQuery, function (err, stdout, stderr) {
+            child_process.exec(regQuery, (err, stdout, stderr) => {
                 if (err) {
                     // The registry key does not exist, which just means the app is not installed.
                     reject(err);
diff --git a/src/exec.js b/src/exec.js
index f97a60b..a15d20c 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -28,16 +28,16 @@ const child_process = require('child_process');
  * @return {Promise} a promise that either resolves with the stdout, or rejects with an error message and the stderr.
  */
 module.exports = function (cmd, opt_cwd) {
-    return new Promise(function (resolve, reject) {
+    return new Promise((resolve, reject) => {
         try {
             const opt = { cwd: opt_cwd, maxBuffer: 1024000 };
             let timerID = 0;
             if (process.platform === 'linux') {
-                timerID = setTimeout(function () {
+                timerID = setTimeout(() => {
                     resolve('linux-timeout');
                 }, 5000);
             }
-            child_process.exec(cmd, opt, function (err, stdout, stderr) {
+            child_process.exec(cmd, opt, (err, stdout, stderr) => {
                 clearTimeout(timerID);
                 if (err) {
                     reject(new Error('Error executing "' + cmd + '": ' + stderr));
diff --git a/src/main.js b/src/main.js
index 9210345..4d9c9ce 100644
--- a/src/main.js
+++ b/src/main.js
@@ -29,7 +29,7 @@ function CordovaServe () {
     this.app = express();
 
     // Attach this before anything else to provide status output
-    this.app.use(function (req, res, next) {
+    this.app.use((req, res, next) => {
         res.on('finish', function () {
             const color = this.statusCode === '404' ? chalk.red : chalk.green;
             let msg = color(this.statusCode) + ' ' + this.req.originalUrl;
diff --git a/src/platform.js b/src/platform.js
index 9cb4823..80d7038 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -34,7 +34,7 @@ module.exports = function (platform, opts) {
     // note: `this` is actually an instance of main.js CordovaServe
     // this module is a mixin
     const that = this;
-    const retPromise = new Promise(function (resolve, reject) {
+    const retPromise = new Promise((resolve, reject) => {
         if (!platform) {
             reject(new Error('Error: A platform must be specified'));
         } else {
diff --git a/src/server.js b/src/server.js
index 5a360f2..7bef6df 100644
--- a/src/server.js
+++ b/src/server.js
@@ -29,11 +29,11 @@ const express = require('express');
  */
 module.exports = function (opts) {
     const that = this;
-    const promise = new Promise(function (resolve, reject) {
+    const promise = new Promise((resolve, reject) => {
         opts = opts || {};
         let port = opts.port || 8000;
 
-        const log = module.exports.log = function (msg) {
+        const log = module.exports.log = msg => {
             if (!opts.noLogOutput) {
                 if (opts.events) {
                     opts.events.emit('log', msg);
@@ -64,7 +64,7 @@ module.exports = function (opts) {
         }
 
         const listener = server.listen(port);
-        listener.on('listening', function () {
+        listener.on('listening', () => {
             that.port = port;
             const message = 'Static file server running on: ' + chalk.green('http://localhost:' + port) + ' (CTRL + C to shut down)';
             if (!opts.noServerInfo) {
@@ -72,7 +72,7 @@ module.exports = function (opts) {
             }
             resolve(message);
         });
-        listener.on('error', function (e) {
+        listener.on('error', e => {
             if (e && e.toString().indexOf('EADDRINUSE') > -1) {
                 port++;
                 server.listen(port);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org