Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(NA): creates pkg_npm_types bazel rule #116465

Merged
merged 52 commits into from
Nov 16, 2021
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
82961a1
chore(NA): auto creation of the package.json for the new types pkg rule
mistic Sep 30, 2021
2edbb63
chore(NA): first alpha api extractor working version
mistic Sep 30, 2021
4516010
chore(NA): support kbn-analytics
mistic Oct 1, 2021
28fa3d9
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 5, 2021
2822a60
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 5, 2021
d510f31
chore(NA): correctly read tsconfig files and deps from ts_config rule
mistic Oct 5, 2021
99c677c
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 6, 2021
afee280
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 6, 2021
78e9719
chore(NA): layed out pkg_npm_types tree artifact custom rule
mistic Oct 6, 2021
b1d9b7f
chore(NA): missing todos
mistic Oct 6, 2021
bdead3e
chore(NA): node modules link mapping
mistic Oct 6, 2021
ae054bb
chore(NA): fully working pkg_npm_types rule
mistic Oct 7, 2021
13f7801
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 7, 2021
385454a
chore(NA): merge and solve conflicts with master
mistic Oct 7, 2021
1286d9b
chore(NA): merge and solve conflicts with master
mistic Oct 25, 2021
199300a
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 26, 2021
5f5ed46
chore(NA): fix changes on new packages using elastic datemath pkgs
mistic Oct 26, 2021
e1b2ec0
docs(NA): remove todo
mistic Oct 26, 2021
2fa62c7
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 26, 2021
ac72784
docs(NA): last todo text correction
mistic Oct 27, 2021
2df52f5
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 27, 2021
89888b4
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 27, 2021
15cc77a
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 27, 2021
488407b
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 28, 2021
8aa3705
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 28, 2021
a036832
chore(NA): removed commented lines
mistic Oct 28, 2021
0a437b6
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic Oct 28, 2021
c3d6e43
fix(NA): include missing package version
mistic Oct 28, 2021
8872d5a
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine Oct 28, 2021
c9de76f
chore(NA): include license keys
mistic Oct 28, 2021
bdc396b
Merge branch 'create-types-pkg-bazel-rule' of github.com:mistic/kiban…
mistic Oct 28, 2021
051d25f
chore(NA): change mock types package into private
mistic Oct 29, 2021
b0ef9d1
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Oct 29, 2021
ffae6f4
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Oct 29, 2021
f94089c
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 2, 2021
5bbdd13
Merge remote-tracking branch 'upstream/main' into create-types-pkg-ba…
mistic Nov 3, 2021
e2938df
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 3, 2021
51e17a3
chore(NA): disable validator on ts_project rule
mistic Nov 3, 2021
c1e37a0
Merge remote-tracking branch 'upstream/main' into create-types-pkg-ba…
mistic Nov 3, 2021
b07b499
chore(NA): merge and solve conflicts with main
mistic Nov 4, 2021
5a69198
chore(NA): use the wrapper for ts_project
mistic Nov 4, 2021
2a78de7
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 5, 2021
72942cd
commit using @elastic.co
mistic Nov 5, 2021
fd9cd5d
chore(NA): commit using @elastic.co
mistic Nov 5, 2021
c114e5b
chore(NA): merge and solve conflicts with master
mistic Nov 5, 2021
51f5b9d
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 6, 2021
4ff37c7
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 8, 2021
4d02d60
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 9, 2021
8170b72
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 9, 2021
8024695
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 11, 2021
2cfff27
chore(NA): merge and solve conflicts with main
mistic Nov 12, 2021
0c14fa4
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine Nov 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(NA): auto creation of the package.json for the new types pkg rule
mistic committed Sep 30, 2021

Verified

This commit was signed with the committer’s verified signature.
mistic Tiago Costa
commit 82961a17835f52845c3cd67808aaec751424a387
14 changes: 12 additions & 2 deletions packages/elastic-datemath/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
load("//src/dev/bazel:index.bzl", "jsts_transpiler")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "types_pkg")

PKG_BASE_NAME = "elastic-datemath"
PKG_REQUIRE_NAME = "@elastic/datemath"
@@ -57,10 +57,20 @@ ts_project(
tsconfig = ":tsconfig",
)

