From 2bb97f234a6f77d55eec1038fb855fe3ba42af48 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 15 Apr 2021 02:33:38 +0100 Subject: [PATCH] chore(NA): moving @kbn/utility-types into bazel (#97151) * chore(NA): moving @kbn/utility-types into bazel * chore(NA): solve ts config errors --- .../monorepo-packages.asciidoc | 1 + package.json | 2 +- packages/BUILD.bazel | 1 + packages/kbn-utility-types/BUILD.bazel | 80 +++++++++++++++++++ packages/kbn-utility-types/package.json | 6 +- packages/kbn-utility-types/tsconfig.json | 6 +- .../kbn-utility-types/tsd_tests/empty.d.ts | 9 +++ .../kbn-utility-types/tsd_tests/package.json | 9 +++ .../test_d}/method_keys_of.ts | 3 +- .../test_d}/public_contract.ts | 3 +- .../test_d}/public_keys.ts | 3 +- .../test_d}/public_methods_of.ts | 3 +- .../test_d}/shallow_promise.ts | 3 +- .../test_d}/union_to_intersection.ts | 3 +- .../test_d}/unwrap_observable.ts | 3 +- .../test_d}/unwrap_promise.ts | 3 +- .../{test-d => tsd_tests/test_d}/values.ts | 3 +- .../{test-d => tsd_tests/test_d}/writable.ts | 3 +- x-pack/plugins/cases/server/client/mocks.ts | 2 +- .../elasticsearch/transform/transform.test.ts | 2 +- yarn.lock | 2 +- 21 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 packages/kbn-utility-types/BUILD.bazel create mode 100644 packages/kbn-utility-types/tsd_tests/empty.d.ts create mode 100644 packages/kbn-utility-types/tsd_tests/package.json rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/method_keys_of.ts (84%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/public_contract.ts (83%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/public_keys.ts (83%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/public_methods_of.ts (88%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/shallow_promise.ts (87%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/union_to_intersection.ts (82%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/unwrap_observable.ts (79%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/unwrap_promise.ts (84%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/values.ts (89%) rename packages/kbn-utility-types/{test-d => tsd_tests/test_d}/writable.ts (85%) diff --git a/docs/developer/getting-started/monorepo-packages.asciidoc b/docs/developer/getting-started/monorepo-packages.asciidoc index fc78729be5a69..bc47e46f6763b 100644 --- a/docs/developer/getting-started/monorepo-packages.asciidoc +++ b/docs/developer/getting-started/monorepo-packages.asciidoc @@ -65,4 +65,5 @@ yarn kbn watch-bazel - @kbn/apm-utils - @kbn/config-schema - @kbn/tinymath +- @kbn/utility-types diff --git a/package.json b/package.json index ff7f76df4aee5..cc2532704114f 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "@kbn/tinymath": "link:bazel-bin/packages/kbn-tinymath/npm_module", "@kbn/ui-framework": "link:packages/kbn-ui-framework", "@kbn/ui-shared-deps": "link:packages/kbn-ui-shared-deps", - "@kbn/utility-types": "link:packages/kbn-utility-types", + "@kbn/utility-types": "link:bazel-bin/packages/kbn-utility-types/npm_module", "@kbn/utils": "link:packages/kbn-utils", "@loaders.gl/core": "^2.3.1", "@loaders.gl/json": "^2.3.1", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 182013c356bb0..fe0e8efe0d44f 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -7,5 +7,6 @@ filegroup( "//packages/kbn-apm-utils:build", "//packages/kbn-config-schema:build", "//packages/kbn-tinymath:build", + "//packages/kbn-utility-types:build", ], ) diff --git a/packages/kbn-utility-types/BUILD.bazel b/packages/kbn-utility-types/BUILD.bazel new file mode 100644 index 0000000000000..e22ba38b24a48 --- /dev/null +++ b/packages/kbn-utility-types/BUILD.bazel @@ -0,0 +1,80 @@ +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-utility-types" +PKG_REQUIRE_NAME = "@kbn/utility-types" + +SOURCE_FILES = glob([ + "jest/index.ts", + "index.ts" +]) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "jest/package.json", + "package.json", + "README.md", +] + +SRC_DEPS = [ + "@npm//utility-types", +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", +] + +DEPS = SRC_DEPS + TYPES_DEPS + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + ], +) + +ts_project( + name = "tsc", + args = ['--pretty'], + srcs = SRCS, + deps = DEPS, + declaration = True, + declaration_map = True, + incremental = True, + out_dir = "target", + source_map = True, + root_dir = ".", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_BASE_NAME, + srcs = [], + deps = [":tsc"] + DEPS, + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + srcs = NPM_MODULE_EXTRA_FILES, + deps = [ + ":%s" % PKG_BASE_NAME, + ] +) + +filegroup( + name = "build", + srcs = [ + ":npm_module", + ], + visibility = ["//visibility:public"], +) diff --git a/packages/kbn-utility-types/package.json b/packages/kbn-utility-types/package.json index ad7dcc6b906c3..95fbd5d00f395 100644 --- a/packages/kbn-utility-types/package.json +++ b/packages/kbn-utility-types/package.json @@ -9,10 +9,6 @@ "devOnly": false }, "scripts": { - "build": "../../node_modules/.bin/tsc", - "kbn:bootstrap": "../../node_modules/.bin/tsc", - "kbn:watch": "../../node_modules/.bin/tsc --watch", - "test": "../../node_modules/.bin/tsd", - "clean": "../../node_modules/.bin/del target" + "test": "../../node_modules/.bin/tsd tsd_tests" } } \ No newline at end of file diff --git a/packages/kbn-utility-types/tsconfig.json b/packages/kbn-utility-types/tsconfig.json index cfa782e5d38d2..50fa71155bee8 100644 --- a/packages/kbn-utility-types/tsconfig.json +++ b/packages/kbn-utility-types/tsconfig.json @@ -1,12 +1,12 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "incremental": false, + "incremental": true, "outDir": "./target", - "declarationDir": "./target", "stripInternal": true, "declaration": true, "declarationMap": true, + "rootDir": "./", "sourceMap": true, "sourceRoot": "../../../../packages/kbn-utility-types", "types": [ @@ -17,6 +17,6 @@ "include": [ "index.ts", "jest/**/*", - "test-d/**/*" + "tsd_tests/**/*" ] } diff --git a/packages/kbn-utility-types/tsd_tests/empty.d.ts b/packages/kbn-utility-types/tsd_tests/empty.d.ts new file mode 100644 index 0000000000000..c5184fc78704b --- /dev/null +++ b/packages/kbn-utility-types/tsd_tests/empty.d.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +// This is just an empty mock file to provide a workaround to run tsd correctly isolated diff --git a/packages/kbn-utility-types/tsd_tests/package.json b/packages/kbn-utility-types/tsd_tests/package.json new file mode 100644 index 0000000000000..fb549abca3197 --- /dev/null +++ b/packages/kbn-utility-types/tsd_tests/package.json @@ -0,0 +1,9 @@ +{ + "types": "empty.d.ts", + "tsd": { + "directory": "test_d", + "compilerOptions": { + "rootDir": "../" + } + } +} \ No newline at end of file diff --git a/packages/kbn-utility-types/test-d/method_keys_of.ts b/packages/kbn-utility-types/tsd_tests/test_d/method_keys_of.ts similarity index 84% rename from packages/kbn-utility-types/test-d/method_keys_of.ts rename to packages/kbn-utility-types/tsd_tests/test_d/method_keys_of.ts index 03ef517c76b68..6169f2d92f81b 100644 --- a/packages/kbn-utility-types/test-d/method_keys_of.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/method_keys_of.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectType } from 'tsd'; -import { MethodKeysOf } from '../index'; +import { MethodKeysOf } from '../../index'; class Test { public name: string = ''; diff --git a/packages/kbn-utility-types/test-d/public_contract.ts b/packages/kbn-utility-types/tsd_tests/test_d/public_contract.ts similarity index 83% rename from packages/kbn-utility-types/test-d/public_contract.ts rename to packages/kbn-utility-types/tsd_tests/test_d/public_contract.ts index 53e657084fec4..ef488f42805ee 100644 --- a/packages/kbn-utility-types/test-d/public_contract.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/public_contract.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectType } from 'tsd'; -import { PublicContract } from '../index'; +import { PublicContract } from '../../index'; class Test { public str: string = ''; diff --git a/packages/kbn-utility-types/test-d/public_keys.ts b/packages/kbn-utility-types/tsd_tests/test_d/public_keys.ts similarity index 83% rename from packages/kbn-utility-types/test-d/public_keys.ts rename to packages/kbn-utility-types/tsd_tests/test_d/public_keys.ts index d9377579f0011..1674520daffba 100644 --- a/packages/kbn-utility-types/test-d/public_keys.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/public_keys.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectType } from 'tsd'; -import { PublicKeys } from '../index'; +import { PublicKeys } from '../../index'; class Test { public str: string = ''; diff --git a/packages/kbn-utility-types/test-d/public_methods_of.ts b/packages/kbn-utility-types/tsd_tests/test_d/public_methods_of.ts similarity index 88% rename from packages/kbn-utility-types/test-d/public_methods_of.ts rename to packages/kbn-utility-types/tsd_tests/test_d/public_methods_of.ts index 66754f8473846..5db1117bf47f3 100644 --- a/packages/kbn-utility-types/test-d/public_methods_of.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/public_methods_of.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable, expectNotAssignable } from 'tsd'; -import { PublicMethodsOf } from '../index'; +import { PublicMethodsOf } from '../../index'; class Test { public name: string = ''; diff --git a/packages/kbn-utility-types/test-d/shallow_promise.ts b/packages/kbn-utility-types/tsd_tests/test_d/shallow_promise.ts similarity index 87% rename from packages/kbn-utility-types/test-d/shallow_promise.ts rename to packages/kbn-utility-types/tsd_tests/test_d/shallow_promise.ts index 4b806a2860626..712189f43bfe2 100644 --- a/packages/kbn-utility-types/test-d/shallow_promise.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/shallow_promise.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectType } from 'tsd'; -import { ShallowPromise } from '../index'; +import { ShallowPromise } from '../../index'; type P1 = ShallowPromise; type P2 = ShallowPromise>; diff --git a/packages/kbn-utility-types/test-d/union_to_intersection.ts b/packages/kbn-utility-types/tsd_tests/test_d/union_to_intersection.ts similarity index 82% rename from packages/kbn-utility-types/test-d/union_to_intersection.ts rename to packages/kbn-utility-types/tsd_tests/test_d/union_to_intersection.ts index 07c8cfb4cfd3f..a37cdc5160edb 100644 --- a/packages/kbn-utility-types/test-d/union_to_intersection.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/union_to_intersection.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable } from 'tsd'; -import { UnionToIntersection } from '../index'; +import { UnionToIntersection } from '../../index'; type INTERSECTED = UnionToIntersection<{ foo: 'bar' } | { baz: 'qux' }>; diff --git a/packages/kbn-utility-types/test-d/unwrap_observable.ts b/packages/kbn-utility-types/tsd_tests/test_d/unwrap_observable.ts similarity index 79% rename from packages/kbn-utility-types/test-d/unwrap_observable.ts rename to packages/kbn-utility-types/tsd_tests/test_d/unwrap_observable.ts index 667ae22984d90..beaf692341615 100644 --- a/packages/kbn-utility-types/test-d/unwrap_observable.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/unwrap_observable.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable } from 'tsd'; -import { UnwrapObservable, ObservableLike } from '../index'; +import { UnwrapObservable, ObservableLike } from '../../index'; type STRING = UnwrapObservable>; diff --git a/packages/kbn-utility-types/test-d/unwrap_promise.ts b/packages/kbn-utility-types/tsd_tests/test_d/unwrap_promise.ts similarity index 84% rename from packages/kbn-utility-types/test-d/unwrap_promise.ts rename to packages/kbn-utility-types/tsd_tests/test_d/unwrap_promise.ts index 9384f58f7fdea..6491555b883bf 100644 --- a/packages/kbn-utility-types/test-d/unwrap_promise.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/unwrap_promise.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable } from 'tsd'; -import { UnwrapPromise } from '../index'; +import { UnwrapPromise } from '../../index'; type STRING = UnwrapPromise>; type TUPLE = UnwrapPromise>; diff --git a/packages/kbn-utility-types/test-d/values.ts b/packages/kbn-utility-types/tsd_tests/test_d/values.ts similarity index 89% rename from packages/kbn-utility-types/test-d/values.ts rename to packages/kbn-utility-types/tsd_tests/test_d/values.ts index 099e94c6b549d..aeb867b78e13d 100644 --- a/packages/kbn-utility-types/test-d/values.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/values.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable } from 'tsd'; -import { Values } from '../index'; +import { Values } from '../../index'; // Arrays type STRING = Values; diff --git a/packages/kbn-utility-types/test-d/writable.ts b/packages/kbn-utility-types/tsd_tests/test_d/writable.ts similarity index 85% rename from packages/kbn-utility-types/test-d/writable.ts rename to packages/kbn-utility-types/tsd_tests/test_d/writable.ts index a9fbf4a1def8f..cfaba555a7980 100644 --- a/packages/kbn-utility-types/test-d/writable.ts +++ b/packages/kbn-utility-types/tsd_tests/test_d/writable.ts @@ -6,8 +6,9 @@ * Side Public License, v 1. */ +// eslint-disable-next-line import/no-extraneous-dependencies import { expectAssignable } from 'tsd'; -import { Writable } from '../index'; +import { Writable } from '../../index'; type WritableArray = Writable; expectAssignable(['1']); diff --git a/x-pack/plugins/cases/server/client/mocks.ts b/x-pack/plugins/cases/server/client/mocks.ts index 51119070a798d..4c0f89cf77a67 100644 --- a/x-pack/plugins/cases/server/client/mocks.ts +++ b/x-pack/plugins/cases/server/client/mocks.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from 'kibana/server'; -import { DeeplyMockedKeys } from 'packages/kbn-utility-types/target/jest'; +import { DeeplyMockedKeys } from '@kbn/utility-types/target/jest'; import { loggingSystemMock, elasticsearchServiceMock } from '../../../../../src/core/server/mocks'; import { AlertServiceContract, diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts index 732f03440ce9d..7fc8d59628738 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts @@ -19,7 +19,7 @@ jest.mock('./common', () => { }); import { ResponseError } from '@elastic/elasticsearch/lib/errors'; -import type { DeeplyMockedKeys } from 'packages/kbn-utility-types/target/jest'; +import type { DeeplyMockedKeys } from '@kbn/utility-types/target/jest'; import type { ElasticsearchClient, SavedObject, SavedObjectsClientContract } from 'kibana/server'; import { ElasticsearchAssetType } from '../../../../types'; diff --git a/yarn.lock b/yarn.lock index 2aaf94250b966..c43641d668ae2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2752,7 +2752,7 @@ version "0.0.0" uid "" -"@kbn/utility-types@link:packages/kbn-utility-types": +"@kbn/utility-types@link:bazel-bin/packages/kbn-utility-types/npm_module": version "0.0.0" uid ""