diff --git a/BUILD.bazel b/BUILD.bazel index 4502daeaacb59..1f6e3030e5d0c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -3,6 +3,7 @@ exports_files( [ "tsconfig.base.json", + "tsconfig.browser.json", "tsconfig.json", "package.json" ], diff --git a/docs/developer/getting-started/monorepo-packages.asciidoc b/docs/developer/getting-started/monorepo-packages.asciidoc index 969226df53cb7..02f96f304ec1e 100644 --- a/docs/developer/getting-started/monorepo-packages.asciidoc +++ b/docs/developer/getting-started/monorepo-packages.asciidoc @@ -64,6 +64,7 @@ yarn kbn watch-bazel - @elastic/datemath - @elastic/eslint-config-kibana - @elastic/safer-lodash-set +- @kbn/analytics - @kbn/apm-config-loader - @kbn/apm-utils - @kbn/babel-code-parser diff --git a/package.json b/package.json index 471ba0d219ff7..23b5bbf0185b9 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "@hapi/podium": "^4.1.1", "@hapi/wreck": "^17.1.0", "@kbn/ace": "link:packages/kbn-ace", - "@kbn/analytics": "link:packages/kbn-analytics", + "@kbn/analytics": "link:bazel-bin/packages/kbn-analytics/npm_module", "@kbn/apm-config-loader": "link:bazel-bin/packages/kbn-apm-config-loader/npm_module", "@kbn/apm-utils": "link:bazel-bin/packages/kbn-apm-utils/npm_module", "@kbn/config": "link:packages/kbn-config", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 39285fb9ea66a..eb93a1055e7b7 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -6,6 +6,7 @@ filegroup( "//packages/elastic-datemath:build", "//packages/elastic-eslint-config-kibana:build", "//packages/elastic-safer-lodash-set:build", + "//packages/kbn-analytics:build", "//packages/kbn-apm-config-loader:build", "//packages/kbn-apm-utils:build", "//packages/kbn-babel-code-parser:build", diff --git a/packages/kbn-analytics/BUILD.bazel b/packages/kbn-analytics/BUILD.bazel new file mode 100644 index 0000000000000..a5506598baeac --- /dev/null +++ b/packages/kbn-analytics/BUILD.bazel @@ -0,0 +1,124 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm") + +PKG_BASE_NAME = "kbn-analytics" +PKG_REQUIRE_NAME = "@kbn/analytics" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json" +] + +SRC_DEPS = [ + "@npm//moment-timezone", + "@npm//tslib", +] + +TYPES_DEPS = [ + "@npm//@types/moment-timezone", + "@npm//@types/node", +] + +DEPS = SRC_DEPS + TYPES_DEPS + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + ], +) + +ts_config( + name = "tsconfig_browser", + src = "tsconfig.browser.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.browser.json", + ], +) + +ts_project( + name = "tsc", + args = ['--pretty'], + srcs = SRCS, + deps = DEPS, + declaration = True, + declaration_dir = "types", + declaration_map = True, + incremental = True, + out_dir = "node", + source_map = True, + root_dir = "src", + tsconfig = ":tsconfig", +) + +ts_project( + name = "tsc_browser", + args = ['--pretty'], + srcs = SRCS, + deps = DEPS, + declaration = False, + incremental = True, + out_dir = "web", + source_map = True, + root_dir = "src", + tsconfig = ":tsconfig_browser", +) + +filegroup( + name = "tsc_types", + srcs = [":tsc"], + output_group = "types", +) + +filegroup( + name = "target_files", + srcs = [ + ":tsc", + ":tsc_browser", + ":tsc_types", + ], +) + +pkg_npm( + name = "target", + deps = [ + ":target_files", + ], +) + +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-analytics/babel.config.js b/packages/kbn-analytics/babel.config.js deleted file mode 100644 index cdbc4feb60176..0000000000000 --- a/packages/kbn-analytics/babel.config.js +++ /dev/null @@ -1,21 +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. - */ - -// We can't use common Kibana presets here because of babel versions incompatibility -module.exports = { - plugins: ['@babel/plugin-proposal-class-properties'], - env: { - web: { - presets: ['@kbn/babel-preset/webpack_preset'], - }, - node: { - presets: ['@kbn/babel-preset/node_preset'], - }, - }, - ignore: ['**/*.test.ts', '**/*.test.tsx'], -}; diff --git a/packages/kbn-analytics/package.json b/packages/kbn-analytics/package.json index 2195de578081e..726b62e1c61b8 100644 --- a/packages/kbn-analytics/package.json +++ b/packages/kbn-analytics/package.json @@ -4,13 +4,8 @@ "version": "1.0.0", "description": "Kibana Analytics tool", "main": "target/node/index.js", - "browser": "target/web/index.js", "types": "target/types/index.d.ts", + "browser": "target/web/index.js", "author": "Ahmad Bamieh ", - "license": "SSPL-1.0 OR Elastic License 2.0", - "scripts": { - "build": "node scripts/build", - "kbn:bootstrap": "node scripts/build --source-maps", - "kbn:watch": "node scripts/build --source-maps --watch" - } + "license": "SSPL-1.0 OR Elastic License 2.0" } \ No newline at end of file diff --git a/packages/kbn-analytics/scripts/build.js b/packages/kbn-analytics/scripts/build.js deleted file mode 100644 index b9677d6a07a88..0000000000000 --- a/packages/kbn-analytics/scripts/build.js +++ /dev/null @@ -1,85 +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 supportsColor = require('supports-color'); -const { run, withProcRunner } = require('@kbn/dev-utils'); - -const ROOT_DIR = resolve(__dirname, '..'); -const BUILD_DIR = resolve(ROOT_DIR, 'target'); - -const padRight = (width, str) => - str.length >= width ? str : `${str}${' '.repeat(width - str.length)}`; - -run( - async ({ log, flags }) => { - await withProcRunner(log, async (proc) => { - log.info('Deleting old output'); - await del(BUILD_DIR); - - const cwd = ROOT_DIR; - const env = { ...process.env }; - if (supportsColor.stdout) { - env.FORCE_COLOR = 'true'; - } - - log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`); - await Promise.all([ - ...['web', 'node'].map((subTask) => - proc.run(padRight(10, `babel:${subTask}`), { - cmd: 'babel', - args: [ - 'src', - '--config-file', - require.resolve('../babel.config.js'), - '--out-dir', - resolve(BUILD_DIR, subTask), - '--extensions', - '.ts,.js,.tsx', - ...(flags.watch ? ['--watch'] : ['--quiet']), - ...(!flags['source-maps'] || !!process.env.CODE_COVERAGE - ? [] - : ['--source-maps', 'inline']), - ], - wait: true, - env: { - ...env, - BABEL_ENV: subTask, - }, - cwd, - }) - ), - - proc.run(padRight(10, 'tsc'), { - cmd: 'tsc', - args: [ - ...(flags.watch ? ['--watch', '--preserveWatchOutput', 'true'] : []), - ...(flags['source-maps'] ? ['--declarationMap', 'true'] : []), - ], - wait: true, - env, - cwd, - }), - ]); - - log.success('Complete'); - }); - }, - { - description: 'Simple build tool for @kbn/analytics package', - flags: { - boolean: ['watch', 'source-maps'], - help: ` - --watch Run in watch mode - --source-maps Include sourcemaps - `, - }, - } -); diff --git a/packages/kbn-analytics/tsconfig.browser.json b/packages/kbn-analytics/tsconfig.browser.json new file mode 100644 index 0000000000000..12f70b77008e7 --- /dev/null +++ b/packages/kbn-analytics/tsconfig.browser.json @@ -0,0 +1,18 @@ +{ + "extends": "../../tsconfig.browser.json", + "compilerOptions": { + "incremental": true, + "outDir": "./target/web", + "stripInternal": true, + "declaration": false, + "isolatedModules": true, + "sourceMap": true, + "sourceRoot": "../../../../../packages/kbn-analytics/src", + "types": [ + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/kbn-analytics/tsconfig.json b/packages/kbn-analytics/tsconfig.json index 80a2255d71805..165a8b695db57 100644 --- a/packages/kbn-analytics/tsconfig.json +++ b/packages/kbn-analytics/tsconfig.json @@ -1,10 +1,10 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "incremental": false, - "outDir": "./target/types", + "incremental": true, + "declarationDir": "./target/types", + "outDir": "./target/node", "stripInternal": true, - "emitDeclarationOnly": true, "declaration": true, "declarationMap": true, "isolatedModules": true, diff --git a/packages/kbn-ui-shared-deps/package.json b/packages/kbn-ui-shared-deps/package.json index 8b08f64ba0f62..54d983bf1bf44 100644 --- a/packages/kbn-ui-shared-deps/package.json +++ b/packages/kbn-ui-shared-deps/package.json @@ -9,7 +9,6 @@ "kbn:watch": "node scripts/build --dev --watch" }, "dependencies": { - "@kbn/analytics": "link:../kbn-analytics", "@kbn/i18n": "link:../kbn-i18n", "@kbn/monaco": "link:../kbn-monaco" } diff --git a/yarn.lock b/yarn.lock index 3db65a2ce4fdd..c4fedb54163ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2587,7 +2587,7 @@ version "0.0.0" uid "" -"@kbn/analytics@link:packages/kbn-analytics": +"@kbn/analytics@link:bazel-bin/packages/kbn-analytics/npm_module": version "0.0.0" uid ""