Skip to content

Commit a41dbd5

Browse files
Merge branch 'master' into feat/logging-requests
2 parents 5d87516 + 9232a5a commit a41dbd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+11576
-9975
lines changed

.bazelignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
.idea
99
.teamcity
1010
.yarn-local-mirror
11-
bazel-cache
12-
bazel-dist
11+
/bazel
1312
build
1413
node_modules
1514
target

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Inspired on from https://raw.githubusercontent.com/bazelbuild/rules_nodejs/master/.bazelrc
1+
# Inspired by https://raw.githubusercontent.com/bazelbuild/rules_nodejs/master/.bazelrc
22
# Import shared settings first so we can override below
33
import %workspace%/.bazelrc.common
44

.bazelrc.common

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
#
66
# The full list of Bazel options: https://docs.bazel.build/versions/master/command-line-reference.html
77

8-
# Cache action outputs on disk so they persist across output_base and bazel shutdown (eg. changing branches)
9-
build --disk_cache=bazel-cache/disk-cache
8+
# Local Cache Settings
9+
## Avoid cache results from being corrupt when changing source during build
10+
common --experimental_guard_against_concurrent_changes
1011

11-
# Bazel repo cache settings
12-
build --repository_cache=bazel-cache/repository-cache
12+
## Cache action outputs on disk so they persist across output_base and bazel shutdown (eg. changing branches)
13+
build --disk_cache=~/.bazel-cache/disk-cache
14+
15+
## Bazel repo cache settings
16+
build --repository_cache=~/.bazel-cache/repository-cache
1317

1418
# Bazel will create symlinks from the workspace directory to output artifacts.
15-
# Build results will be placed in a directory called "bazel-dist/bin"
19+
# Build results will be placed in a directory called "bazel/bin"
1620
# This will still create a bazel-out symlink in
1721
# the project directory, which must be excluded from the
1822
# editor's search path.
19-
build --symlink_prefix=bazel-dist/
23+
build --symlink_prefix=bazel/
2024
# To disable the symlinks altogether (including bazel-out) we can use
2125
# build --symlink_prefix=/
2226
# however this makes it harder to find outputs.
@@ -37,9 +41,7 @@ common --color=yes
3741
build --show_task_finish
3842
build --noshow_progress
3943
build --noshow_loading_progress
40-
41-
## enforced default values
42-
build --show_result=1
44+
build --show_result=0
4345

4446
# Specifies desired output mode for running tests.
4547
# Valid values are
@@ -78,7 +80,8 @@ test:debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999
7880
# The node process will break before user code starts and wait for the debugger to connect.
7981
run:debug --define=VERBOSE_LOGS=1 -- --node_options=--inspect-brk
8082
# The following option will change the build output of certain rules such as terser and may not be desirable in all cases
81-
build:debug --compilation_mode=dbg
83+
# It will also output both the repo cache and action cache to a folder inside the repo
84+
build:debug --compilation_mode=dbg --show_result=1 --disk_cache=bazel/disk-cache --repository_cache=bazel/repository-cache
8285

8386
# Turn off legacy external runfiles
8487
# This prevents accidentally depending on this feature, which Bazel will remove.

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ snapshots.js
4646
/packages/kbn-monaco/src/painless/antlr
4747

4848
# Bazel
49-
/bazel-*
49+
/bazel

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ report.asciidoc
7878
.yarn-local-mirror
7979

8080
# Bazel
81-
/bazel-*
81+
/bazel
8282
/.bazelrc.user
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "../target/stdio"
3+
}

packages/kbn-pm/dist/index.js

Lines changed: 10107 additions & 9769 deletions
Large diffs are not rendered by default.

packages/kbn-pm/src/commands/clean.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@
66
* Public License, v 1.
77
*/
88

9+
import dedent from 'dedent';
910
import del from 'del';
1011
import ora from 'ora';
1112
import { join, relative } from 'path';
1213

14+
import { runBazel } from '../utils/bazel';
1315
import { isDirectory } from '../utils/fs';
1416
import { log } from '../utils/log';
1517
import { ICommand } from './';
1618

