forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] enable sourcemaps in summarized types of @kbn/crypto (elastic#12…
…6410) * [ts] enable sourcemaps in summarized types of @kbn/crypto * update snapshots * remove unnecessary exports of @kbn/type-summarizer package * remove tsc from the build process * use `@kbn/type-summarizer` to summarize its own types * add tests for interface and function * switch to export type where necessary * ignore __tmp__ in global jest preset * ignore __tmp__ globally * remove `@kbn/crypto` types path
- Loading branch information
1 parent
b312193
commit ef3eddb
Showing
62 changed files
with
2,783 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**/*.js.snap | ||
__tmp__ | ||
/.es | ||
/.chromium | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ target | |
*.iml | ||
*.log | ||
types.eslint.config.js | ||
__tmp__ | ||
|
||
# Ignore example plugin builds | ||
/examples/*/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
load("@npm//@bazel/typescript:index.bzl", "ts_config") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") | ||
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "directory_file_path") | ||
|
||
PKG_BASE_NAME = "kbn-type-summarizer" | ||
PKG_REQUIRE_NAME = "@kbn/type-summarizer" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"src/**/*.ts", | ||
], | ||
exclude = [ | ||
"**/*.test.*" | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
"README.md", | ||
] | ||
|
||
RUNTIME_DEPS = [ | ||
"@npm//@babel/runtime", | ||
"@npm//@microsoft/api-extractor", | ||
"@npm//source-map-support", | ||
"@npm//chalk", | ||
"@npm//getopts", | ||
"@npm//is-path-inside", | ||
"@npm//normalize-path", | ||
"@npm//source-map", | ||
"@npm//tslib", | ||
] | ||
|
||
TYPES_DEPS = [ | ||
"@npm//@microsoft/api-extractor", | ||
"@npm//@types/jest", | ||
"@npm//@types/node", | ||
"@npm//@types/normalize-path", | ||
"@npm//getopts", | ||
"@npm//is-path-inside", | ||
"@npm//normalize-path", | ||
"@npm//source-map", | ||
"@npm//tslib", | ||
] | ||
|
||
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", | ||
) | ||
|
||
jsts_transpiler( | ||
name = "target_node", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
) | ||
|
||
js_library( | ||
name = PKG_BASE_NAME, | ||
srcs = NPM_MODULE_EXTRA_FILES, | ||
deps = RUNTIME_DEPS + [":target_node"], | ||
package_name = PKG_REQUIRE_NAME, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
directory_file_path( | ||
name = "bazel-cli-path", | ||
directory = ":target_node", | ||
path = "bazel_cli.js", | ||
) | ||
|
||
nodejs_binary( | ||
name = "bazel-cli", | ||
data = [ | ||
":%s" % PKG_BASE_NAME | ||
], | ||
entry_point = ":bazel-cli-path", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_module", | ||
deps = [ | ||
":%s" % PKG_BASE_NAME, | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "build", | ||
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @kbn/type-summarizer | ||
|
||
Consume the .d.ts files for a package, produced by `tsc`, and generate a single `.d.ts` file of the public types along with a source map that points back to the original source. | ||
|
||
## You mean like API Extractor? | ||
|
||
Yeah, except with source map support and without all the legacy features and other features we disable to generate our current type summaries. | ||
|
||
I first attempted to implement this in api-extractor but I (@spalger) hit a wall when dealing with the `Span` class. This class handles all the text output which ends up becoming source code, and I wasn't able to find a way to associate specific spans with source locations without getting 12 headaches. Instead I decided to try implementing this from scratch, reducing our reliance on the api-extractor project and putting us in control of how we generate type summaries. | ||
|
||
This package is missing some critical features for wider adoption, but rather than build the entire product in a branch I decided to implement support for a small number of TS features and put this to use in the `@kbn/crypto` module ASAP. | ||
|
||
The plan is to expand to other packages in the Kibana repo, adding support for language features as we go. | ||
|
||
## Something isn't working and I'm blocked! | ||
|
||
If there's a problem with the implmentation blocking another team at any point we can move the package back to using api-extractor by removing the package from the `TYPE_SUMMARIZER_PACKAGES` list at the top of [packages/kbn-type-summarizer/src/lib/bazel_cli_config.ts](./src/lib/bazel_cli_config.ts). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** @typedef {import("@jest/types").Config.InitialOptions} JestConfig */ | ||
/** @type {JestConfig} */ | ||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-type-summarizer'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** @typedef {import("@jest/types").Config.InitialOptions} JestConfig */ | ||
/** @type {JestConfig} */ | ||
module.exports = { | ||
preset: '@kbn/test/jest_integration_node', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-type-summarizer'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@kbn/type-summarizer", | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0", | ||
"main": "./target_node/index.js", | ||
"private": true | ||
} |
Oops, something went wrong.