forked from cockroachdb/cockroach
-
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.
build: compile js protos with
protoc-gen-es
This change introduces a new JS package that compiles JS protobuf client code with help of `protoc` compiler and `protoc-gen-es` plugin. It is supposed that this package will be consumed by CC Console. Release note: None
- Loading branch information
Showing
11 changed files
with
238 additions
and
61 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
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 |
---|---|---|
|
@@ -275,6 +275,7 @@ npm_translate_lock( | |
"//pkg/ui:pnpm-workspace.yaml", | ||
"//pkg/ui/patches:[email protected]", | ||
"//pkg/ui/workspaces/cluster-ui:package.json", | ||
"//pkg/ui/workspaces/crdb-api-client:package.json", | ||
"//pkg/ui/workspaces/db-console:package.json", | ||
"//pkg/ui/workspaces/db-console/src/js:package.json", | ||
"//pkg/ui/workspaces/e2e-tests:package.json", | ||
|
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,62 @@ | ||
# PROTOBUF_TARGETS lists the indirect dependencies needed to compile proto dependencies | ||
# of //pkg/server/serverpb:serverpb_proto target | ||
PROTOBUF_TARGETS = [ | ||
"//pkg/build:build_proto", | ||
"//pkg/clusterversion:clusterversion_proto", | ||
"//pkg/config/zonepb:zonepb_proto", | ||
"//pkg/geo/geopb:geopb_proto", | ||
"//pkg/gossip:gossip_proto", | ||
"//pkg/jobs/jobspb:jobspb_proto", | ||
"//pkg/kv/kvpb:kvpb_proto", | ||
"//pkg/kv/kvserver/concurrency/isolation:isolation_proto", | ||
"//pkg/kv/kvserver/concurrency/lock:lock_proto", | ||
"//pkg/kv/kvserver/kvserverpb:kvserverpb_proto", | ||
"//pkg/kv/kvserver/liveness/livenesspb:livenesspb_proto", | ||
"//pkg/kv/kvserver/loqrecovery/loqrecoverypb:loqrecoverypb_proto", | ||
"//pkg/kv/kvserver/readsummary/rspb:rspb_proto", | ||
"//pkg/kv/kvserver/kvflowcontrol/kvflowcontrolpb:kvflowcontrolpb_proto", | ||
"//pkg/multitenant/mtinfopb:mtinfopb_proto", | ||
"//pkg/multitenant/tenantcapabilities/tenantcapabilitiespb:tenantcapabilitiespb_proto", | ||
"//pkg/roachpb:roachpb_proto", | ||
"//pkg/rpc/rpcpb:rpcpb_proto", | ||
"//pkg/server/diagnostics/diagnosticspb:diagnosticspb_proto", | ||
"//pkg/server/serverpb:serverpb_proto", | ||
"//pkg/server/status/statuspb:statuspb_proto", | ||
"//pkg/settings:settings_proto", | ||
"//pkg/sql/appstatspb:appstatspb_proto", | ||
"//pkg/sql/catalog/catenumpb:catenumpb_proto", | ||
"//pkg/sql/catalog/catpb:catpb_proto", | ||
"//pkg/sql/catalog/descpb:descpb_proto", | ||
"//pkg/sql/catalog/fetchpb:fetchpb_proto", | ||
"//pkg/sql/contentionpb:contentionpb_proto", | ||
"//pkg/sql/execinfrapb:execinfrapb_proto", | ||
"//pkg/sql/sem/semenumpb:semenumpb_proto", | ||
"//pkg/sql/inverted:inverted_proto", | ||
"//pkg/sql/lex:lex_proto", | ||
"//pkg/sql/pgwire/pgerror:pgerror_proto", | ||
"//pkg/sql/schemachanger/scpb:scpb_proto", | ||
"//pkg/sql/sessiondatapb:sessiondatapb_proto", | ||
"//pkg/sql/sqlstats/insights:insights_proto", | ||
"//pkg/sql/types:types_proto", | ||
"//pkg/storage/enginepb:enginepb_proto", | ||
"//pkg/ts/catalog:catalog_proto", | ||
"//pkg/ts/tspb:tspb_proto", | ||
"//pkg/util/duration:duration_proto", | ||
"//pkg/util/hlc:hlc_proto", | ||
"//pkg/util/admission/admissionpb:admissionpb_proto", | ||
"//pkg/util/log/logpb:logpb_proto", | ||
"//pkg/util/metric:metric_proto", | ||
"//pkg/util/timeutil/pgdate:pgdate_proto", | ||
"//pkg/util/tracing/tracingpb:tracingpb_proto", | ||
"//pkg/util:util_proto", | ||
"@com_github_prometheus_client_model//io/prometheus/client:io_prometheus_client_proto", | ||
"@com_github_cockroachdb_errors//errorspb:errorspb_proto", | ||
"@com_github_gogo_protobuf//gogoproto:gogo_proto", | ||
"@com_google_protobuf//:any_proto", | ||
"@com_google_protobuf//:descriptor_proto", | ||
"@com_google_protobuf//:duration_proto", | ||
"@com_google_protobuf//:timestamp_proto", | ||
"@go_googleapis//google/api:annotations_proto", | ||
"@go_googleapis//google/api:http_proto", | ||
"@io_etcd_go_raft_v3//raftpb:raftpb_proto", | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,88 @@ | ||
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test") | ||
load("@aspect_rules_js//npm:defs.bzl", "npm_package") | ||
load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
load("//docs/generated/http:defs.bzl", "PROTOBUF_TARGETS") | ||
load("//pkg/ui/workspaces/db-console/src/js:defs.bzl", "proto_sources") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
genrule( | ||
name = "protos", | ||
srcs = [ | ||
":node_modules/@bufbuild/protoc-gen-es/bin/protoc-gen-es", | ||
":proto_sources", | ||
] + PROTOBUF_TARGETS, | ||
outs = ["dist"], | ||
cmd = """ | ||
mkdir -p $(OUTS); | ||
DESCRIPTOR_SET_IN=$$(for word in $(SRCS); do echo $$word; done | grep '\\.bin$$' | tr -s '\\n' ':'); | ||
PROTO_PATHS=$$(for f in $(locations :proto_sources); | ||
do if [[ "$$f" =~ ^.*/pkg/.*/_virtual_imports/.*_proto/.*.proto$$ ]]; | ||
then echo $$f | sed 's|.*pkg/.*/_virtual_imports/.*_proto/||' | sed 's|.bin$$||'; | ||
fi; done | sort -u); | ||
export PATH=$$PATH:$$(dirname $(NODE_PATH)) | ||
$(location @com_google_protobuf//:protoc) \ | ||
--plugin=$(location :node_modules/@bufbuild/protoc-gen-es/bin/protoc-gen-es) \ | ||
--es_out $(OUTS) \ | ||
--descriptor_set_in $$DESCRIPTOR_SET_IN \ | ||
--es_opt target=js+dts \ | ||
$$PROTO_PATHS""", | ||
toolchains = ["@nodejs_toolchains//:resolved_toolchain"], | ||
tools = [ | ||
"@com_google_protobuf//:protoc", | ||
"@nodejs_toolchains//:resolved_toolchain", | ||
], | ||
) | ||
|
||
proto_sources( | ||
name = "proto_sources", | ||
protos = [ | ||
"//pkg/server/serverpb:serverpb_proto", | ||
"//pkg/ts/tspb:tspb_proto", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "index_ts", | ||
srcs = [":protos"], | ||
outs = ["index.ts"], | ||
cmd = """ | ||
ABS_ROOT_PATH=$$(realpath $(SRCS)) | ||
for f in $$(find $$ABS_ROOT_PATH -name *.js) | ||
do | ||
filename=$$(basename -s .js $$f) | ||
filepath=$${f#$$ABS_ROOT_PATH/} | ||
filepath=$${filepath%.js} | ||
import_name=$${filepath/-/_}; \ | ||
echo export "*" as $${import_name////_} from \\"./$$(basename $(SRCS))/$${filepath}\\"\\; >> $@ | ||
done | ||
""", | ||
) | ||
|
||
ts_project( | ||
name = "ts_project", | ||
srcs = [ | ||
"tsconfig.json", | ||
":index_ts", | ||
":protos", | ||
], | ||
tsconfig = "tsconfig.json", | ||
validate = True, | ||
deps = [":node_modules"], | ||
) | ||
|
||
npm_package( | ||
name = "crdb-api-client", | ||
srcs = [ | ||
"package.json", | ||
"tsconfig.json", | ||
":index_ts", | ||
":protos", | ||
":ts_project", | ||
], | ||
package = "@cockroachlabs/crdb-api-client", | ||
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,12 @@ | ||
{ | ||
"name": "@cockroachlabs/crdb-api-client", | ||
"version": "1.0.0", | ||
"main": "index.ts", | ||
"devDependencies": { | ||
"@bufbuild/protoc-gen-es": "^1.7.2", | ||
"typescript": "5.1.6" | ||
}, | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^1.7.2" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"lib": ["ESNext"], | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": false | ||
} | ||
} |
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