From 56934a0cfef676804b58198eb056ffc28a9b259a Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Fri, 9 Nov 2018 17:36:15 +0300 Subject: [PATCH 1/7] [I18n] Inject Intl Polyfill to PhantomJS --- x-pack/package.json | 1 + .../server/browsers/phantom/driver/index.js | 227 ++++++++++-------- x-pack/yarn.lock | 5 + 3 files changed, 133 insertions(+), 100 deletions(-) diff --git a/x-pack/package.json b/x-pack/package.json index fa24b5d247717..1fd6f2f090ec3 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -88,6 +88,7 @@ "gulp-multi-process": "^1.3.1", "gulp-pegjs": "^0.1.0", "hapi": "^17.5.3", + "intl": "^1.2.5", "jest": "^23.5.0", "jest-cli": "^23.5.0", "jest-styled-components": "^6.1.1", diff --git a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js index af2036c5382e1..2cbc8d7cf4d1a 100644 --- a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js +++ b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js @@ -125,117 +125,146 @@ export function PhantomDriver({ page, browser, zoom, logger }) { randomBytes(6).toString('base64'), ].join('-'); - return _injectPromise(page) - .then(() => { - return fromCallback(cb => { - page.evaluate(transformFn(evaluateWrapper), transformFn(fn).toString(), uniqId, args, cb); - - // The original function is passed here as a string, and eval'd in phantom's context. - // It's then executed in phantom's context and the result is attached to a __reporting - // property on window. Promises can be used, and the result will be handled in the next - // block. If the original function does not return a promise, its result is passed on. - function evaluateWrapper(userFnStr, cbIndex, origArgs) { - // you can't pass a function to phantom, so we pass the string and eval back into a function - let userFn; - eval('userFn = ' + userFnStr); // eslint-disable-line no-eval - - // keep a record of the resulting execution for future calls (used when async) - window.__reporting = window.__reporting || {}; - window.__reporting[cbIndex] = undefined; - - // used to format the response consistently - function done(err, res) { - if (window.__reporting[cbIndex]) { - return; - } + function checkForIntl() { + return fromCallback(cb => { + page.evaluate(function hasIntl() { + return (window.Intl !== undefined); + }, cb); + }); + } - const isErr = err instanceof Error; - if (isErr) { - const keys = Object.getOwnPropertyNames(err); - err = keys.reduce(function copyErr(obj, key) { - obj[key] = err[key]; - return obj; - }, {}); - } + return checkForIntl() + .then(hasIntl => { + if (hasIntl) return; - return window.__reporting[cbIndex] = { - err: err, - res: res, - }; + const nodeModules = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'node_modules'); + const intlPath = path.join(nodeModules, 'intl', 'dist', 'Intl.js'); + + return fromCallback(cb => page.injectJs(intlPath, cb)) + .then(status => { + if (status !== true) { + return Promise.reject('Failed to load Intl library'); + } + }) + .then(checkForIntl) + .then(hasIntlLoaded => { + if (hasIntlLoaded !== true) { + return Promise.reject('Failed to inject Intl'); } + }); + }) + .then(() => _injectPromise(page) + .then(() => { + return fromCallback(cb => { + page.evaluate(transformFn(evaluateWrapper), transformFn(fn).toString(), uniqId, args, cb); + + // The original function is passed here as a string, and eval'd in phantom's context. + // It's then executed in phantom's context and the result is attached to a __reporting + // property on window. Promises can be used, and the result will be handled in the next + // block. If the original function does not return a promise, its result is passed on. + function evaluateWrapper(userFnStr, cbIndex, origArgs) { + // you can't pass a function to phantom, so we pass the string and eval back into a function + let userFn; + eval('userFn = ' + userFnStr); // eslint-disable-line no-eval + + // keep a record of the resulting execution for future calls (used when async) + window.__reporting = window.__reporting || {}; + window.__reporting[cbIndex] = undefined; + + // used to format the response consistently + function done(err, res) { + if (window.__reporting[cbIndex]) { + return; + } + + const isErr = err instanceof Error; + if (isErr) { + const keys = Object.getOwnPropertyNames(err); + err = keys.reduce(function copyErr(obj, key) { + obj[key] = err[key]; + return obj; + }, {}); + } + + return window.__reporting[cbIndex] = { + err: err, + res: res, + }; + } - try { - // execute the original function - const res = userFn.apply(this, origArgs); - - if (res && typeof res.then === 'function') { - // handle async resolution via Promises - res.then((val) => { - done(null, val); - }, (err) => { - if (!(err instanceof Error)) { - err = new Error(err || 'Unspecified error'); - } - done(err); - }); - return '__promise__'; - } else { - // if not given a promise, execute as sync - return done(null, res); + try { + // execute the original function + const res = userFn.apply(this, origArgs); + + if (res && typeof res.then === 'function') { + // handle async resolution via Promises + res.then((val) => { + done(null, val); + }, (err) => { + if (!(err instanceof Error)) { + err = new Error(err || 'Unspecified error'); + } + done(err); + }); + return '__promise__'; + } else { + // if not given a promise, execute as sync + return done(null, res); + } + } catch (err) { + // any error during execution should be dealt with + return done(err); } - } catch (err) { - // any error during execution should be dealt with - return done(err); - } - } - }) - .then((res) => { - // if the response is not a promise, pass it along - if (res !== '__promise__') { - return res; } + }) + .then((res) => { + // if the response is not a promise, pass it along + if (res !== '__promise__') { + return res; + } - // promise response means async, so wait for its resolution - return this.waitFor({ - fn: function (cbIndex) { - // resolves when the result object is no longer undefined - return !!window.__reporting[cbIndex]; - }, - args: [uniqId], - toEqual: true, - }) - .then(() => { - // once the original promise is resolved, pass along its value - return fromCallback(cb => { - page.evaluate(function (cbIndex) { - return window.__reporting[cbIndex]; - }, uniqId, cb); + // promise response means async, so wait for its resolution + return this.waitFor({ + fn: function (cbIndex) { + // resolves when the result object is no longer undefined + return !!window.__reporting[cbIndex]; + }, + args: [uniqId], + toEqual: true, + }) + .then(() => { + // once the original promise is resolved, pass along its value + return fromCallback(cb => { + page.evaluate(function (cbIndex) { + return window.__reporting[cbIndex]; + }, uniqId, cb); + }); }); - }); - }) - .then((res) => { - if (res.err) { - // Make long/normal stack traces work - res.err.name = res.err.name || 'Error'; + }) + .then((res) => { + if (res.err) { + // Make long/normal stack traces work + res.err.name = res.err.name || 'Error'; - if (!res.err.stack) { - res.err.stack = res.err.toString(); - } + if (!res.err.stack) { + res.err.stack = res.err.toString(); + } - res.err.stack.replace(/\n*$/g, '\n'); + res.err.stack.replace(/\n*$/g, '\n'); - if (res.err.stack) { - res.err.toString = function () { - return this.name + ': ' + this.message; - }; - } + if (res.err.stack) { + res.err.toString = function () { + return this.name + ': ' + this.message; + }; + } - return Promise.reject(res.err); - } + return Promise.reject(res.err); + } - return res.res; - }); - }); + return res.res; + }); + }) + ); }, wait(timeout) { @@ -345,5 +374,3 @@ function _injectPromise(page) { }); }); } - - diff --git a/x-pack/yarn.lock b/x-pack/yarn.lock index f085dabe5aa6b..5ed41e2a16f52 100644 --- a/x-pack/yarn.lock +++ b/x-pack/yarn.lock @@ -5651,6 +5651,11 @@ intl-relativeformat@^2.1.0: dependencies: intl-messageformat "^2.0.0" +intl@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/intl/-/intl-1.2.5.tgz#82244a2190c4e419f8371f5aa34daa3420e2abde" + integrity sha1-giRKIZDE5Bn4Nx9ao02qNCDiq94= + into-stream@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/into-stream/-/into-stream-3.1.0.tgz#96fb0a936c12babd6ff1752a17d05616abd094c6" From c46409c413b0236de193c2cc447ffeb6eebc7a6b Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Mon, 12 Nov 2018 11:05:36 +0300 Subject: [PATCH 2/7] Refactor injection code --- .../server/browsers/phantom/driver/index.js | 286 +++++++++--------- 1 file changed, 135 insertions(+), 151 deletions(-) diff --git a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js index 2cbc8d7cf4d1a..4aa1800e8b469 100644 --- a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js +++ b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js @@ -125,146 +125,137 @@ export function PhantomDriver({ page, browser, zoom, logger }) { randomBytes(6).toString('base64'), ].join('-'); - function checkForIntl() { - return fromCallback(cb => { - page.evaluate(function hasIntl() { - return (window.Intl !== undefined); - }, cb); - }); - } + const nodeModules = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'node_modules'); + const intlPath = path.join(nodeModules, 'intl', 'dist', 'Intl.js'); + const promisePath = path.join(nodeModules, 'bluebird', 'js', 'browser', 'bluebird.js'); - return checkForIntl() - .then(hasIntl => { - if (hasIntl) return; + return injectPolyfill( + page, + intlPath, + function hasIntl() { + return (window.Intl !== undefined); + }, + 'Intl' + ) + .then(() => + injectPolyfill( + page, + promisePath, + function hasPromise() { + return (typeof window.Promise !== 'undefined'); + }, + 'Promise' + )) + .then(() => { + return fromCallback(cb => { + page.evaluate(transformFn(evaluateWrapper), transformFn(fn).toString(), uniqId, args, cb); + + // The original function is passed here as a string, and eval'd in phantom's context. + // It's then executed in phantom's context and the result is attached to a __reporting + // property on window. Promises can be used, and the result will be handled in the next + // block. If the original function does not return a promise, its result is passed on. + function evaluateWrapper(userFnStr, cbIndex, origArgs) { + // you can't pass a function to phantom, so we pass the string and eval back into a function + let userFn; + eval('userFn = ' + userFnStr); // eslint-disable-line no-eval + + // keep a record of the resulting execution for future calls (used when async) + window.__reporting = window.__reporting || {}; + window.__reporting[cbIndex] = undefined; + + // used to format the response consistently + function done(err, res) { + if (window.__reporting[cbIndex]) { + return; + } - const nodeModules = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'node_modules'); - const intlPath = path.join(nodeModules, 'intl', 'dist', 'Intl.js'); + const isErr = err instanceof Error; + if (isErr) { + const keys = Object.getOwnPropertyNames(err); + err = keys.reduce(function copyErr(obj, key) { + obj[key] = err[key]; + return obj; + }, {}); + } - return fromCallback(cb => page.injectJs(intlPath, cb)) - .then(status => { - if (status !== true) { - return Promise.reject('Failed to load Intl library'); + return window.__reporting[cbIndex] = { + err: err, + res: res, + }; } - }) - .then(checkForIntl) - .then(hasIntlLoaded => { - if (hasIntlLoaded !== true) { - return Promise.reject('Failed to inject Intl'); - } - }); - }) - .then(() => _injectPromise(page) - .then(() => { - return fromCallback(cb => { - page.evaluate(transformFn(evaluateWrapper), transformFn(fn).toString(), uniqId, args, cb); - - // The original function is passed here as a string, and eval'd in phantom's context. - // It's then executed in phantom's context and the result is attached to a __reporting - // property on window. Promises can be used, and the result will be handled in the next - // block. If the original function does not return a promise, its result is passed on. - function evaluateWrapper(userFnStr, cbIndex, origArgs) { - // you can't pass a function to phantom, so we pass the string and eval back into a function - let userFn; - eval('userFn = ' + userFnStr); // eslint-disable-line no-eval - - // keep a record of the resulting execution for future calls (used when async) - window.__reporting = window.__reporting || {}; - window.__reporting[cbIndex] = undefined; - - // used to format the response consistently - function done(err, res) { - if (window.__reporting[cbIndex]) { - return; - } - - const isErr = err instanceof Error; - if (isErr) { - const keys = Object.getOwnPropertyNames(err); - err = keys.reduce(function copyErr(obj, key) { - obj[key] = err[key]; - return obj; - }, {}); - } - - return window.__reporting[cbIndex] = { - err: err, - res: res, - }; - } - try { - // execute the original function - const res = userFn.apply(this, origArgs); - - if (res && typeof res.then === 'function') { - // handle async resolution via Promises - res.then((val) => { - done(null, val); - }, (err) => { - if (!(err instanceof Error)) { - err = new Error(err || 'Unspecified error'); - } - done(err); - }); - return '__promise__'; - } else { - // if not given a promise, execute as sync - return done(null, res); - } - } catch (err) { - // any error during execution should be dealt with - return done(err); + try { + // execute the original function + const res = userFn.apply(this, origArgs); + + if (res && typeof res.then === 'function') { + // handle async resolution via Promises + res.then((val) => { + done(null, val); + }, (err) => { + if (!(err instanceof Error)) { + err = new Error(err || 'Unspecified error'); + } + done(err); + }); + return '__promise__'; + } else { + // if not given a promise, execute as sync + return done(null, res); } + } catch (err) { + // any error during execution should be dealt with + return done(err); + } + } + }) + .then((res) => { + // if the response is not a promise, pass it along + if (res !== '__promise__') { + return res; } - }) - .then((res) => { - // if the response is not a promise, pass it along - if (res !== '__promise__') { - return res; - } - // promise response means async, so wait for its resolution - return this.waitFor({ - fn: function (cbIndex) { - // resolves when the result object is no longer undefined - return !!window.__reporting[cbIndex]; - }, - args: [uniqId], - toEqual: true, - }) - .then(() => { - // once the original promise is resolved, pass along its value - return fromCallback(cb => { - page.evaluate(function (cbIndex) { - return window.__reporting[cbIndex]; - }, uniqId, cb); - }); - }); + // promise response means async, so wait for its resolution + return this.waitFor({ + fn: function (cbIndex) { + // resolves when the result object is no longer undefined + return !!window.__reporting[cbIndex]; + }, + args: [uniqId], + toEqual: true, }) - .then((res) => { - if (res.err) { - // Make long/normal stack traces work - res.err.name = res.err.name || 'Error'; - - if (!res.err.stack) { - res.err.stack = res.err.toString(); - } + .then(() => { + // once the original promise is resolved, pass along its value + return fromCallback(cb => { + page.evaluate(function (cbIndex) { + return window.__reporting[cbIndex]; + }, uniqId, cb); + }); + }); + }) + .then((res) => { + if (res.err) { + // Make long/normal stack traces work + res.err.name = res.err.name || 'Error'; - res.err.stack.replace(/\n*$/g, '\n'); + if (!res.err.stack) { + res.err.stack = res.err.toString(); + } - if (res.err.stack) { - res.err.toString = function () { - return this.name + ': ' + this.message; - }; - } + res.err.stack.replace(/\n*$/g, '\n'); - return Promise.reject(res.err); + if (res.err.stack) { + res.err.toString = function () { + return this.name + ': ' + this.message; + }; } - return res.res; - }); - }) - ); + return Promise.reject(res.err); + } + + return res.res; + }); + }); }, wait(timeout) { @@ -344,33 +335,26 @@ export function PhantomDriver({ page, browser, zoom, logger }) { }; } +async function injectPolyfill(page, pathToPolyfillFile, checkFunction, libraryName) { + const hasPolyfill = await fromCallback(cb => { + page.evaluate(checkFunction, cb); + }); -function _injectPromise(page) { - function checkForPromise() { - return fromCallback(cb => { - page.evaluate(function hasPromise() { - return (typeof window.Promise !== 'undefined'); - }, cb); - }); + if (hasPolyfill) { + return; } - return checkForPromise() - .then(hasPromise => { - if (hasPromise) return; + const status = await fromCallback(cb => page.injectJs(pathToPolyfillFile, cb)); - const nodeModules = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'node_modules'); - const promisePath = path.join(nodeModules, 'bluebird', 'js', 'browser', 'bluebird.js'); - return fromCallback(cb => page.injectJs(promisePath, cb)) - .then(status => { - if (status !== true) { - return Promise.reject('Failed to load Promise library'); - } - }) - .then(checkForPromise) - .then(hasPromiseLoaded => { - if (hasPromiseLoaded !== true) { - return Promise.reject('Failed to inject Promise'); - } - }); - }); + if (status !== true) { + return Promise.reject(`Failed to load ${libraryName} library`); + } + + const hasPolyfillLoaded = await fromCallback(cb => { + page.evaluate(checkFunction, cb); + }); + + if (hasPolyfillLoaded !== true) { + return Promise.reject(`Failed to inject ${libraryName}`); + } } From 66ca98ba365732dbec47cd1c71e9de91f595c166 Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Mon, 12 Nov 2018 17:26:01 +0300 Subject: [PATCH 3/7] Move intl to "dependencies" --- x-pack/package.json | 2 +- yarn.lock | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/package.json b/x-pack/package.json index 1fd6f2f090ec3..8e7c83812d139 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -88,7 +88,6 @@ "gulp-multi-process": "^1.3.1", "gulp-pegjs": "^0.1.0", "hapi": "^17.5.3", - "intl": "^1.2.5", "jest": "^23.5.0", "jest-cli": "^23.5.0", "jest-styled-components": "^6.1.1", @@ -179,6 +178,7 @@ "humps": "2.0.1", "icalendar": "0.7.1", "inline-style": "^2.0.0", + "intl": "^1.2.5", "isomorphic-fetch": "2.2.1", "joi": "^13.5.2", "jquery": "^3.3.1", diff --git a/yarn.lock b/yarn.lock index 05a7459e2008f..c44f70d6227bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8500,6 +8500,11 @@ intl-relativeformat@^2.1.0: dependencies: intl-messageformat "^2.0.0" +intl@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/intl/-/intl-1.2.5.tgz#82244a2190c4e419f8371f5aa34daa3420e2abde" + integrity sha1-giRKIZDE5Bn4Nx9ao02qNCDiq94= + into-stream@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/into-stream/-/into-stream-3.1.0.tgz#96fb0a936c12babd6ff1752a17d05616abd094c6" From 73b0344e14b29245b4dd7239b737b1a894670ce6 Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Tue, 13 Nov 2018 12:36:06 +0300 Subject: [PATCH 4/7] Move 'intl' to the root 'package.json' --- package.json | 1 + x-pack/package.json | 1 - .../reporting/server/browsers/phantom/driver/index.js | 6 +++--- x-pack/yarn.lock | 5 ----- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c1564dd1c9327..d7aea194800b8 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "http-proxy-agent": "^2.1.0", "https-proxy-agent": "^2.2.1", "inert": "^5.1.0", + "intl": "^1.2.5", "joi": "^13.5.2", "jquery": "^3.3.1", "js-yaml": "3.4.1", diff --git a/x-pack/package.json b/x-pack/package.json index 8e7c83812d139..fa24b5d247717 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -178,7 +178,6 @@ "humps": "2.0.1", "icalendar": "0.7.1", "inline-style": "^2.0.0", - "intl": "^1.2.5", "isomorphic-fetch": "2.2.1", "joi": "^13.5.2", "jquery": "^3.3.1", diff --git a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js index 4aa1800e8b469..dd18a95bf2a15 100644 --- a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js +++ b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js @@ -125,9 +125,9 @@ export function PhantomDriver({ page, browser, zoom, logger }) { randomBytes(6).toString('base64'), ].join('-'); - const nodeModules = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', 'node_modules'); - const intlPath = path.join(nodeModules, 'intl', 'dist', 'Intl.js'); - const promisePath = path.join(nodeModules, 'bluebird', 'js', 'browser', 'bluebird.js'); + const xpackRoot = path.resolve(__dirname, '..', '..', '..', '..', '..', '..'); + const intlPath = path.join(xpackRoot, '..', 'node_modules', 'intl', 'dist', 'Intl.js'); + const promisePath = path.join(xpackRoot, 'node_modules', 'bluebird', 'js', 'browser', 'bluebird.js'); return injectPolyfill( page, diff --git a/x-pack/yarn.lock b/x-pack/yarn.lock index 5ed41e2a16f52..f085dabe5aa6b 100644 --- a/x-pack/yarn.lock +++ b/x-pack/yarn.lock @@ -5651,11 +5651,6 @@ intl-relativeformat@^2.1.0: dependencies: intl-messageformat "^2.0.0" -intl@^1.2.5: - version "1.2.5" - resolved "https://registry.yarnpkg.com/intl/-/intl-1.2.5.tgz#82244a2190c4e419f8371f5aa34daa3420e2abde" - integrity sha1-giRKIZDE5Bn4Nx9ao02qNCDiq94= - into-stream@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/into-stream/-/into-stream-3.1.0.tgz#96fb0a936c12babd6ff1752a17d05616abd094c6" From 2d767872a4c9804db8efd055e1a6335ce0579c31 Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Thu, 15 Nov 2018 12:56:59 +0300 Subject: [PATCH 5/7] Fix polyfills paths --- .../reporting/server/browsers/phantom/driver/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js index dd18a95bf2a15..469791394cd6d 100644 --- a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js +++ b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import path from 'path'; import { randomBytes } from 'crypto'; import { fromCallback } from 'bluebird'; import { transformFn } from './transform_fn'; @@ -125,9 +124,8 @@ export function PhantomDriver({ page, browser, zoom, logger }) { randomBytes(6).toString('base64'), ].join('-'); - const xpackRoot = path.resolve(__dirname, '..', '..', '..', '..', '..', '..'); - const intlPath = path.join(xpackRoot, '..', 'node_modules', 'intl', 'dist', 'Intl.js'); - const promisePath = path.join(xpackRoot, 'node_modules', 'bluebird', 'js', 'browser', 'bluebird.js'); + const intlPath = require.resolve('intl/dist/Intl.min.js'); + const promisePath = require.resolve('bluebird/js/browser/bluebird.js'); return injectPolyfill( page, From 6c67657d6032bcfc7bcce3cb1d35afb5f5f8075b Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Thu, 15 Nov 2018 16:15:41 +0300 Subject: [PATCH 6/7] Move intl to x-pack package.json --- package.json | 3 +-- x-pack/package.json | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d64008376d27d..11c973df22f72 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,6 @@ "http-proxy-agent": "^2.1.0", "https-proxy-agent": "^2.2.1", "inert": "^5.1.0", - "intl": "^1.2.5", "joi": "^13.5.2", "jquery": "^3.3.1", "js-yaml": "3.4.1", @@ -385,4 +384,4 @@ "node": "8.11.4", "yarn": "^1.10.1" } -} \ No newline at end of file +} diff --git a/x-pack/package.json b/x-pack/package.json index 278f350386751..14fff20e07df7 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -178,6 +178,7 @@ "humps": "2.0.1", "icalendar": "0.7.1", "inline-style": "^2.0.0", + "intl": "^1.2.5", "isomorphic-fetch": "2.2.1", "joi": "^13.5.2", "jquery": "^3.3.1", @@ -268,4 +269,4 @@ "engines": { "yarn": "^1.6.0" } -} \ No newline at end of file +} From c720cfd294494497a907fd886c2330ae08f05bf5 Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Thu, 15 Nov 2018 16:43:38 +0300 Subject: [PATCH 7/7] Resolve comments --- package.json | 2 +- x-pack/package.json | 2 +- .../server/browsers/phantom/driver/index.js | 18 ++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 11c973df22f72..bb04bc804fcc8 100644 --- a/package.json +++ b/package.json @@ -384,4 +384,4 @@ "node": "8.11.4", "yarn": "^1.10.1" } -} +} \ No newline at end of file diff --git a/x-pack/package.json b/x-pack/package.json index 14fff20e07df7..249cc08c8b900 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -269,4 +269,4 @@ "engines": { "yarn": "^1.6.0" } -} +} \ No newline at end of file diff --git a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js index 469791394cd6d..f8e7f0f254bea 100644 --- a/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js +++ b/x-pack/plugins/reporting/server/browsers/phantom/driver/index.js @@ -132,17 +132,15 @@ export function PhantomDriver({ page, browser, zoom, logger }) { intlPath, function hasIntl() { return (window.Intl !== undefined); - }, - 'Intl' + } ) .then(() => injectPolyfill( page, promisePath, function hasPromise() { - return (typeof window.Promise !== 'undefined'); - }, - 'Promise' + return (window.Promise !== undefined); + } )) .then(() => { return fromCallback(cb => { @@ -333,7 +331,7 @@ export function PhantomDriver({ page, browser, zoom, logger }) { }; } -async function injectPolyfill(page, pathToPolyfillFile, checkFunction, libraryName) { +async function injectPolyfill(page, pathToPolyfillFile, checkFunction) { const hasPolyfill = await fromCallback(cb => { page.evaluate(checkFunction, cb); }); @@ -344,15 +342,15 @@ async function injectPolyfill(page, pathToPolyfillFile, checkFunction, libraryNa const status = await fromCallback(cb => page.injectJs(pathToPolyfillFile, cb)); - if (status !== true) { - return Promise.reject(`Failed to load ${libraryName} library`); + if (!status) { + return Promise.reject(`Failed to load ${pathToPolyfillFile} library`); } const hasPolyfillLoaded = await fromCallback(cb => { page.evaluate(checkFunction, cb); }); - if (hasPolyfillLoaded !== true) { - return Promise.reject(`Failed to inject ${libraryName}`); + if (!hasPolyfillLoaded) { + return Promise.reject(`Failed to inject ${pathToPolyfillFile}`); } }