chore(NA): adds @kbn/whereis-pkg-cli to quickly find a pkg location (#148696)

This PR ads a new cli package to allow us to search for package
locations by providing their IDs. I see this as useful as we start
adding more and more packages across different locations.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tiago Costa 2023-01-14 00:45:24 +00:00 committed by GitHub
parent 99013bdab8
commit 548da835a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 120 additions and 2 deletions

1
.github/CODEOWNERS vendored
View file

@ -1025,6 +1025,7 @@ packages/kbn-utility-types @elastic/kibana-core
packages/kbn-utility-types-jest @elastic/kibana-operations
packages/kbn-utils @elastic/kibana-operations
packages/kbn-web-worker-stub @elastic/kibana-operations
packages/kbn-whereis-pkg-cli @elastic/kibana-operations
packages/kbn-yarn-lock-validator @elastic/kibana-operations
packages/shared-ux/avatar/solution @elastic/kibana-global-experience
packages/shared-ux/avatar/user_profile/impl @elastic/kibana-global-experience

View file

@ -821,6 +821,7 @@
"@kbn/ts-projects": "link:packages/kbn-ts-projects",
"@kbn/ts-type-check-cli": "link:packages/kbn-ts-type-check-cli",
"@kbn/web-worker-stub": "link:packages/kbn-web-worker-stub",
"@kbn/whereis-pkg-cli": "link:packages/kbn-whereis-pkg-cli",
"@kbn/yarn-lock-validator": "link:packages/kbn-yarn-lock-validator",
"@loaders.gl/polyfills": "^2.3.5",
"@mapbox/vector-tile": "1.3.1",

View file

@ -16,7 +16,7 @@
/** @typedef {import('./modern/types').PluginTypeInfo} PluginTypeInfo */
/** @typedef {Map<string, string>} PackageMap */
const { getPackages, findPackageInfoForPath } = require('./modern/get_packages');
const { getPackages, findPackageInfoForPath, getPkgMap } = require('./modern/get_packages');
const {
parsePackageManifest,
readPackageManifest,
@ -38,6 +38,7 @@ module.exports = {
readPackageMap,
getPackages,
findPackageInfoForPath,
getPkgMap,
parsePackageManifest,
readPackageManifest,
validatePackageManifest,

View file

@ -95,4 +95,4 @@ function findPackageInfoForPath(repoRoot, path) {
}
}
module.exports = { getPackages, findPackageInfoForPath };
module.exports = { getPackages, findPackageInfoForPath, getPkgMap };

View file

@ -0,0 +1,3 @@
# @kbn/whereis-pkg-cli
CLI for finding package locations by providing their IDs.

View file

@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-whereis-pkg-cli'],
};

View file

@ -0,0 +1,6 @@
{
"type": "shared-common",
"id": "@kbn/whereis-pkg-cli",
"owner": "@elastic/kibana-operations",
"devOnly": true
}

View file

@ -0,0 +1,7 @@
{
"name": "@kbn/whereis-pkg-cli",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./run_whereis_pkg_cli"
}

View file

@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { run } from '@kbn/dev-cli-runner';
import { createFailError } from '@kbn/dev-cli-errors';
import { getPkgMap } from '@kbn/repo-packages';
import type { ToolingLog } from '@kbn/tooling-log';
const locatePkgsByID = function (inputFilters: string[], log: ToolingLog) {
const packagesMap = getPkgMap();
let missingPkgsCount = 0;
inputFilters.forEach((filterInput) => {
const pkgId = filterInput.toLowerCase();
if (packagesMap.has(pkgId)) {
const pkgLocation = packagesMap.get(pkgId);
log.success(`pkg ${pkgId} location => ${pkgLocation}`);
} else {
missingPkgsCount++;
// fail
log.error(`pkg ${pkgId} NOT FOUND`);
}
});
return missingPkgsCount;
};
run(
async ({ log, flagsReader }) => {
const missingPackagesCount = locatePkgsByID(flagsReader.getPositionals(), log);
if (!missingPackagesCount) {
log.success('All packages were found successfully');
} else {
throw createFailError('see above errors');
}
},
{
usage: `node scripts/whereis_pkg [...packages]`,
description: 'Logs where a given package(s) ID is located in the repository',
}
);

View file

@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/dev-cli-runner",
"@kbn/dev-cli-errors",
"@kbn/repo-packages",
"@kbn/tooling-log"
]
}

10
scripts/whereis_pkg.js Normal file
View file

@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
require('../src/setup_node_env');
require('@kbn/whereis-pkg-cli');

View file

@ -1296,6 +1296,8 @@
"@kbn/watcher-plugin/*": ["x-pack/plugins/watcher/*"],
"@kbn/web-worker-stub": ["packages/kbn-web-worker-stub"],
"@kbn/web-worker-stub/*": ["packages/kbn-web-worker-stub/*"],
"@kbn/whereis-pkg-cli": ["packages/kbn-whereis-pkg-cli"],
"@kbn/whereis-pkg-cli/*": ["packages/kbn-whereis-pkg-cli/*"],
"@kbn/yarn-lock-validator": ["packages/kbn-yarn-lock-validator"],
"@kbn/yarn-lock-validator/*": ["packages/kbn-yarn-lock-validator/*"],
// END AUTOMATED PACKAGE LISTING

View file

@ -4309,6 +4309,10 @@
version "0.0.0"
uid ""
"@kbn/whereis-pkg-cli@link:packages/kbn-whereis-pkg-cli":
version "0.0.0"
uid ""
"@kbn/yarn-lock-validator@link:packages/kbn-yarn-lock-validator":
version "0.0.0"
uid ""