jenkins-bot has submitted this change and it was merged.

Change subject: Switch from es6-shim to core-js; update prfun and jshint.
......................................................................


Switch from es6-shim to core-js; update prfun and jshint.

We now use a subclass of the native Promise instead of polluting the
global Promise.  The `P.spawn()` method has also been updated to match
the version in mw-ocg-latexer.

Change-Id: I3a319520b4614aaaeeb1bf1742f4390d73d624d4
---
M .jshintrc
M bin/mw-ocg-texter
M lib/db.js
M lib/index.js
M lib/p.js
M package.json
M test/samples.js
7 files changed, 51 insertions(+), 24 deletions(-)

Approvals:
  Arlolra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.jshintrc b/.jshintrc
index 529d30e..88e79fd 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -7,7 +7,6 @@
                "QUnit",
 
                "Map",
-               "Promise",
                "Set"
        ],
 
diff --git a/bin/mw-ocg-texter b/bin/mw-ocg-texter
index 1b3b415..d1a1de5 100755
--- a/bin/mw-ocg-texter
+++ b/bin/mw-ocg-texter
@@ -1,6 +1,6 @@
 #!/usr/bin/env node
-require('es6-shim');
-require('prfun');
+require('core-js/shim');
+var Promise = require('prfun');
 
 var program = require('commander');
 var texter = require('../');
diff --git a/lib/db.js b/lib/db.js
index 1d9b0c9..c208056 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -1,7 +1,7 @@
 // Helpers to create/read key/value mappings in sqlite db
 "use strict";
-require('es6-shim');
-require('prfun');
+require('core-js/shim');
+var Promise = require('prfun');
 
 var sqlite3 = require('sqlite3');
 
diff --git a/lib/index.js b/lib/index.js
index 7e5f467..d01a1fa 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,8 +2,8 @@
 // ---------------------------------------------------------------------
 "use strict";
 
-require('es6-shim');
-require('prfun');
+require('core-js/shim');
+var Promise = require('prfun');
 
 var json = require('../package.json');
 
@@ -896,7 +896,7 @@
                // now unpack the zip archive
                var bundledir = path.join(builddir, 'bundle');
                return P.spawn('unzip', [ '-q', path.resolve( options.bundle ) 
], {
-                       cwd: bundledir
+                       childOptions: { cwd: bundledir }
                });
        }).then(function() {
                return builddir;
diff --git a/lib/p.js b/lib/p.js
index 1a997ea..efcf20e 100644
--- a/lib/p.js
+++ b/lib/p.js
@@ -1,7 +1,7 @@
 // Helpers for promises.
 "use strict";
-require('es6-shim');
-require('prfun');
+require('core-js/shim');
+var Promise = require('prfun');
 
 var spawn = require('child_process').spawn;
 
@@ -18,18 +18,46 @@
 // Returns a promise for completion after spawning `program`
 P.spawn = function(program, args, options) {
        return new Promise(function(resolve, reject) {
-               spawn(program, args || [], options || { stdio: 'inherit' }).
-                       on('exit', function(exitCode) {
+               options = options || {};
+               options.childOptions = options.childOptions || {};
+               options.childOptions.stdio = options.childOptions.stdio || 
'inherit';
+               var killTimer = null, killed = false;
+               var clearKillTimer = function() {
+                       if (killTimer) {
+                               clearTimeout(killTimer);
+                               killTimer = null;
+                       }
+               };
+               var child = spawn(program, args || [], options.childOptions).
+                       on('exit', function(exitCode, signal) {
+                               clearKillTimer();
                                if (exitCode === 0) {
-                                       resolve();
-                               } else {
-                                       reject(new Error(
-                                               program+' '+args.join(' ')+' 
exited with code '+exitCode
-                                       ));
+                                       return resolve();
                                }
+                               var timeout = killed && /* maybe we tried, but 
failed */
+                                       ( signal === 'SIGTERM' || signal === 
'SIGKILL');
+                               var e = new Error(
+                                       program + ' ' + args.join(' ') + ' ' +
+                                       (timeout ? 'exceeded execution time' : 
'exited with code '+exitCode)
+                               );
+                               e.code = exitCode;
+                               e.signal = signal;
+                               e.timeout = timeout;
+                               return reject(e);
                        }).on('error', function(err) {
+                               clearKillTimer();
                                reject(err);
                        });
+               if (options.timeout) {
+                       killTimer = setTimeout(function() {
+                               killed = true;
+                               child.kill('SIGTERM');
+                               killTimer = setTimeout(function() {
+                                       child.kill('SIGKILL');
+                                       killTimer = null;
+                               }, options.timeout * 2);
+                       }, options.timeout);
+               }
        });
 };
 
@@ -39,7 +67,7 @@
 // If the optional `p` parameter is provided, wait for that to resolve
 // before starting to process the array contents.
 P.forEachPar = function(a, f, p) {
-       return (p || Promise.resolve()).then(function() {
+       return Promise.resolve(p).then(function() {
                return a;
        }).then(function(aResolved) {
                return Promise.all(aResolved.map(f));
@@ -52,7 +80,7 @@
 // before starting to process the array contents.
 P.forEachSeq = function(a, f, p) {
        // The initial value must not be undefined.  Arbitrarily choose `true`.
-       p = p ? p.return(true) : Promise.resolve(true);
+       p = p ? Promise.resolve(p).return(true) : Promise.resolve(true);
        return Promise.reduce(a, function(curResult, value, index, total) {
                /* jshint unused: vars */
                return f.call(null, value, index, null);
diff --git a/package.json b/package.json
index 696fc88..457a4a0 100644
--- a/package.json
+++ b/package.json
@@ -17,16 +17,16 @@
   "license": "GPLv2",
   "dependencies": {
     "commander": "~2.5.0",
+    "core-js": "~0.9.1",
     "domino": "~1.0.17",
-    "es6-shim": "~0.20.2",
     "linewrap": "~0.2.1",
-    "prfun": "~1.0.1",
+    "prfun": "~2.1.1",
     "readable-stream": "~1.0.0",
     "sqlite3": "~2.2.3",
     "tmp": "~0.0.24"
   },
   "devDependencies": {
-    "jshint": "~2.5.0",
+    "jshint": "~2.6.3",
     "mocha": "~2.0.1"
   },
   "bin": {
diff --git a/test/samples.js b/test/samples.js
index dc9ada7..f8c277d 100644
--- a/test/samples.js
+++ b/test/samples.js
@@ -1,7 +1,7 @@
 /* global describe, it */
 "use strict";
-require('es6-shim');
-require('prfun');
+require('core-js/shim');
+var Promise = require('prfun');
 
 var assert = require('assert');
 var fs = require('fs');

-- 
To view, visit https://gerrit.wikimedia.org/r/209797
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a319520b4614aaaeeb1bf1742f4390d73d624d4
Gerrit-PatchSet: 1
Gerrit-Project: 
mediawiki/extensions/Collection/OfflineContentGenerator/text_renderer
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to