[8.8] fix(NA): build external plugins with correct bazel artifacts output mode (#159630) (#159761)

# Backport

This will backport the following commits from `main` to `8.8`:
- [fix(NA): build external plugins with correct bazel artifacts output
mode (#159630)](https://github.com/elastic/kibana/pull/159630)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tiago
Costa","email":"tiago.costa@elastic.co"},"sourceCommit":{"committedDate":"2023-06-14T23:43:05Z","message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses https://github.com/elastic/kibana/issues/159328
,\r\nhttps://github.com/elastic/kibana/issues/154325,\r\nhttps://github.com/elastic/kibana/issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["chore","Team:Operations","release_note:skip","auto-backport","v8.7.2","v8.9.0","v8.8.2"],"number":159630,"url":"https://github.com/elastic/kibana/pull/159630","mergeCommit":{"message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses https://github.com/elastic/kibana/issues/159328
,\r\nhttps://github.com/elastic/kibana/issues/154325,\r\nhttps://github.com/elastic/kibana/issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7"}},"sourceBranch":"main","suggestedTargetBranches":["8.7","8.8"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159630","number":159630,"mergeCommit":{"message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses https://github.com/elastic/kibana/issues/159328
,\r\nhttps://github.com/elastic/kibana/issues/154325,\r\nhttps://github.com/elastic/kibana/issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
This commit is contained in:
Kibana Machine 2023-06-14 22:17:48 -04:00 committed by GitHub
parent 2088c4d425
commit 2a02b2aa78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 3 deletions

View file

@ -112,7 +112,7 @@ async function runBazelRunner(runner, args, options = undefined) {
]),
]);
if (process.env.CI) {
if (process.env.CI && !options?.quiet) {
// on CI it's useful to reduce the logging output, but we still want to see basic info from Bazel so continue to log the INFO: lines from bazel
for (const line of buffer) {
if (line.startsWith('INFO:') && !line.startsWith('INFO: From ')) {

View file

@ -53,9 +53,9 @@ Generated plugins receive a handful of scripts that can be used during developme
> ***NOTE:*** The following scripts should be run from the generated plugin root folder.
- `yarn kbn bootstrap`
- `yarn bootstrap`
Install dependencies and crosslink Kibana and all projects/plugins.
Install dependencies both on Kibana and in your plugin.
> ***IMPORTANT:*** Use this script instead of `yarn` to install dependencies when switching branches, and re-run it whenever your dependencies change.

View file

@ -3,6 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"bootstrap": "yarn kbn bootstrap && yarn install",
"build": "yarn plugin-helpers build",
"dev": "yarn plugin-helpers dev",
"plugin-helpers": "node ../../scripts/plugin_helpers",

View file

@ -85,6 +85,7 @@ export function runCli() {
};
await Tasks.initTargets(context);
await Tasks.buildBazelPackages(context);
await Tasks.optimize(context);
await Tasks.writePublicAssets(context);
await Tasks.writeServerFiles(context);
@ -160,6 +161,7 @@ export function runCli() {
};
await Tasks.initDev(context);
await Tasks.buildBazelPackages(context);
await Tasks.optimize(context);
},
})

View file

@ -68,6 +68,8 @@ it('builds a generated plugin into a viable archive', async () => {
expect(filterLogs(buildProc.all)).toMatchInlineSnapshot(`
" info deleting the build and target directories
info run bazel and build required artifacts for the optimizer
succ bazel run successfully and artifacts were created
info running @kbn/optimizer
succ browser bundle created at plugins/foo_test_plugin/build/kibana/fooTestPlugin/target/public
info stopping @kbn/optimizer

View file

@ -0,0 +1,35 @@
/*
* 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 { runBazel } from '@kbn/bazel-runner';
import { TaskContext } from '../task_context';
export async function buildBazelPackages({ log, dist }: TaskContext) {
log.info('run bazel and build required artifacts for the optimizer');
try {
await runBazel(
[
'build',
'//packages/kbn-ui-shared-deps-npm:shared_built_assets',
'//packages/kbn-ui-shared-deps-src:shared_built_assets',
'//packages/kbn-monaco:target_workers',
'--show_result=1',
].concat(dist ? [`--define=dist=true`] : []),
{
logPrefix: ' │ ',
quiet: true,
}
);
log.success('bazel run successfully and artifacts were created');
} catch (e) {
log.error(`bazel run failed: ${e}`);
process.exit(1);
}
}

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
export * from './bazel_packages';
export * from './clean';
export * from './create_archive';
export * from './optimize';

View file

@ -20,6 +20,7 @@
"@kbn/jest-serializers",
"@kbn/repo-packages",
"@kbn/stdio-dev-helpers",
"@kbn/bazel-runner",
],
"exclude": [
"target/**/*",