fix(NA): only importing @kbn/dev-utils on serve if available in dev (#165357)

This is a follow up of https://github.com/elastic/kibana/pull/165311

Instead of duplicating the key we are only importing from
`@kbn/dev-utils` if the package is available. The serve file is also
load under dist mode where the devOnly dependencies are not availble and
as such we can't reliable load from them.
This commit is contained in:
Tiago Costa 2023-08-31 18:40:41 +01:00 committed by GitHub
parent 60f33febd6
commit 59231988c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,9 +18,6 @@ import { getConfigFromFiles } from '@kbn/config';
const DEV_MODE_PATH = '@kbn/cli-dev-mode';
const DEV_MODE_SUPPORTED = canRequire(DEV_MODE_PATH);
const KIBANA_DEV_SERVICE_ACCOUNT_TOKEN =
process.env.TEST_KIBANA_SERVICE_ACCOUNT_TOKEN ||
'AAEAAWVsYXN0aWMva2liYW5hL2tpYmFuYS1kZXY6VVVVVVVVTEstKiBaNA';
function canRequire(path) {
try {
@ -47,6 +44,23 @@ const getBootstrapScript = (isDev) => {
}
};
const setServerlessKibanaDevServiceAccountIfPossible = (set, opts) => {
if (!opts.dev || !opts.serverless || process.env.isDevCliChild === 'true') {
return;
}
const DEV_UTILS_PATH = '@kbn/dev-utils';
if (!canRequire(DEV_UTILS_PATH)) {
return;
}
// need dynamic require to exclude it from production build
// eslint-disable-next-line import/no-dynamic-require
const { kibanaDevServiceAccount } = require(DEV_UTILS_PATH);
set('elasticsearch.serviceAccountToken', kibanaDevServiceAccount.token);
};
function pathCollector() {
const paths = [];
return function (path) {
@ -72,7 +86,7 @@ export function applyConfigOverrides(rawConfig, opts, extraCliOptions) {
if (opts.dev) {
if (opts.serverless) {
set('elasticsearch.serviceAccountToken', KIBANA_DEV_SERVICE_ACCOUNT_TOKEN);
setServerlessKibanaDevServiceAccountIfPossible(set, opts);
}
if (!has('elasticsearch.serviceAccountToken') && opts.devCredentials !== false) {