Skip to content

Commit

Permalink
SKA: Relocate Script v7.1 (elastic#206233)
Browse files Browse the repository at this point in the history
## Summary

* Fix an issue with the `--list` command failing the 1st run.
* Allow passing in no filters, and relocate "incorrect" modules (aka
modules that are not in the correct folder) in that case.
  • Loading branch information
gsoldevila authored Jan 10, 2025
1 parent 82721b0 commit 3b42b80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
49 changes: 20 additions & 29 deletions packages/kbn-relocate/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,53 @@ import { sortBy } from 'lodash';
import type { ToolingLog } from '@kbn/tooling-log';
import { getPackages } from '@kbn/repo-packages';
import { REPO_ROOT } from '@kbn/repo-info';
import { join } from 'path';
import type { Package } from './types';
import { BASE_FOLDER, EXCLUDED_MODULES, KIBANA_FOLDER } from './constants';
import { calculateModuleTargetFolder, isInTargetFolder } from './utils/relocate';
import { createModuleTable } from './utils/logging';
import { safeExec } from './utils/exec';

export const listModules = async (listFlag: string, log: ToolingLog) => {
// get all modules
const modules = getPackages(REPO_ROOT);
const devOnly: Package[] = [];
const test: Package[] = [];
const examples: Package[] = [];
const uncategorised: Package[] = [];
const incorrect: Package[] = [];
const correct: Package[] = [];

// get all modules
await safeExec('yarn kbn bootstrap');
const modules = getPackages(REPO_ROOT);

// find modules selected by user filters
sortBy(modules, 'directory')
// explicit exclusions
.filter(({ id }) => !EXCLUDED_MODULES.includes(id))
.forEach((module) => {
const directory = module.directory.startsWith(BASE_FOLDER)
? module.directory
: join(BASE_FOLDER, module.directory);

if (module.isDevOnly()) {
devOnly.push(module);
return;
}

if (
module.directory.includes(`/${KIBANA_FOLDER}/test/`) ||
module.directory.includes(`/${KIBANA_FOLDER}/x-pack/test/`)
} else if (
directory.includes(`/${KIBANA_FOLDER}/test/`) ||
directory.includes(`/${KIBANA_FOLDER}/x-pack/test/`)
) {
test.push(module);
return;
}

if (
module.directory.includes(`/${KIBANA_FOLDER}/examples/`) ||
module.directory.includes(`/${KIBANA_FOLDER}/x-pack/examples/`)
} else if (
directory.includes(`/${KIBANA_FOLDER}/examples/`) ||
directory.includes(`/${KIBANA_FOLDER}/x-pack/examples/`)
) {
examples.push(module);
return;
}

if (!module.group || module.group === 'common' || !module.visibility) {
// log.warning(`The module ${module.id} does not specify 'group' or 'visibility'. Skipping`);
} else if (!module.group || module.group === 'common' || !module.visibility) {
uncategorised.push(module);
return;
}

if (!isInTargetFolder(module)) {
} else if (!isInTargetFolder(module)) {
incorrect.push(module);
// log.warning(dedent`The module ${module.id} is not in the correct folder:
// - ${module.directory}
// - ${calculateModuleTargetFolder(module)}`);

return;
} else {
correct.push(module);
}
correct.push(module);
});

if (listFlag === 'all') {
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-relocate/relocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface RelocateModulesParams {
const findModules = ({ teams, paths, included, excluded }: FindModulesParams, log: ToolingLog) => {
// get all modules
const modules = getPackages(REPO_ROOT);
const moduleFilters = teams.length > 0 || paths.length > 0 || included.length > 0;

// find modules selected by user filters
return (
Expand All @@ -121,6 +122,7 @@ const findModules = ({ teams, paths, included, excluded }: FindModulesParams, lo
// the module is under the umbrella specified by the user
.filter(
(module) =>
!moduleFilters ||
included.includes(module.id) ||
teams.some((team) => belongsTo(module, team)) ||
paths.some((path) => module.directory.includes(path))
Expand Down

0 comments on commit 3b42b80

Please sign in to comment.