mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
move to new rules_nodejs protobuf example to unblock upgrade
@hgiesel the tag editor will need to add the following to the rollup deps: "//ts/lib:backend_proto", "//ts/lib:fluent_proto",
This commit is contained in:
parent
0ca9a6b009
commit
afc2892f2e
8 changed files with 184 additions and 853 deletions
|
@ -1,8 +1,6 @@
|
|||
"""Repo setup that can't happen until after defs.bzl:setup_deps() is run."""
|
||||
|
||||
load("@py_deps//:requirements.bzl", "pip_install")
|
||||
load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies")
|
||||
|
||||
def setup_late_deps():
|
||||
pip_install()
|
||||
npm_bazel_labs_dependencies()
|
||||
|
|
|
@ -43,6 +43,8 @@ rollup_bundle(
|
|||
"CongratsPage",
|
||||
"bootstrap",
|
||||
"//ts/lib",
|
||||
"//ts/lib:backend_proto",
|
||||
"//ts/lib:fluent_proto",
|
||||
"@npm//@rollup/plugin-commonjs",
|
||||
"@npm//@rollup/plugin-node-resolve",
|
||||
"@npm//rollup-plugin-terser",
|
||||
|
|
|
@ -64,6 +64,8 @@ rollup_bundle(
|
|||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//ts/lib",
|
||||
"//ts/lib:backend_proto",
|
||||
"//ts/lib:fluent_proto",
|
||||
"bootstrap",
|
||||
"@npm//@rollup/plugin-commonjs",
|
||||
"@npm//@rollup/plugin-node-resolve",
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("//ts:prettier.bzl", "prettier_test")
|
||||
load("//ts:eslint.bzl", "eslint_test")
|
||||
load("//ts:protobuf.bzl", "protobufjs_library")
|
||||
|
||||
# Protobuf
|
||||
#############
|
||||
|
||||
load("@npm//@bazel/labs:index.bzl", "protobufjs_ts_library")
|
||||
|
||||
protobufjs_ts_library(
|
||||
protobufjs_library(
|
||||
name = "fluent_proto",
|
||||
proto = "//rslib:fluent_proto_lib",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//rslib:fluent_proto_lib"],
|
||||
)
|
||||
|
||||
protobufjs_ts_library(
|
||||
protobufjs_library(
|
||||
name = "backend_proto",
|
||||
proto = "//rslib:backend_proto_lib",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//rslib:backend_proto_lib"],
|
||||
)
|
||||
|
||||
# Anki Library
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
"license": "AGPL-3.0-or-later",
|
||||
"description": "Anki JS support files",
|
||||
"devDependencies": {
|
||||
"@bazel/labs": "=3.0.0",
|
||||
"@bazel/rollup": "=3.0.0",
|
||||
"@bazel/typescript": "=3.0.0",
|
||||
"@pyoner/svelte-types": "^3.4.4-2",
|
||||
|
@ -26,27 +25,33 @@
|
|||
"@types/react-dom": "^16.9.8",
|
||||
"@typescript-eslint/eslint-plugin": "^2.11.0",
|
||||
"@typescript-eslint/parser": "^2.11.0",
|
||||
"chalk": "^4.1.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"diff": "^5.0.0",
|
||||
"escodegen": "^2.0.0",
|
||||
"eslint": "^6.7.2",
|
||||
"espree": "^7.3.1",
|
||||
"estraverse": "^5.2.0",
|
||||
"glob": "^7.1.6",
|
||||
"jsdoc": "^3.6.6",
|
||||
"license-checker-rseidelsohn": "=1.1.2",
|
||||
"patch-package": "^6.2.2",
|
||||
"minimist": "^1.2.5",
|
||||
"prettier": "^2.1.2",
|
||||
"prettier-plugin-svelte": "^1.4.0",
|
||||
"protobufjs-cli-taylorm": "^7.0.4",
|
||||
"protobufjs-taylorm": "^7.0.4",
|
||||
"rollup": "^2.32.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"sass": "^1.32.6",
|
||||
"semver": "^7.3.4",
|
||||
"svelte": "^3.28.0",
|
||||
"svelte-check": "^1.0.61",
|
||||
"svelte2tsx": "^0.1.133",
|
||||
"tmp": "^0.2.1",
|
||||
"tslib": "^2.0.3",
|
||||
"typescript": "^3.9.7"
|
||||
"typescript": "^3.9.7",
|
||||
"uglify-js": "^3.13.1"
|
||||
},
|
||||
"scripts": {
|
||||
"fix": "prettier --write */*.ts */*.svelte",
|
||||
"postinstall": "patch-package"
|
||||
"fix": "prettier --write */*.ts */*.svelte"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluent/bundle": "^0.15.1",
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
diff --git a/node_modules/@bazel/labs/protobufjs/ts_proto_library.bzl b/node_modules/@bazel/labs/protobufjs/ts_proto_library.bzl
|
||||
index fec29b6..fc77192 100755
|
||||
--- a/node_modules/@bazel/labs/protobufjs/ts_proto_library.bzl
|
||||
+++ b/node_modules/@bazel/labs/protobufjs/ts_proto_library.bzl
|
||||
@@ -15,7 +15,16 @@
|
||||
|
||||
load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "JSEcmaScriptModuleInfo", "JSModuleInfo", "JSNamedModuleInfo")
|
||||
|
||||
-def _run_pbjs(actions, executable, var, output_name, proto_files, suffix = ".js", wrap = "default", amd_name = ""):
|
||||
+def _run_pbjs(
|
||||
+ actions,
|
||||
+ executable,
|
||||
+ var,
|
||||
+ output_name,
|
||||
+ proto_files,
|
||||
+ suffix = ".js",
|
||||
+ wrap = "default",
|
||||
+ amd_name = "",
|
||||
+ target = "static-module"):
|
||||
js_file = actions.declare_file(output_name + suffix)
|
||||
|
||||
# Create an intermediate file so that we can do some manipulation of the
|
||||
@@ -25,9 +34,8 @@ def _run_pbjs(actions, executable, var, output_name, proto_files, suffix = ".js"
|
||||
# Reference of arguments:
|
||||
# https://github.com/dcodeIO/ProtoBuf.js/#pbjs-for-javascript
|
||||
args = actions.args()
|
||||
- args.add_all(["--target", "static-module"])
|
||||
+ args.add_all(["--target", target])
|
||||
args.add_all(["--wrap", wrap])
|
||||
- args.add("--strict-long") # Force usage of Long type with int64 fields
|
||||
args.add_all(["--out", js_file.path + ".tmpl"])
|
||||
args.add_all(proto_files)
|
||||
|
||||
@@ -106,6 +114,7 @@ def _ts_proto_library(ctx):
|
||||
sources,
|
||||
suffix = ".mjs",
|
||||
wrap = "es6",
|
||||
+ target = "json-module",
|
||||
)
|
||||
|
||||
# pbts doesn't understand '.mjs' extension so give it the es5 file
|
124
ts/protobuf.bzl
Normal file
124
ts/protobuf.bzl
Normal file
|
@ -0,0 +1,124 @@
|
|||
# taken from example on
|
||||
# https://github.com/bazelbuild/rules_nodejs/commit/078243a217afe85a8c8f449838bb66ca87608aba
|
||||
# tweaked to use json-module instead of static-module, and disable strict long
|
||||
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||
|
||||
# TODO switch to protobufjs-cli when its published
|
||||
# https://github.com/protobufjs/protobuf.js/commit/da34f43ccd51ad97017e139f137521782f5ef119
|
||||
load("@npm//protobufjs:index.bzl", "pbjs", "pbts")
|
||||
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
|
||||
|
||||
# protobuf.js relies on these packages, but does not list them as dependencies
|
||||
# in its package.json.
|
||||
# Instead they are listed under "cliDependencies"
|
||||
# (see https://unpkg.com/protobufjs@6.10.2/package.json)
|
||||
# When run, the CLI attempts to run `npm install` at runtime to get them.
|
||||
# This fails under Bazel as it tries to access the npm cache outside of the sandbox.
|
||||
# Per Bazel semantics, all dependencies should be pre-declared.
|
||||
# Note, you'll also need to install all of these in your package.json!
|
||||
# (This should be fixed when we switch to protobufjs-cli)
|
||||
_PROTOBUFJS_CLI_DEPS = ["@npm//%s" % s for s in [
|
||||
"chalk",
|
||||
"escodegen",
|
||||
"espree",
|
||||
"estraverse",
|
||||
"glob",
|
||||
"jsdoc",
|
||||
"minimist",
|
||||
"semver",
|
||||
"tmp",
|
||||
"uglify-js",
|
||||
]]
|
||||
|
||||
def _proto_sources_impl(ctx):
|
||||
return DefaultInfo(files = ctx.attr.proto[ProtoInfo].transitive_sources)
|
||||
|
||||
_proto_sources = rule(
|
||||
doc = """Provider Adapter from ProtoInfo to DefaultInfo.
|
||||
Extracts the transitive_sources from the ProtoInfo provided by the proto attr.
|
||||
This allows a macro to access the complete set of .proto files needed during compilation.
|
||||
""",
|
||||
implementation = _proto_sources_impl,
|
||||
attrs = {"proto": attr.label(providers = [ProtoInfo])},
|
||||
)
|
||||
|
||||
def protobufjs_library(name, proto, **kwargs):
|
||||
"""Minimal wrapper macro around pbjs/pbts tooling
|
||||
Args:
|
||||
name: name of generated js_library target, also used to name the .js/.d.ts outputs
|
||||
proto: label of a single proto_library target to generate for
|
||||
**kwargs: passed through to the js_library
|
||||
"""
|
||||
|
||||
js_static_out = name + "_static.js"
|
||||
js_out = name + ".js"
|
||||
ts_out = js_out.replace(".js", ".d.ts")
|
||||
|
||||
# Generate some target names, based on the provided name
|
||||
# (so that they are unique if the macro is called several times in one package)
|
||||
proto_target = "_%s_protos" % name
|
||||
js_target = "_%s_pbjs" % name
|
||||
js_static_target = js_target + "_static"
|
||||
ts_target = "_%s_pbts" % name
|
||||
|
||||
# grab the transitive .proto files needed to compile the given one
|
||||
_proto_sources(
|
||||
name = proto_target,
|
||||
proto = proto,
|
||||
)
|
||||
|
||||
# Build static module, which we need for pbjs
|
||||
pbjs(
|
||||
name = js_static_target,
|
||||
data = [proto_target] + _PROTOBUFJS_CLI_DEPS,
|
||||
# Arguments documented at
|
||||
# https://github.com/protobufjs/protobuf.js/tree/6.8.8#pbjs-for-javascript
|
||||
args = [
|
||||
"--target=static-module",
|
||||
"--wrap=default",
|
||||
#"--strict-long", # Force usage of Long type with int64 fields
|
||||
"--out=$@",
|
||||
"$(execpaths %s)" % proto_target,
|
||||
],
|
||||
outs = [js_static_out],
|
||||
)
|
||||
|
||||
# Build json module, which we'll use in our code.
|
||||
pbjs(
|
||||
name = js_target,
|
||||
data = [proto_target] + _PROTOBUFJS_CLI_DEPS,
|
||||
# Arguments documented at
|
||||
# https://github.com/protobufjs/protobuf.js/tree/6.8.8#pbjs-for-javascript
|
||||
args = [
|
||||
"--target=json-module",
|
||||
"--wrap=default",
|
||||
#"--strict-long", # Force usage of Long type with int64 fields
|
||||
"--out=$@",
|
||||
"$(execpaths %s)" % proto_target,
|
||||
],
|
||||
outs = [js_out],
|
||||
)
|
||||
|
||||
# Transform the _pb.js file to a .d.ts file with TypeScript types
|
||||
pbts(
|
||||
name = ts_target,
|
||||
data = [js_static_target] + _PROTOBUFJS_CLI_DEPS,
|
||||
# Arguments documented at
|
||||
# https://github.com/protobufjs/protobuf.js/tree/6.8.8#pbts-for-typescript
|
||||
args = [
|
||||
"--out=$@",
|
||||
"$(execpath %s)" % js_static_target,
|
||||
],
|
||||
outs = [ts_out],
|
||||
)
|
||||
|
||||
# Expose the results as js_library which provides DeclarationInfo for interop with other rules
|
||||
js_library(
|
||||
name = name,
|
||||
srcs = [
|
||||
js_target,
|
||||
ts_target,
|
||||
],
|
||||
**kwargs
|
||||
)
|
836
ts/yarn.lock
836
ts/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue