-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from all commits
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 2edbb63
chore(NA): first alpha api extractor working version
mistic 4516010
chore(NA): support kbn-analytics
mistic 28fa3d9
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic 2822a60
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic d510f31
chore(NA): correctly read tsconfig files and deps from ts_config rule
mistic 99c677c
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic afee280
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic 78e9719
chore(NA): layed out pkg_npm_types tree artifact custom rule
mistic b1d9b7f
chore(NA): missing todos
mistic bdead3e
chore(NA): node modules link mapping
mistic ae054bb
chore(NA): fully working pkg_npm_types rule
mistic 13f7801
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic 385454a
chore(NA): merge and solve conflicts with master
mistic 1286d9b
chore(NA): merge and solve conflicts with master
mistic 199300a
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic 5f5ed46
chore(NA): fix changes on new packages using elastic datemath pkgs
mistic e1b2ec0
docs(NA): remove todo
mistic 2fa62c7
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic ac72784
docs(NA): last todo text correction
mistic 2df52f5
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine 89888b4
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine 15cc77a
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine 488407b
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine 8aa3705
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine a036832
chore(NA): removed commented lines
mistic 0a437b6
Merge remote-tracking branch 'upstream/master' into create-types-pkg-…
mistic c3d6e43
fix(NA): include missing package version
mistic 8872d5a
Merge branch 'master' into create-types-pkg-bazel-rule
kibanamachine c9de76f
chore(NA): include license keys
mistic bdc396b
Merge branch 'create-types-pkg-bazel-rule' of github.com:mistic/kiban…
mistic 051d25f
chore(NA): change mock types package into private
mistic b0ef9d1
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine ffae6f4
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine f94089c
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 5bbdd13
Merge remote-tracking branch 'upstream/main' into create-types-pkg-ba…
mistic e2938df
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 51e17a3
chore(NA): disable validator on ts_project rule
mistic c1e37a0
Merge remote-tracking branch 'upstream/main' into create-types-pkg-ba…
mistic b07b499
chore(NA): merge and solve conflicts with main
mistic 5a69198
chore(NA): use the wrapper for ts_project
mistic 2a78de7
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 72942cd
commit using @elastic.co
mistic fd9cd5d
chore(NA): commit using @elastic.co
mistic c114e5b
chore(NA): merge and solve conflicts with master
mistic 51f5b9d
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 4ff37c7
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 4d02d60
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 8170b72
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 8024695
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine 2cfff27
chore(NA): merge and solve conflicts with main
mistic 0c14fa4
Merge branch 'main' into create-types-pkg-bazel-rule
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,28 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary") | ||
|
||
filegroup( | ||
name = "packager_all_files", | ||
srcs = glob([ | ||
"packager/*", | ||
]), | ||
) | ||
|
||
exports_files( | ||
[ | ||
"package_json.mustache", | ||
], | ||
visibility = ["//visibility:public"] | ||
) | ||
|
||
nodejs_binary( | ||
name = "_packager", | ||
data = [ | ||
"@npm//@bazel/typescript", | ||
"@npm//@microsoft/api-extractor", | ||
"@npm//mustache", | ||
":packager_all_files" | ||
], | ||
entry_point = ":packager/index.js", | ||
) |
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. | ||
# | ||
|
||
"""Public API interface for pkg_npm_types rule. | ||
Please do not import from any other files when looking to this rule | ||
""" | ||
|
||
load(":pkg_npm_types.bzl", _pkg_npm_types = "pkg_npm_types") | ||
|
||
pkg_npm_types = _pkg_npm_types |
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,8 @@ | ||
{ | ||
"name": "{{{NAME}}}", | ||
"description": "Generated by Bazel", | ||
"types": "./index.d.ts", | ||
"private": true, | ||
"license": "MIT", | ||
"version": "1.1.0" | ||
} |
90 changes: 90 additions & 0 deletions
90
src/dev/bazel/pkg_npm_types/packager/create_api_extraction.js
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,90 @@ | ||
/* | ||
* 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('@bazel/typescript'); | ||
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function createApiExtraction( | ||
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', | ||
description: 'This is a dummy package.json as API Extractor always requires one.', | ||
types: './index.d.ts', | ||
private: true, | ||
license: 'SSPL-1.0 OR Elastic License 2.0', | ||
version: '1.0.0', | ||
}) | ||
); | ||
} | ||
// 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; | ||
} | ||
|
||
module.exports.createApiExtraction = createApiExtraction; |
43 changes: 43 additions & 0 deletions
43
src/dev/bazel/pkg_npm_types/packager/generate_package_json.js
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,43 @@ | ||
/* | ||
* 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 fs = require('fs'); | ||
const Mustache = require('mustache'); | ||
const path = require('path'); | ||
|
||
function generatePackageJson(outputBasePath, packageJsonTemplatePath, rawPackageJsonTemplateArgs) { | ||
const packageJsonTemplateArgsInTuples = rawPackageJsonTemplateArgs.reduce( | ||
(a, v) => { | ||
const lastTupleIdx = a.length - 1; | ||
const lastTupleSize = a[lastTupleIdx].length; | ||
|
||
if (lastTupleSize < 2) { | ||
a[lastTupleIdx].push(v); | ||
|
||
return a; | ||
} | ||
|
||
return a.push([v]); | ||
}, | ||
[[]] | ||
); | ||
const packageJsonTemplateArgs = Object.fromEntries(new Map(packageJsonTemplateArgsInTuples)); | ||
|
||
try { | ||
const template = fs.readFileSync(packageJsonTemplatePath); | ||
const renderedTemplate = Mustache.render(template.toString(), packageJsonTemplateArgs); | ||
fs.writeFileSync(path.resolve(outputBasePath, 'package.json'), renderedTemplate); | ||
} catch (e) { | ||
console.error(e); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
module.exports.generatePackageJson = generatePackageJson; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should license/version match the package's settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a placeholder and those packages won't be published, I believe we can ignore those 😃