types_pkg(
name = "npm_package_types",
package_name = "@types/elastic__datemath",
data = SRCS + DEPS + [
"tsconfig.json",
"//:tsconfig.base.json",
":tsc_types",
]
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":target_node", ":tsc_types"],
deps = DEPS + [":target_node", ":tsc_types", ":npm_package_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions src/dev/bazel/index.bzl
Original file line number Diff line number Diff line change
@@ -11,5 +11,7 @@ Please do not import from any other files when looking to use a custom rule
"""

load("//src/dev/bazel:jsts_transpiler.bzl", _jsts_transpiler = "jsts_transpiler")
load("//src/dev/bazel/types_pkg:types_pkg.bzl", _types_pkg = "types_pkg")

jsts_transpiler = _jsts_transpiler
types_pkg = _types_pkg
19 changes: 19 additions & 0 deletions src/dev/bazel/types_pkg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package(default_visibility = ["//visibility:public"])

load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary")

exports_files(
[
"package_json.tpl",
"api_extractor.js"
],
visibility = ["//visibility:public"]
)

nodejs_binary(
name = "api_extractor",
data = [
":api_extractor.js",
],
entry_point = ":api_extractor.js",
)
108 changes: 108 additions & 0 deletions src/dev/bazel/types_pkg/api_extractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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.
*/

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

const { format, parseTsconfig } = require('typescript');
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor');
const fs = require('fs');
const path = require('path');
const DEBUG = false;

function runMain(tsConfig, entryPoint, dtsBundleOut, apiReviewFolder, acceptApiUpdates = false) {
const [parsedConfig, errors] = parseTsconfig(tsConfig);
if (errors && errors.length) {
console.error(format('', errors));
return 1;
}
const pkgJson = path.resolve(path.dirname(entryPoint), 'package.json');
if (!fs.existsSync(pkgJson)) {
fs.writeFileSync(
pkgJson,
JSON.stringify({
name: 'GENERATED-BY-BAZEL',
version: '0.0.0',
description: 'This is a dummy package.json as API Extractor always requires one.',
})
);
}
// API extractor doesn't always support the version of TypeScript used in the repo
// example: at the moment it is not compatable with 3.2
// to use the internal TypeScript we shall not create a program but rather pass a parsed tsConfig.
const parsedTsConfig = parsedConfig.config;
const extractorOptions = {
localBuild: acceptApiUpdates,
};
const configObject = {
compiler: {
overrideTsconfig: parsedTsConfig,
},
projectFolder: path.resolve(path.dirname(tsConfig)),
mainEntryPointFilePath: path.resolve(entryPoint),
apiReport: {
enabled: !!apiReviewFolder,
// TODO(alan-agius4): remove this folder name when the below issue is solved upstream
// See: https://github.com/microsoft/web-build-tools/issues/1470
reportFileName: (apiReviewFolder && path.resolve(apiReviewFolder)) || 'invalid',
},
docModel: {
enabled: false,
},
dtsRollup: {
enabled: !!dtsBundleOut,
untrimmedFilePath: dtsBundleOut && path.resolve(dtsBundleOut),
},
tsdocMetadata: {
enabled: false,
},
};
const options = {
configObject,
packageJson: undefined,
packageJsonFullPath: pkgJson,
configObjectFullPath: undefined,
};
const extractorConfig = ExtractorConfig.prepare(options);
const { succeeded } = Extractor.invoke(extractorConfig, extractorOptions);
// API extractor errors are emitted by it's logger.
return succeeded ? 0 : 1;
}

exports.runMain = runMain;

// Entry point
if (require.main === module) {
if (DEBUG) {
console.error(`
api-extractor: running with
cwd: ${process.cwd()}
argv:
${process.argv.join('\n ')}
`);
}
const [tsConfig, entryPoint, dtsBundleOut] = process.argv.slice(2);
const entryPoints = entryPoint.split(',');
const dtsBundleOuts = dtsBundleOut.split(',');
if (entryPoints.length !== entryPoints.length) {
throw new Error(
`Entry points count (${entryPoints.length}) does not match Bundle out count (${dtsBundleOuts.length})`
);
}
for (let i = 0; i < entryPoints.length; i++) {
process.exitCode = runMain(tsConfig, entryPoints[i], dtsBundleOuts[i]);
if (process.exitCode !== 0) {
break;
}
}
}
5 changes: 5 additions & 0 deletions src/dev/bazel/types_pkg/package_json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "{NAME}",
"description": "Generated by Bazel",
"types": "./index.d.ts"
}
82 changes: 82 additions & 0 deletions src/dev/bazel/types_pkg/types_pkg.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#
# 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.
#

load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
#load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary")
#load("@npm//typescript:index.bzl", "tsc")

def _join(*elements):
segments = [f for f in elements if f]
if len(segments):
return "/".join(segments)
return "."

def _types_pkg_impl(ctx):
out = ctx.actions.declare_file(_join(ctx.label.name, "package.json"))
# out = ctx.actions.declare_file("package.json")
inputs = ctx.files.data[:]

ctx.actions.expand_template(
output = out,
template = ctx.file._template,
substitutions = {"{NAME}": ctx.attr.package_name},
)

outputs = []
outputs.append(out)
# # outputs.append(ctx.actions.declare_file(ctx.label.name + "index.d.ts"))
# js_out = ctx.actions.declare_directory("%s" % ctx.attr.name)
# outputs.append(js_out)
#
# extractor_args = ctx.actions.args()
# extractor_args.add_all([
# ctx.expand_location("tsconfig.json"),
# ctx.expand_location("index.d.ts"),
# "index.d.ts"
# ])
#
# ctx.actions.run(
# progress_message = "Running API Extractor",
# mnemonic = "APIExtractor",
# executable = ctx.executable._api_extractor,
# inputs = inputs,
# outputs = outputs,
# arguments = [extractor_args],
# )

# run_node(
# ctx,
# inputs = inputs,
# arguments = [extractor_args],
# outputs = outputs,
# mnemonic = "ApiExtractor",
# executable = "_api_extractor"
# execution_requirements = {},
# )

return [DefaultInfo(files = depset(outputs))]

types_pkg = rule(
implementation = _types_pkg_impl,
attrs = {
"package_name": attr.string(),
"_template": attr.label(
allow_single_file = True,
default = "package_json.tpl",
),
"data": attr.label_list(
allow_files = True,
),
"_api_extractor": attr.label(
doc = "Target that executes the api-extractor binary",
executable = True,
cfg = "host",
default = Label("//src/dev/bazel/types_pkg:api_extractor"),
),
},
)