1719
export const CleanCommand: ICommand = {
18-
description: 'Remove the node_modules and target directories from all projects.',
20+
description: 'Deletes output directories, node_modules and resets internal caches.',
1921
name: 'clean',
2022

2123
async run(projects) {
24+
log.warning(dedent`
25+
This command is only necessary for the rare circumstance where you need to recover a consistent
26+
state when problems arise. If you need to run this command often, please let us know by
27+
filling out this form: https://ela.st/yarn-kbn-clean
28+
`);
29+
2230
const toDelete = [];
2331
for (const project of projects.values()) {
2432
if (await isDirectory(project.nodeModulesLocation)) {
@@ -44,6 +52,10 @@ export const CleanCommand: ICommand = {
4452
}
4553
}
4654

55+
// Runs Bazel soft clean
56+
await runBazel(['clean']);
57+
log.success('Soft cleaned bazel');
58+
4759
if (toDelete.length === 0) {
4860
log.success('Nothing to delete');
4961
} else {

packages/kbn-pm/src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export interface ICommand {
2424

2525
import { BootstrapCommand } from './bootstrap';
2626
import { CleanCommand } from './clean';
27+
import { ResetCommand } from './reset';
2728
import { RunCommand } from './run';
2829
import { WatchCommand } from './watch';
2930
import { Kibana } from '../utils/kibana';
3031

3132
export const commands: { [key: string]: ICommand } = {
3233
bootstrap: BootstrapCommand,
3334
clean: CleanCommand,
35+
reset: ResetCommand,
3436
run: RunCommand,
3537
watch: WatchCommand,
3638
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* and the Server Side Public License, v 1; you may not use this file except in
5+
* compliance with, at your election, the Elastic License or the Server Side
6+
* Public License, v 1.
7+
*/
8+
9+
import dedent from 'dedent';
10+
import del from 'del';
11+
import ora from 'ora';
12+
import { join, relative } from 'path';
13+
14+
import { getBazelDiskCacheFolder, getBazelRepositoryCacheFolder, runBazel } from '../utils/bazel';
15+
import { isDirectory } from '../utils/fs';
16+
import { log } from '../utils/log';
17+
import { ICommand } from './';
18+
19+
export const ResetCommand: ICommand = {
20+
description:
21+
'Deletes node_modules and output directories, resets internal and disk caches, and stops Bazel server',
22+
name: 'reset',
23+
24+
async run(projects) {
25+
log.warning(dedent`
26+
In most cases, 'yarn kbn clean' is all that should be needed to recover a consistent state when
27+
problems arise. If you need to use this command, please let us know, as it should not be necessary.
28+
`);
29+
30+
const toDelete = [];
31+
for (const project of projects.values()) {
32+
if (await isDirectory(project.nodeModulesLocation)) {
33+
toDelete.push({
34+
cwd: project.path,
35+
pattern: relative(project.path, project.nodeModulesLocation),
36+
});
37+
}
38+
39+
if (await isDirectory(project.targetLocation)) {
40+
toDelete.push({
41+
cwd: project.path,
42+
pattern: relative(project.path, project.targetLocation),
43+
});
44+
}
45+
46+
const { extraPatterns } = project.getCleanConfig();
47+
if (extraPatterns) {
48+
toDelete.push({
49+
cwd: project.path,
50+
pattern: extraPatterns,
51+
});
52+
}
53+
}
54+
55+
// Runs Bazel hard clean
56+
await runBazel(['clean', '--expunge']);
57+
log.success('Hard cleaned bazel');
58+
59+
// Deletes Bazel Cache Folders
60+
await del([await getBazelDiskCacheFolder(), await getBazelRepositoryCacheFolder()], {
61+
force: true,
62+
});
63+
log.success('Removed disk caches');
64+
65+
if (toDelete.length === 0) {
66+
return;
67+
}
68+
69+
/**
70+
* In order to avoid patterns like `/build` in packages from accidentally
71+
* impacting files outside the package we use `process.chdir()` to change
72+
* the cwd to the package and execute `del()` without the `force` option
73+
* so it will check that each file being deleted is within the package.
74+
*
75+
* `del()` does support a `cwd` option, but it's only for resolving the
76+
* patterns and does not impact the cwd check.
77+
*/
78+
const originalCwd = process.cwd();
79+
try {
80+
for (const { pattern, cwd } of toDelete) {
81+
process.chdir(cwd);
82+
const promise = del(pattern);
83+
84+
if (log.wouldLogLevel('info')) {
85+
ora.promise(promise, relative(originalCwd, join(cwd, String(pattern))));
86+
}
87+
88+
await promise;
89+
}
90+
} finally {
91+
process.chdir(originalCwd);
92+
}
93+
},
94+
};

0 commit comments

Comments
 (0)