chore(NA): moving @kbn/analytics into bazel (#98917) (#99134)

* chore(NA): moving @kbn/analytics into bazel

* chore(NA): fix type check for package migration

* chore(NA): fix type check for package migration

* chore(NA): fix type check for package migration

* chore(NA): separate type generating from server code

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	packages/kbn-analytics/scripts/build.js
This commit is contained in:
Tiago Costa 2021-05-04 00:44:07 +01:00 committed by GitHub
parent 2ae368beee
commit d779fa460e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 152 additions and 117 deletions

View file

@ -3,6 +3,7 @@
exports_files(
[
"tsconfig.base.json",
"tsconfig.browser.json",
"tsconfig.json",
"package.json"
],

View file

@ -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

View file

@ -119,7 +119,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",

View file

@ -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",

View file

@ -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"],
)

View file

@ -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'],
};

View file

@ -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 <ahmadbamieh@gmail.com>",
"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"
}

View file

@ -1,83 +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'] ? ['--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
`,
},
}
);

View file

@ -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/**/*"
]
}

View file

@ -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,

View file

@ -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"
}

View file

@ -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 ""