From ee876a24fa2d9daabeef448e02088f36f779637d Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 5 May 2021 17:13:32 +0100 Subject: [PATCH 1/2] chore(NA): moving @kbn/es into bazel --- .../monorepo-packages.asciidoc | 1 + package.json | 2 +- packages/BUILD.bazel | 1 + packages/kbn-es/.babelrc | 3 + packages/kbn-es/BUILD.bazel | 90 +++++++++++++++++++ packages/kbn-es/scripts/build.js | 60 ------------- packages/kbn-test/package.json | 1 - x-pack/package.json | 1 - yarn.lock | 10 ++- 9 files changed, 104 insertions(+), 65 deletions(-) create mode 100644 packages/kbn-es/.babelrc create mode 100644 packages/kbn-es/BUILD.bazel delete mode 100644 packages/kbn-es/scripts/build.js diff --git a/docs/developer/getting-started/monorepo-packages.asciidoc b/docs/developer/getting-started/monorepo-packages.asciidoc index 3fc006c0aae6b..fc7101bfdd85b 100644 --- a/docs/developer/getting-started/monorepo-packages.asciidoc +++ b/docs/developer/getting-started/monorepo-packages.asciidoc @@ -72,6 +72,7 @@ yarn kbn watch-bazel - @kbn/config - @kbn/config-schema - @kbn/dev-utils +- @kbn/es - @kbn/eslint-import-resolver-kibana - @kbn/eslint-plugin-eslint - @kbn/expect diff --git a/package.json b/package.json index af300b164ec18..12ed4c4699343 100644 --- a/package.json +++ b/package.json @@ -446,7 +446,7 @@ "@kbn/cli-dev-mode": "link:packages/kbn-cli-dev-mode", "@kbn/dev-utils": "link:bazel-bin/packages/kbn-dev-utils/npm_module", "@kbn/docs-utils": "link:packages/kbn-docs-utils", - "@kbn/es": "link:packages/kbn-es", + "@kbn/es": "link:bazel-bin/packages/kbn-es/npm_module", "@kbn/es-archiver": "link:packages/kbn-es-archiver", "@kbn/eslint-import-resolver-kibana": "link:bazel-bin/packages/kbn-eslint-import-resolver-kibana/npm_module", "@kbn/eslint-plugin-eslint": "link:bazel-bin/packages/kbn-eslint-plugin-eslint/npm_module", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 38374513502fb..eb0d895133c8c 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -14,6 +14,7 @@ filegroup( "//packages/kbn-config:build", "//packages/kbn-config-schema:build", "//packages/kbn-dev-utils:build", + "//packages/kbn-es:build", "//packages/kbn-eslint-import-resolver-kibana:build", "//packages/kbn-eslint-plugin-eslint:build", "//packages/kbn-expect:build", diff --git a/packages/kbn-es/.babelrc b/packages/kbn-es/.babelrc new file mode 100644 index 0000000000000..7da72d1779128 --- /dev/null +++ b/packages/kbn-es/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@kbn/babel-preset/node_preset"] +} diff --git a/packages/kbn-es/BUILD.bazel b/packages/kbn-es/BUILD.bazel new file mode 100644 index 0000000000000..bc8986e527fc5 --- /dev/null +++ b/packages/kbn-es/BUILD.bazel @@ -0,0 +1,90 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm") +load("@npm//@babel/cli:index.bzl", "babel") + +PKG_BASE_NAME = "kbn-es" +PKG_REQUIRE_NAME = "@kbn/es" + +SOURCE_FILES = glob( + [ + "src/**/*", + ], + exclude = [ + "**/*.test.*", + "**/integration_tests/**", + "**/__fixtures__/**", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", + "README.md", +] + +DEPS = [ + "//packages/kbn-babel-preset", + "@npm//@elastic/elasticsearch", + "@npm//abort-controller", + "@npm//chalk", + "@npm//dedent", + "@npm//del", + "@npm//execa", + "@npm//getopts", + "@npm//glob", + "@npm//node-fetch", + "@npm//simple-git", + "@npm//tar-fs", + "@npm//tree-kill", + "@npm//yauzl", + "@npm//zlib" +] + +babel( + name = "target", + data = [ + ":srcs", + ".babelrc", + ] + DEPS, + output_dir = True, + # the following arg paths includes $(execpath) as babel runs on the sandbox root + args = [ + "./%s/src" % package_name(), + "--config-file", + "./%s/.babelrc" % package_name(), + "--out-dir", + "$(@D)", + "--extensions", + ".ts,.js", + "--copy-files", + "--quiet" + ], +) + +js_library( + name = PKG_BASE_NAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = [":target"] + DEPS, + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [ + ":%s" % PKG_BASE_NAME, + ] +) + +filegroup( + name = "build", + srcs = [ + ":npm_module", + ], + visibility = ["//visibility:public"], +) diff --git a/packages/kbn-es/scripts/build.js b/packages/kbn-es/scripts/build.js deleted file mode 100644 index d8d8d0e69ee27..0000000000000 --- a/packages/kbn-es/scripts/build.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -const { resolve } = require('path'); - -const del = require('del'); -const { run, withProcRunner } = require('@kbn/dev-utils'); - -const ROOT_DIR = resolve(__dirname, '..'); -const BUILD_DIR = resolve(ROOT_DIR, 'target'); - -run( - async ({ log, flags }) => { - await withProcRunner(log, async (proc) => { - log.info('Deleting old output'); - await del(BUILD_DIR); - - const cwd = ROOT_DIR; - - log.info(`Starting babel${flags.watch ? ' in watch mode' : ''}`); - await proc.run(`babel`, { - cmd: 'babel', - args: [ - 'src', - '--no-babelrc', - '--presets', - require.resolve('@kbn/babel-preset/node_preset'), - '--extensions', - '.ts,.js', - '--copy-files', - '--out-dir', - BUILD_DIR, - ...(flags.watch ? ['--watch'] : ['--quiet']), - ...(!flags['source-maps'] || !!process.env.CODE_COVERAGE - ? [] - : ['--source-maps', 'inline']), - ], - wait: true, - cwd, - }); - - log.success('Complete'); - }); - }, - { - description: 'Simple build tool for @kbn/es package', - flags: { - boolean: ['watch', 'source-maps'], - help: ` - --watch Run in watch mode - --source-maps Include sourcemaps - `, - }, - } -); diff --git a/packages/kbn-test/package.json b/packages/kbn-test/package.json index 15d6ac90b2ebe..a668d8c1f8588 100644 --- a/packages/kbn-test/package.json +++ b/packages/kbn-test/package.json @@ -14,7 +14,6 @@ "devOnly": true }, "dependencies": { - "@kbn/es": "link:../kbn-es", "@kbn/i18n": "link:../kbn-i18n", "@kbn/optimizer": "link:../kbn-optimizer" } diff --git a/x-pack/package.json b/x-pack/package.json index 129c8d86adecc..91caae7a976e4 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -27,7 +27,6 @@ "yarn": "^1.21.1" }, "devDependencies": { - "@kbn/es": "link:../packages/kbn-es", "@kbn/plugin-helpers": "link:../packages/kbn-plugin-helpers", "@kbn/storybook": "link:../packages/kbn-storybook", "@kbn/test": "link:../packages/kbn-test" diff --git a/yarn.lock b/yarn.lock index 3afbfee0af875..076c3bd2871bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2635,7 +2635,7 @@ version "0.0.0" uid "" -"@kbn/es@link:packages/kbn-es": +"@kbn/es@link:bazel-bin/packages/kbn-es/npm_module": version "0.0.0" uid "" @@ -2692,11 +2692,17 @@ uid "" "@kbn/securitysolution-constants@link:bazel-bin/packages/kbn-securitysolution-constants/npm_module": -"@kbn/securitysolution-utils@link:bazel-bin/packages/kbn-securitysolution-utils/npm_module": + version "0.0.0" + uid "" + "@kbn/securitysolution-io-ts-utils@link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module": version "0.0.0" uid "" +"@kbn/securitysolution-utils@link:bazel-bin/packages/kbn-securitysolution-utils/npm_module": + version "0.0.0" + uid "" + "@kbn/server-http-tools@link:packages/kbn-server-http-tools": version "0.0.0" uid "" From ebb7c2100b59e77950e9158916e79c785756139e Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Wed, 5 May 2021 17:17:49 +0100 Subject: [PATCH 2/2] chore(NA): remove build scripts from pkg json --- packages/kbn-es/package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/kbn-es/package.json b/packages/kbn-es/package.json index e7356794b6113..ed3f29feaef98 100644 --- a/packages/kbn-es/package.json +++ b/packages/kbn-es/package.json @@ -6,10 +6,5 @@ "private": true, "kibana": { "devOnly": true - }, - "scripts": { - "build": "node scripts/build", - "kbn:bootstrap": "node scripts/build", - "kbn:watch": "node scripts/build --watch" } } \ No newline at end of file