Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spencer's changes #15

Closed
12 changes: 9 additions & 3 deletions kbn_pm/src/commands/bootstrap/bootstrap_command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { haveNodeModulesBeenManuallyDeleted, removeYarnIntegrityFileIfExists } f
import { setupRemoteCache } from './setup_remote_cache.mjs';
import { regenerateSyntheticPackageMap } from './regenerate_synthetic_package_map.mjs';
import { sortPackageJson } from './sort_package_json.mjs';
import { packagesDiscovery } from './packages.mjs';
import { pluginDiscovery } from './plugins.mjs';
import { regenerateBaseTsconfig } from './regenerate_base_tsconfig.mjs';

Expand Down Expand Up @@ -92,6 +93,14 @@ export const command = {
regenerateSyntheticPackageMap(plugins);
});

const packages = await time('packages discovery', async () => {
return await packagesDiscovery();
});

await time('regenerate tsconfig.base.json', async () => {
regenerateBaseTsconfig(plugins, packages);
});

// build packages
await time('build packages', async () => {
await Bazel.buildPackages(log, { offline, quiet });
Expand All @@ -100,9 +109,6 @@ export const command = {
await time('sort package json', async () => {
await sortPackageJson();
});
await time('regenerate tsconfig.base.json', async () => {
regenerateBaseTsconfig(plugins);
});

if (validate) {
// now that packages are built we can import `@kbn/yarn-lock-validator`
Expand Down
26 changes: 26 additions & 0 deletions kbn_pm/src/commands/bootstrap/packages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { REPO_ROOT } from '../../lib/paths.mjs';

/** @type {string} */
const KBN_BAZEL_PACKAGES_SRC = '../../../../packages/kbn-bazel-packages/src/index.js';

/**
* @returns {Promise<import('@kbn/bazel-packages').BazelPackage[]>}
*/
export async function packagesDiscovery() {
/* eslint-disable no-unsanitized/method */
/** @type {import('@kbn/bazel-packages')} */
const { discoverBazelPackages } = await import(
KBN_BAZEL_PACKAGES_SRC
);
/* eslint-enable no-unsanitized/method */

return await discoverBazelPackages(REPO_ROOT);
}
18 changes: 15 additions & 3 deletions kbn_pm/src/commands/bootstrap/regenerate_base_tsconfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ import { normalizePath } from './normalize_path.mjs';

/**
* @param {import('@kbn/plugin-discovery').KibanaPlatformPlugin[]} plugins
* @param {import('@kbn/bazel-packages').BazelPackage[]} packages
*/
export function regenerateBaseTsconfig(plugins) {
export function regenerateBaseTsconfig(plugins, packages) {
const tsconfigPath = Path.resolve(REPO_ROOT, 'tsconfig.base.json');
const lines = Fs.readFileSync(tsconfigPath, 'utf-8').split('\n');

const packageMap = plugins
const packagesMap = packages
.slice()
.sort((a, b) => a.normalizedRepoRelativeDir.localeCompare(b.normalizedRepoRelativeDir))
.flatMap((p) => {
const id = p.pkg.name
const path = p.normalizedRepoRelativeDir
// return [` "${id}": ["${path}"],`, ` "${id}/*": ["${path}/*"],`];
// return [` "${id}": ["node_modules/@types/${id.replace("@", "").replace("/", "__")}", "bazel-out/darwin-fastbuild/bin/${path}/target_types", "bazel-out/darwin_arm64-fastbuild/bin/${path}/target_types", "bazel-out/k8-fastbuild/bin/${path}/target_types", "bazel-out/x64_windows-fastbuild/bin/${path}/target_types"],`,];
return [` "${id}": ["bazel-out/darwin_arm64-fastbuild/bin/${path}/target_types"],`,];
});

const pluginsMap = plugins
.slice()
.sort((a, b) => a.manifestPath.localeCompare(b.manifestPath))
.flatMap((p) => {
Expand All @@ -34,6 +46,6 @@ export function regenerateBaseTsconfig(plugins) {

Fs.writeFileSync(
tsconfigPath,
[...lines.slice(0, start + 1), ...packageMap, ...lines.slice(end)].join('\n')
[...lines.slice(0, start + 1), ...packagesMap, ...pluginsMap, ...lines.slice(end)].join('\n')
);
}
262 changes: 1 addition & 261 deletions package.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ filegroup(
"//packages/kbn-optimizer-webpack-helpers:build",
"//packages/kbn-optimizer:build",
"//packages/kbn-performance-testing-dataset-extractor:build",
"//packages/kbn-plugin-discovery-common-types:build",
"//packages/kbn-plugin-discovery:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-plugin-helpers:build",
Expand Down Expand Up @@ -454,6 +455,7 @@ filegroup(
"//packages/kbn-optimizer-webpack-helpers:build_types",
"//packages/kbn-optimizer:build_types",
"//packages/kbn-performance-testing-dataset-extractor:build_types",
"//packages/kbn-plugin-discovery-common-types:build_types",
"//packages/kbn-plugin-discovery:build_types",
"//packages/kbn-plugin-generator:build_types",
"//packages/kbn-plugin-helpers:build_types",
Expand Down Expand Up @@ -539,6 +541,5 @@ filegroup(
name = "build",
srcs = [
":build_pkg_code",
":build_pkg_types"
],
)
37 changes: 0 additions & 37 deletions packages/analytics/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ jsts_transpiler(
web = True,
)

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
Expand All @@ -115,18 +93,3 @@ filegroup(
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"],
)
37 changes: 0 additions & 37 deletions packages/analytics/shippers/elastic_v3/browser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,6 @@ jsts_transpiler(
root_input_dir = "src",
)

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
Expand All @@ -114,18 +92,3 @@ filegroup(
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"],
)
37 changes: 0 additions & 37 deletions packages/analytics/shippers/elastic_v3/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,6 @@ jsts_transpiler(
web = True,
)

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
Expand All @@ -110,18 +88,3 @@ filegroup(
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"],
)
37 changes: 0 additions & 37 deletions packages/analytics/shippers/elastic_v3/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ jsts_transpiler(
root_input_dir = "src",
)

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
Expand All @@ -108,18 +86,3 @@ filegroup(
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"],
)
37 changes: 0 additions & 37 deletions packages/analytics/shippers/fullstory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ jsts_transpiler(
web = True,
)

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
Expand All @@ -111,18 +89,3 @@ filegroup(
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"],
)
Loading