Skip to content

Commit

Permalink
fix(NA): build external plugins with correct bazel artifacts output m…
Browse files Browse the repository at this point in the history
…ode (#159630)

Closes #159328 ,
#154325,
#157440

This PR fixes a problem in the plugin helpers tasks used to build
external plugins. After changes to transpile packages differently in the
past months a bug was introduced and external plugins were being built
with the wrong shared ui deps output mode causing development form
imports to be bundled and causing problems at page load time.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 7e067ec)
  • Loading branch information
mistic committed Jun 14, 2023
1 parent 6464bdb commit e154ef3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-bazel-runner/src/bazel_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-plugin-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-plugin-generator/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-plugin-helpers/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -160,6 +161,7 @@ export function runCli() {
};

await Tasks.initDev(context);
await Tasks.buildBazelPackages(context);
await Tasks.optimize(context);
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions packages/kbn-plugin-helpers/src/tasks/bazel_packages.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

export * from './bazel_packages';
export * from './clean';
export * from './create_archive';
export * from './optimize';
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@kbn/jest-serializers",
"@kbn/repo-packages",
"@kbn/stdio-dev-helpers",
"@kbn/bazel-runner",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit e154ef3

Please sign in to comment.