Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optimize/bundleContext] do not include absolute urls or windows slashes #45318

Merged
merged 3 commits into from
Sep 11, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/legacy/ui/ui_bundles/ui_bundles_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) => {
Expand All @@ -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 {
Expand All @@ -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') || '*', {
Expand Down