From de7da0cd19ecbab63f9e0cc58f8356a22e3698c6 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 11 Sep 2019 10:04:25 -0700 Subject: [PATCH] =?UTF-8?q?[optimize/bundleContext]=20do=20not=20include?= =?UTF-8?q?=20absolute=20urls=20or=20windo=E2=80=A6=20(#45318)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [optimize/bundleContext] do not include absolute urls or windows slashes * simplify the stable clone fn, it doesn't need to be generic --- .../ui/ui_bundles/ui_bundles_controller.js | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/legacy/ui/ui_bundles/ui_bundles_controller.js b/src/legacy/ui/ui_bundles/ui_bundles_controller.js index 5e9ae0abbb18..f0410f57c457 100644 --- a/src/legacy/ui/ui_bundles/ui_bundles_controller.js +++ b/src/legacy/ui/ui_bundles/ui_bundles_controller.js @@ -17,7 +17,7 @@ * under the License. */ -import { resolve } from 'path'; +import { resolve, relative, isAbsolute } from 'path'; import { createHash } from 'crypto'; import { promisify } from 'util'; import { existsSync } from 'fs'; @@ -27,12 +27,13 @@ import { makeRe } from 'minimatch'; import mkdirp from 'mkdirp'; import jsonStableStringify from 'json-stable-stringify'; -import { IS_KIBANA_DISTRIBUTABLE } from '../../utils'; +import { IS_KIBANA_DISTRIBUTABLE, fromRoot } from '../../utils'; import { UiBundle } from './ui_bundle'; import { appEntryTemplate } from './app_entry_template'; const mkdirpAsync = promisify(mkdirp); +const REPO_ROOT = fromRoot(); function getWebpackAliases(pluginSpecs) { return pluginSpecs.reduce((aliases, spec) => { @@ -49,19 +50,21 @@ function getWebpackAliases(pluginSpecs) { }, {}); } -function sortAllArrays(input) { - if (Array.isArray(input)) { - return input - .map(i => sortAllArrays(i)) - .sort((a, b) => typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0); - } - - if (typeof input === 'object') { - return Object.entries(input) - .map(([key, value]) => [key, sortAllArrays(value)]); - } - - return input; +// Recursively clone appExtensions, sorting array and normalizing absolute paths +function stableCloneAppExtensions(appExtensions) { + return Object.fromEntries( + Object.entries(appExtensions).map(([extensionType, moduleIds]) => [ + extensionType, + moduleIds + .map(moduleId => { + if (isAbsolute(moduleId)) { + moduleId = `absolute:${relative(REPO_ROOT, moduleId)}`; + } + return moduleId.replace(/\\/g, '/'); + }) + .sort((a, b) => a.localeCompare(b)) + ]) + ); } export class UiBundlesController { @@ -75,7 +78,7 @@ export class UiBundlesController { sourceMaps: config.get('optimize.sourceMaps'), kbnVersion: config.get('pkg.version'), buildNum: config.get('pkg.buildNum'), - appExtensions: sortAllArrays(uiExports.appExtensions), + appExtensions: stableCloneAppExtensions(uiExports.appExtensions), }; this._filter = makeRe(config.get('optimize.bundleFilter') || '*', {