[8.x] [dev] Fix bazel watch command (#203750) (#203851)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[dev] Fix bazel watch command
(#203750)](https://github.com/elastic/kibana/pull/203750)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Alex
Szabo","email":"alex.szabo@elastic.co"},"sourceCommit":{"committedDate":"2024-12-11T17:00:17Z","message":"[dev]
Fix bazel watch command (#203750)\n\n## Summary\r\nAfter
https://github.com/elastic/kibana/pull/193113 - the `yarn kbn\r\nwatch`
command fails with an error, because the required variable\r\nREACT_18
is not available.\r\n\r\nThis PR fixes that, by defining the variable
for
bazel.","sha":"785b333fb3eded2b8a46975b8cd0a065f25b7a21","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","v9.0.0","backport:prev-minor"],"title":"[dev]
Fix bazel watch
command","number":203750,"url":"https://github.com/elastic/kibana/pull/203750","mergeCommit":{"message":"[dev]
Fix bazel watch command (#203750)\n\n## Summary\r\nAfter
https://github.com/elastic/kibana/pull/193113 - the `yarn kbn\r\nwatch`
command fails with an error, because the required variable\r\nREACT_18
is not available.\r\n\r\nThis PR fixes that, by defining the variable
for
bazel.","sha":"785b333fb3eded2b8a46975b8cd0a065f25b7a21"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203750","number":203750,"mergeCommit":{"message":"[dev]
Fix bazel watch command (#203750)\n\n## Summary\r\nAfter
https://github.com/elastic/kibana/pull/193113 - the `yarn kbn\r\nwatch`
command fails with an error, because the required variable\r\nREACT_18
is not available.\r\n\r\nThis PR fixes that, by defining the variable
for bazel.","sha":"785b333fb3eded2b8a46975b8cd0a065f25b7a21"}}]}]
BACKPORT-->

Co-authored-by: Alex Szabo <alex.szabo@elastic.co>
This commit is contained in:
Kibana Machine 2024-12-12 05:54:50 +11:00 committed by GitHub
parent c8f3163a1c
commit 6b11919100
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View file

@ -27,6 +27,7 @@ export const command = {
async run({ args, log }) {
await Bazel.watch(log, {
offline: args.getBooleanValue('offline') ?? true,
reactVersion: process.env.REACT_18 ? '18' : '17',
});
},
};

View file

@ -83,7 +83,7 @@ async function runBazel(log, inputArgs, opts = undefined) {
/**
*
* @param {import('./log.mjs').Log} log
* @param {{ offline: boolean } | undefined} opts
* @param {{ offline: boolean, reactVersion?: string } | undefined} opts
*/
export async function watch(log, opts = undefined) {
const ibazel = (await getBazelRunner()).runIBazel;
@ -97,10 +97,12 @@ export async function watch(log, opts = undefined) {
...BAZEL_TARGETS,
'--show_result=1',
...(opts?.offline ? ['--config=offline'] : []),
`--define=REACT_18=${opts?.reactVersion === '18' ? 'true' : 'false'}`,
];
log.debug(`> ibazel ${args.join(' ')}`);
await ibazel(args, {
cwd: REPO_ROOT,
env: { ...process.env, REACT_18: opts?.reactVersion === '18' ? 'true' : 'false' },
logPrefix: Color.info('[ibazel]'),
onErrorExit(code, output) {
throwBazelError(log, 'ibazel', code, output);