Skip to content

Commit

Permalink
Merge pull request #7 from spalger/pr/80463
Browse files Browse the repository at this point in the history
only run plugin discovery once to speed up circular dep detection
  • Loading branch information
mshustov authored Oct 15, 2020
2 parents dee6316 + b1c7468 commit c8d7ed8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
24 changes: 9 additions & 15 deletions src/dev/plugin_discovery/get_plugin_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/
import { KibanaPlatformPlugin } from '@kbn/dev-utils';
import { SearchOptions, findPlugins } from './find_plugins';

type AllOptions = SearchOptions & {
interface AllOptions {
id: string;
};
pluginMap: Map<string, KibanaPlatformPlugin>;
}

interface CircularRefsError {
from: string;
Expand All @@ -37,8 +37,8 @@ interface State {
errors: Map<string, SearchErrors>;
}

function traverse(pluginTree: Map<string, KibanaPlatformPlugin>, state: State, id: string) {
const plugin = pluginTree.get(id);
function traverse(pluginMap: Map<string, KibanaPlatformPlugin>, state: State, id: string) {
const plugin = pluginMap.get(id);
if (plugin === undefined) {
throw new Error(`Unknown plugin id: ${id}`);
}
Expand Down Expand Up @@ -69,27 +69,21 @@ function traverse(pluginTree: Map<string, KibanaPlatformPlugin>, state: State, i
...plugin.manifest.optionalPlugins,
...plugin.manifest.requiredBundles,
]).forEach((depId) => {
state.deps.add(pluginTree.get(depId)!);
traverse(pluginTree, state, depId);
state.deps.add(pluginMap.get(depId)!);
traverse(pluginMap, state, depId);
});

state.stack.pop();
}

export function getPluginDeps({
oss = false,
examples = false,
extraPluginScanDirs = [],
id,
}: AllOptions): State {
const pluginTree = findPlugins({ oss, examples, extraPluginScanDirs });
export function getPluginDeps({ pluginMap, id }: AllOptions): State {
const state: State = {
deps: new Set(),
errors: new Map(),
stack: [],
};

traverse(pluginTree, state, id);
traverse(pluginMap, state, id);

return state;
}
9 changes: 4 additions & 5 deletions src/dev/run_find_plugin_circular_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ run(
async ({ flags, log }) => {
const { examples = false, extraPluginScanDirs = [] } = flags as AllOptions;

const plugins = findPlugins({
const pluginMap = findPlugins({
oss: false,
examples,
extraPluginScanDirs,
});

const allErrors = new Map<string, SearchErrors>();
for (const pluginId of plugins.keys()) {
for (const pluginId of pluginMap.keys()) {
const { errors } = getPluginDeps({
oss: false,
examples,
extraPluginScanDirs,
pluginMap,
id: pluginId,
});

for (const [errorId, error] of errors) {
if (!allErrors.has(errorId)) {
allErrors.set(errorId, error);
Expand Down
8 changes: 6 additions & 2 deletions src/dev/run_find_plugins_without_ts_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Path from 'path';
import Fs from 'fs';
import { get } from 'lodash';
import { run } from '@kbn/dev-utils';
import { getPluginDeps } from './plugin_discovery';
import { getPluginDeps, findPlugins } from './plugin_discovery';

interface AllOptions {
id?: string;
Expand All @@ -37,10 +37,14 @@ run(
throw new Error('Plugin id required');
}

const result = getPluginDeps({
const pluginMap = findPlugins({
oss: false,
examples,
extraPluginScanDirs,
});

const result = getPluginDeps({
pluginMap,
id,
});

Expand Down

0 comments on commit c8d7ed8

Please sign in to comment.