Skip to content

Commit

Permalink
Revert "[7.x] [kbn/optimizer] implement "requiredBundles" property of…
Browse files Browse the repository at this point in the history
… KP plugins (#70911) (#71355)" (#71382)

This reverts commit 243a864.
  • Loading branch information
brianseeders authored Jul 11, 2020
1 parent 243a864 commit c45fa3d
Show file tree
Hide file tree
Showing 127 changed files with 184 additions and 890 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ export interface DiscoveredPlugin
| [configPath](./kibana-plugin-core-server.discoveredplugin.configpath.md) | <code>ConfigPath</code> | Root configuration path used by the plugin, defaults to "id" in snake\_case format. |
| [id](./kibana-plugin-core-server.discoveredplugin.id.md) | <code>PluginName</code> | Identifier of the plugin. |
| [optionalPlugins](./kibana-plugin-core-server.discoveredplugin.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredBundles](./kibana-plugin-core-server.discoveredplugin.requiredbundles.md) | <code>readonly PluginName[]</code> | List of plugin ids that this plugin's UI code imports modules from that are not in <code>requiredPlugins</code>. |
| [requiredPlugins](./kibana-plugin-core-server.discoveredplugin.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Should never be used in code outside of Core but is exported for documentation p
| [id](./kibana-plugin-core-server.pluginmanifest.id.md) | <code>PluginName</code> | Identifier of the plugin. Must be a string in camelCase. Part of a plugin public contract. Other plugins leverage it to access plugin API, navigate to the plugin, etc. |
| [kibanaVersion](./kibana-plugin-core-server.pluginmanifest.kibanaversion.md) | <code>string</code> | The version of Kibana the plugin is compatible with, defaults to "version". |
| [optionalPlugins](./kibana-plugin-core-server.pluginmanifest.optionalplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that if installed and enabled \*\*may be\*\* leveraged by this plugin for some additional functionality but otherwise are not required for this plugin to work properly. |
| [requiredBundles](./kibana-plugin-core-server.pluginmanifest.requiredbundles.md) | <code>readonly string[]</code> | List of plugin ids that this plugin's UI code imports modules from that are not in <code>requiredPlugins</code>. |
| [requiredPlugins](./kibana-plugin-core-server.pluginmanifest.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
| [server](./kibana-plugin-core-server.pluginmanifest.server.md) | <code>boolean</code> | Specifies whether plugin includes some server-side specific functionality. |
| [ui](./kibana-plugin-core-server.pluginmanifest.ui.md) | <code>boolean</code> | Specifies whether plugin includes some client/browser specific functionality that should be included into client bundle via <code>public/ui_plugin.js</code> file. |
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions examples/bfetch_explorer/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"server": true,
"ui": true,
"requiredPlugins": ["bfetch", "developerExamples"],
"optionalPlugins": [],
"requiredBundles": ["kibanaReact"]
"optionalPlugins": []
}
3 changes: 1 addition & 2 deletions examples/dashboard_embeddable_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"server": false,
"ui": true,
"requiredPlugins": ["embeddable", "embeddableExamples", "dashboard", "developerExamples"],
"optionalPlugins": [],
"requiredBundles": ["esUiShared"]
"optionalPlugins": []
}
3 changes: 1 addition & 2 deletions examples/embeddable_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"ui": true,
"requiredPlugins": ["embeddable", "uiActions"],
"optionalPlugins": [],
"extraPublicDirs": ["public/todo", "public/hello_world", "public/todo/todo_ref_embeddable"],
"requiredBundles": ["kibanaReact"]
"extraPublicDirs": ["public/todo", "public/hello_world", "public/todo/todo_ref_embeddable"]
}
3 changes: 1 addition & 2 deletions examples/state_containers_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"server": true,
"ui": true,
"requiredPlugins": ["navigation", "data", "developerExamples"],
"optionalPlugins": [],
"requiredBundles": ["kibanaUtils", "kibanaReact"]
"optionalPlugins": []
}
3 changes: 1 addition & 2 deletions examples/ui_action_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"server": false,
"ui": true,
"requiredPlugins": ["uiActions"],
"optionalPlugins": [],
"requiredBundles": ["kibanaReact"]
"optionalPlugins": []
}
3 changes: 1 addition & 2 deletions examples/ui_actions_explorer/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"server": false,
"ui": true,
"requiredPlugins": ["uiActions", "uiActionsExamples", "developerExamples"],
"optionalPlugins": [],
"requiredBundles": ["kibanaReact"]
"optionalPlugins": []
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"id": "bar",
"ui": true,
"requiredBundles": ["foo"]
"ui": true
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "./other_styles.scss";

