-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kbn/pm] reduce responsibilities (#130592)
* [kbn/pm] reduce responsibilities * [CI] Auto-commit changed files from 'node scripts/generate packages_build_manifest' * [CI] Auto-commit changed files from 'yarn kbn run build -i @kbn/pm' Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
9430e41
commit 9ed9c02
Showing
38 changed files
with
31,108 additions
and
58,353 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
load("@npm//@bazel/typescript:index.bzl", "ts_config") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") | ||
|
||
PKG_DIRNAME = "kbn-bazel-runner" | ||
PKG_REQUIRE_NAME = "@kbn/bazel-runner" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"src/**/*.ts", | ||
], | ||
exclude = [ | ||
"**/*.test.*", | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
] | ||
|
||
# In this array place runtime dependencies, including other packages and NPM packages | ||
# which must be available for this code to run. | ||
# | ||
# To reference other packages use: | ||
# "//repo/relative/path/to/package" | ||
# eg. "//packages/kbn-utils" | ||
# | ||
# To reference a NPM package use: | ||
# "@npm//name-of-package" | ||
# eg. "@npm//lodash" | ||
RUNTIME_DEPS = [ | ||
"@npm//execa", | ||
"@npm//chalk", | ||
"@npm//rxjs", | ||
"//packages/kbn-dev-utils", | ||
] | ||
|
||
# In this array place dependencies necessary to build the types, which will include the | ||
# :npm_module_types target of other packages and packages from NPM, including @types/* | ||
# packages. | ||
# | ||
# To reference the types for another package use: | ||
# "//repo/relative/path/to/package:npm_module_types" | ||
# eg. "//packages/kbn-utils:npm_module_types" | ||
# | ||
# References to NPM packages work the same as RUNTIME_DEPS | ||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"@npm//execa", | ||
"@npm//chalk", | ||
"@npm//rxjs", | ||
"//packages/kbn-dev-utils:npm_module_types", | ||
] | ||
|
||
jsts_transpiler( | ||
name = "target_node", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
) | ||
|
||
ts_config( | ||
name = "tsconfig", | ||
src = "tsconfig.json", | ||
deps = [ | ||
"//:tsconfig.base.json", | ||
"//:tsconfig.bazel.json", | ||
], | ||
) | ||
|
||
ts_project( | ||
name = "tsc_types", | ||
args = ['--pretty'], | ||
srcs = SRCS, | ||
deps = TYPES_DEPS, | ||
declaration = True, | ||
emit_declaration_only = True, | ||
out_dir = "target_types", | ||
root_dir = "src", | ||
tsconfig = ":tsconfig", | ||
) | ||
|
||
js_library( | ||
name = PKG_DIRNAME, | ||
srcs = NPM_MODULE_EXTRA_FILES, | ||
deps = RUNTIME_DEPS + [":target_node"], | ||
package_name = PKG_REQUIRE_NAME, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_module", | ||
deps = [":" + PKG_DIRNAME], | ||
) | ||
|
||
filegroup( | ||
name = "build", | ||
srcs = [":npm_module"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm_types( | ||
name = "npm_module_types", | ||
srcs = SRCS, | ||
deps = [":tsc_types"], | ||
package_name = PKG_REQUIRE_NAME, | ||
tsconfig = ":tsconfig", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "build_types", | ||
srcs = [":npm_module_types"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/bazel-runner | ||
|
||
Helpers for running bazel commands, used everywhere we programatically run bazel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-bazel-runner'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@kbn/bazel-runner", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./target_node/index.js", | ||
"license": "SSPL-1.0 OR Elastic License 2.0", | ||
"kibana": { | ||
"devOnly": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 chalk from 'chalk'; | ||
import execa from 'execa'; | ||
import * as Rx from 'rxjs'; | ||
import { tap } from 'rxjs/operators'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { observeLines } from '@kbn/stdio-dev-helpers'; | ||
|
||
type BazelCommandRunner = 'bazel' | 'ibazel'; | ||
|
||
interface BazelRunOptions { | ||
log: ToolingLog; | ||
bazelArgs: string[]; | ||
offline?: boolean; | ||
execaOpts?: execa.Options; | ||
} | ||
|
||
async function runBazelCommandWithRunner(runner: BazelCommandRunner, options: BazelRunOptions) { | ||
const bazelProc = execa( | ||
runner, | ||
options.offline ? [...options.bazelArgs, '--config=offline'] : options.bazelArgs, | ||
{ | ||
...options.execaOpts, | ||
stdio: 'pipe', | ||
preferLocal: true, | ||
} | ||
); | ||
|
||
await Promise.all([ | ||
// Bazel outputs machine readable output into stdout and human readable output goes to stderr. | ||
// Therefore we need to get both. In order to get errors we need to parse the actual text line | ||
Rx.lastValueFrom( | ||
Rx.merge( | ||
observeLines(bazelProc.stdout!).pipe( | ||
tap((line) => options.log.info(`${chalk.cyan(`[${runner}]`)} ${line}`)) | ||
), | ||
observeLines(bazelProc.stderr!).pipe( | ||
tap((line) => options.log.info(`${chalk.cyan(`[${runner}]`)} ${line}`)) | ||
) | ||
).pipe(Rx.defaultIfEmpty(undefined)) | ||
), | ||
|
||
// Wait for process and logs to finish, unsubscribing in the end | ||
bazelProc.catch(() => { | ||
options.log.error( | ||
'HINT: If experiencing problems with node_modules try `yarn kbn bootstrap --force-install` or as last resort `yarn kbn reset && yarn kbn bootstrap`' | ||
); | ||
|
||
throw new Error(`The bazel command that was running failed to complete.`); | ||
}), | ||
]); | ||
} | ||
|
||
export async function runBazel(options: BazelRunOptions) { | ||
await runBazelCommandWithRunner('bazel', options); | ||
} | ||
|
||
export async function runIBazel(options: BazelRunOptions) { | ||
await runBazelCommandWithRunner('ibazel', { | ||
...options, | ||
execaOpts: { | ||
...options.execaOpts, | ||
env: { | ||
...options.execaOpts?.env, | ||
IBAZEL_USE_LEGACY_WATCHER: '0', | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../tsconfig.bazel.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "target_types", | ||
"rootDir": "src", | ||
"stripInternal": false, | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.