Skip to content

Commit

Permalink
fix(NA): only importing @kbn/dev-utils on serve if available in dev (#…
Browse files Browse the repository at this point in the history
…165357)

This is a follow up of #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.
  • Loading branch information
mistic authored Aug 31, 2023
1 parent 60f33fe commit 5923198
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 5923198

Please sign in to comment.