body {
width: $globalStyleConstant;
background-image: url("ui/icon.svg");
Expand Down
10 changes: 1 addition & 9 deletions packages/kbn-optimizer/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ run(
throw createFlagError('expected --report-stats to have no value');
}

const filter = typeof flags.filter === 'string' ? [flags.filter] : flags.filter;
if (!Array.isArray(filter) || !filter.every((f) => typeof f === 'string')) {
throw createFlagError('expected --filter to be one or more strings');
}

const config = OptimizerConfig.create({
repoRoot: REPO_ROOT,
watch,
Expand All @@ -104,7 +99,6 @@ run(
extraPluginScanDirs,
inspectWorkers,
includeCoreBundle,
filter,
});

let update$ = runOptimizer(config);
Expand Down Expand Up @@ -134,13 +128,12 @@ run(
'inspect-workers',
'report-stats',
],
string: ['workers', 'scan-dir', 'filter'],
string: ['workers', 'scan-dir'],
default: {
core: true,
examples: true,
cache: true,
'inspect-workers': true,
filter: [],
},
help: `
--watch run the optimizer in watch mode
Expand All @@ -149,7 +142,6 @@ run(
--profile profile the webpack builds and write stats.json files to build outputs
--no-core disable generating the core bundle
--no-cache disable the cache
--filter comma-separated list of bundle id filters, results from multiple flags are merged, * and ! are supported
--no-examples don't build the example plugins
--dist create bundles that are suitable for inclusion in the Kibana distributable
--scan-dir add a directory to the list of directories scanned for plugins (specify as many times as necessary)
Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-optimizer/src/common/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ it('creates cache keys', () => {
"spec": Object {
"contextDir": "/foo/bar",
"id": "bar",
"manifestPath": undefined,
"outputDir": "/foo/bar/target",
"publicDirNames": Array [
"public",
Expand Down Expand Up @@ -86,7 +85,6 @@ it('parses bundles from JSON specs', () => {
},
"contextDir": "/foo/bar",
"id": "bar",
"manifestPath": undefined,
"outputDir": "/foo/bar/target",
"publicDirNames": Array [
"public",
Expand Down
69 changes: 0 additions & 69 deletions packages/kbn-optimizer/src/common/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
*/

import Path from 'path';
import Fs from 'fs';

import { BundleCache } from './bundle_cache';
import { UnknownVals } from './ts_helpers';
import { includes, ascending, entriesToObject } from './array_helpers';

const VALID_BUNDLE_TYPES = ['plugin' as const, 'entry' as const];

const DEFAULT_IMPLICIT_BUNDLE_DEPS = ['core'];

const isStringArray = (input: any): input is string[] =>
Array.isArray(input) && input.every((x) => typeof x === 'string');

export interface BundleSpec {
readonly type: typeof VALID_BUNDLE_TYPES[0];
/** Unique id for this bundle */
Expand All @@ -43,8 +37,6 @@ export interface BundleSpec {
readonly sourceRoot: string;
/** Absolute path to the directory where output should be written */
readonly outputDir: string;
/** Absolute path to a kibana.json manifest file, if omitted we assume there are not dependenices */
readonly manifestPath?: string;
}

export class Bundle {
Expand All @@ -64,12 +56,6 @@ export class Bundle {
public readonly sourceRoot: BundleSpec['sourceRoot'];
/** Absolute path to the output directory for this bundle */
public readonly outputDir: BundleSpec['outputDir'];
/**
* Absolute path to a manifest file with "requiredBundles" which will be
* used to allow bundleRefs from this bundle to the exports of another bundle.
* Every bundle mentioned in the `requiredBundles` must be built together.
*/
public readonly manifestPath: BundleSpec['manifestPath'];

public readonly cache: BundleCache;

Expand All @@ -80,7 +66,6 @@ export class Bundle {
this.contextDir = spec.contextDir;
this.sourceRoot = spec.sourceRoot;
this.outputDir = spec.outputDir;
this.manifestPath = spec.manifestPath;

this.cache = new BundleCache(Path.resolve(this.outputDir, '.kbn-optimizer-cache'));
}
Expand Down Expand Up @@ -111,54 +96,8 @@ export class Bundle {
contextDir: this.contextDir,
sourceRoot: this.sourceRoot,
outputDir: this.outputDir,
manifestPath: this.manifestPath,
};
}

readBundleDeps(): { implicit: string[]; explicit: string[] } {
if (!this.manifestPath) {
return {
implicit: [...DEFAULT_IMPLICIT_BUNDLE_DEPS],
explicit: [],
};
}

let json: string;
try {
json = Fs.readFileSync(this.manifestPath, 'utf8');
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}

json = '{}';
}

let parsedManifest: { requiredPlugins?: string[]; requiredBundles?: string[] };
try {
parsedManifest = JSON.parse(json);
} catch (error) {
throw new Error(
`unable to parse manifest at [${this.manifestPath}], error: [${error.message}]`
);
}

if (typeof parsedManifest === 'object' && parsedManifest) {
const explicit = parsedManifest.requiredBundles || [];
const implicit = [...DEFAULT_IMPLICIT_BUNDLE_DEPS, ...(parsedManifest.requiredPlugins || [])];

if (isStringArray(explicit) && isStringArray(implicit)) {
return {
explicit,
implicit,
};
}
}

throw new Error(
`Expected "requiredBundles" and "requiredPlugins" in manifest file [${this.manifestPath}] to be arrays of strings`
);
}
}

/**
Expand Down Expand Up @@ -213,21 +152,13 @@ export function parseBundles(json: string) {
throw new Error('`bundles[]` must have an absolute path `outputDir` property');
}

const { manifestPath } = spec;
if (manifestPath !== undefined) {
if (!(typeof manifestPath === 'string' && Path.isAbsolute(manifestPath))) {
throw new Error('`bundles[]` must have an absolute path `manifestPath` property');
}
}

return new Bundle({
type,
id,
publicDirNames,
contextDir,
sourceRoot,
outputDir,
manifestPath,
});
}
);
Expand Down
5 changes: 0 additions & 5 deletions packages/kbn-optimizer/src/common/bundle_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface State {
optimizerCacheKey?: unknown;
cacheKey?: unknown;
moduleCount?: number;
workUnits?: number;
files?: string[];
bundleRefExportIds?: string[];
}
Expand Down Expand Up @@ -97,10 +96,6 @@ export class BundleCache {
return this.get().cacheKey;
}

public getWorkUnits() {
return this.get().workUnits;
}

public getOptimizerCacheKey() {
return this.get().optimizerCacheKey;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/kbn-optimizer/src/common/bundle_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ export class BundleRefs {

constructor(private readonly refs: BundleRef[]) {}

public forBundleIds(bundleIds: string[]) {
return this.refs.filter((r) => bundleIds.includes(r.bundleId));
}

public filterByExportIds(exportIds: string[]) {
return this.refs.filter((r) => exportIds.includes(r.exportId));
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
expect(foo.cache.getModuleCount()).toBe(6);
expect(foo.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/async_import.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/ext.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/index.ts,
Expand All @@ -161,17 +160,12 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
Array [
<absolute path>/node_modules/css-loader/package.json,
<absolute path>/node_modules/style-loader/package.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/kibana.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/legacy/_other_styles.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/legacy/styles.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/lib.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/legacy/ui/public/icon.svg,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/legacy/ui/public/styles/_globals_v7dark.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/legacy/ui/public/styles/_globals_v7light.scss,
<absolute path>/packages/kbn-optimizer/target/worker/entry_point_creator.js,
<absolute path>/packages/kbn-optimizer/target/worker/postcss.config.js,
<absolute path>/packages/kbn-ui-shared-deps/public_path_module_creator.js,
]
`);
Expand Down
12 changes: 3 additions & 9 deletions packages/kbn-optimizer/src/log_optimizer_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,12 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) {

if (event?.type === 'worker started') {
let moduleCount = 0;
let workUnits = 0;
for (const bundle of event.bundles) {
moduleCount += bundle.cache.getModuleCount() ?? NaN;
workUnits += bundle.cache.getWorkUnits() ?? NaN;
}

log.info(
`starting worker [${event.bundles.length} ${
event.bundles.length === 1 ? 'bundle' : 'bundles'
}]`
);
log.debug(`modules [${moduleCount}] work units [${workUnits}]`);
const mcString = isFinite(moduleCount) ? String(moduleCount) : '?';
const bcString = String(event.bundles.length);
log.info(`starting worker [${bcString} bundles, ${mcString} modules]`);
}

if (state.phase === 'reallocating') {
Expand Down
Loading

0 comments on commit c45fa3d

Please sign in to comment.