Skip to content

Commit

Permalink
feat(labs): ts_proto_library directly exports commonjs
Browse files Browse the repository at this point in the history
Removes direct interoperability with ts_library
Update to latest grpc-web protoc plugin
  • Loading branch information
Daniel Muller authored and alexeagle committed Jul 2, 2021
1 parent a9c5966 commit 5f26d0f
Show file tree
Hide file tree
Showing 31 changed files with 3,062 additions and 3,324 deletions.
2 changes: 0 additions & 2 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ example_integration_test(
name = "examples_protocol_buffers",
timeout = "long",
npm_packages = {
"//packages/concatjs:npm_package": "@bazel/concatjs",
"//packages/labs:npm_package": "@bazel/labs",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
"//packages/typescript:npm_package": "@bazel/typescript",
Expand Down
93 changes: 27 additions & 66 deletions examples/protocol_buffers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "karma_web_test_suite")
load("@npm//@bazel/labs:index.bzl", "ts_proto_library")
load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library")
load("@npm//http-server:index.bzl", "http_server")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@rules_proto//proto:defs.bzl", "proto_library")
load(":jest.bzl", "jest_test")

proto_library(
name = "tire_proto",
Expand Down Expand Up @@ -34,62 +32,59 @@ ts_proto_library(
proto = ":car_proto",
)

ts_config(
name = "tsconfig-test",
src = "tsconfig-test.json",
deps = [":tsconfig.json"],
)

ts_library(
ts_project(
name = "test_lib",
testonly = True,
srcs = ["car.spec.ts"],
tsconfig = "//:tsconfig-test",
deps = [
":car",
":tire",
"@npm//@types/jasmine",
"@npm//@types/google-protobuf",
"@npm//@types/jest",
"@npm//@types/node",
"@npm//grpc-web",
],
)

karma_web_test_suite(
jest_test(
name = "test",
srcs = [
"@npm//@bazel/labs/grpc_web:bootstrap_scripts",
"babel.config.js",
":car.spec.js",
],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
"@io_bazel_rules_webtesting//browsers:firefox-local",
jest_config = ":jest.config.js",
deps = [
":car",
":tire",
"@npm//@babel/core",
"@npm//@babel/preset-env",
"@npm//babel-jest",
"@npm//google-protobuf",
],
tags = ["native"],
deps = ["test_lib"],
)

ts_library(
ts_project(
name = "app",
srcs = ["app.ts"],
deps = [":car"],
)

concatjs_devserver(
name = "devserver",
entry_module = "examples_protocol_buffers/app",
scripts = ["@npm//@bazel/labs/grpc_web:bootstrap_scripts"],
deps = [":app"],
deps = [
":car",
"@npm//@types/google-protobuf",
"@npm//grpc-web",
],
)

# Test for production mode
rollup_bundle(
name = "bundle",
srcs = [
":tsconfig.json",
],
config_file = "rollup.config.js",
entry_point = ":app.ts",
format = "iife",
deps = [
":app",
"@npm//:node_modules",
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-node-resolve",
"@npm//@rollup/plugin-typescript",
],
)

Expand All @@ -98,26 +93,6 @@ terser_minified(
src = ":bundle",
)

http_server(
name = "prodserver",
data = [
"index.html",
":bundle.min",
],
)

ts_library(
name = "e2e",
testonly = 1,
srcs = ["app.e2e-spec.ts"],
tsconfig = ":tsconfig-test",
deps = [
"@npm//@types/jasmine",
"@npm//jasmine",
"@npm//protractor",
],
)

proto_library(
name = "rules_typescript_proto",
srcs = [
Expand All @@ -127,20 +102,6 @@ proto_library(
visibility = ["//visibility:public"],
)

protractor_web_test_suite(
name = "prodserver_test",
on_prepare = ":protractor.on-prepare.js",
server = "//:prodserver",
deps = [":e2e"],
)

protractor_web_test_suite(
name = "devserver_test",
on_prepare = ":protractor.on-prepare.js",
server = "//:devserver",
deps = [":e2e"],
)

# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test
sh_test(
name = "dummy_test",
Expand Down
28 changes: 4 additions & 24 deletions examples/protocol_buffers/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ http_archive(

http_archive(
name = "rules_proto",
sha256 = "9fc210a34f0f9e7cc31598d109b5d069ef44911a82f507d5a88716db171615a8",
strip_prefix = "rules_proto-f7a30f6f80006b591fa7c437fe5a951eb10bcbcf",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/f7a30f6f80006b591fa7c437fe5a951eb10bcbcf.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
],
)

Expand All @@ -49,16 +50,6 @@ yarn_install(
yarn_lock = "//:yarn.lock",
)

load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies")

npm_bazel_protractor_dependencies()

http_archive(
name = "io_bazel_rules_webtesting",
sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3",
urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"],
)

load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies")

npm_bazel_labs_dependencies()
Expand All @@ -69,17 +60,6 @@ rules_proto_dependencies()

rules_proto_toolchains()

load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()

load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")

browser_repositories(
chromium = True,
firefox = True,
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
29 changes: 0 additions & 29 deletions examples/protocol_buffers/app.e2e-spec.ts

This file was deleted.

12 changes: 12 additions & 0 deletions examples/protocol_buffers/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
8 changes: 0 additions & 8 deletions examples/protocol_buffers/index.html

This file was deleted.

23 changes: 23 additions & 0 deletions examples/protocol_buffers/jest.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"Shows how you might create a macro for the autogenerated Jest rule"

load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")

def jest_test(name, srcs, deps, jest_config, **kwargs):
"A macro around the autogenerated jest_test rule"
templated_args = [
"--no-cache",
"--no-watchman",
"--ci",
"--colors",
]
templated_args.extend(["--config", "$(rootpath %s)" % jest_config])
for src in srcs:
templated_args.extend(["--runTestsByPath", "$(rootpath %s)" % src])

data = [jest_config] + srcs + deps
_jest_test(
name = name,
data = data,
templated_args = templated_args,
**kwargs
)
10 changes: 10 additions & 0 deletions examples/protocol_buffers/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

module.exports = {
testEnvironment: 'node',
// explicitly specify the path to babel.config.js relative to jest.config.js so
// jest can find it even when jest.config.js is not in the root folder of the workspace
transform:
{ '^.+\\.[jt]sx?$': ['babel-jest', { configFile: path.resolve(__dirname, 'babel.config.js') }] },
testMatch: ['**/*.spec.js']
};
46 changes: 19 additions & 27 deletions examples/protocol_buffers/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
{
"devDependencies": {
"@bazel/concatjs": "^3.6.0",
"@bazel/labs": "^3.6.0",
"@bazel/protractor": "^3.6.0",
"@bazel/rollup": "^3.6.0",
"@bazel/terser": "^3.6.0",
"@bazel/typescript": "^3.6.0",
"@rollup/plugin-commonjs": "14.0.0",
"@rollup/plugin-node-resolve": "8.4.0",
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@bazel/labs": "3.6.0",
"@bazel/rollup": "3.6.0",
"@bazel/terser": "3.6.0",
"@bazel/typescript": "3.6.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/google-protobuf": "^3.15.2",
"@types/jasmine": "2.8.2",
"@types/jest": "^26.0.23",
"@types/long": "^4.0.0",
"@types/node": "11.11.1",
"google-protobuf": "3.11.4",
"grpc-web": "1.1.0",
"http-server": "^0.11.1",
"jasmine": "2.8.0",
"karma": "~4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-firefox-launcher": "1.1.0",
"karma-jasmine": "2.0.1",
"karma-requirejs": "1.1.0",
"karma-sourcemap-loader": "0.3.7",
"long": "4.0.0",
"protobufjs": "5.0.3",
"protractor": "^5.4.2",
"requirejs": "2.3.6",
"rollup": "2.3.4",
"terser": "4.3.1",
"typescript": "^3.3.1"
"@types/node": "^15.12.4",
"babel-jest": "^27.0.5",
"google-protobuf": "3.17.3",
"grpc-web": "1.2.1",
"jest": "^27.0.5",
"jest-cli": "^27.0.5",
"rollup": "2.52.2",
"terser": "5.7.0",
"typescript": "4.3.4"
},
"scripts": {
"test": "bazel test ..."
}
}
}
24 changes: 0 additions & 24 deletions examples/protocol_buffers/protractor.on-prepare.js

This file was deleted.

11 changes: 4 additions & 7 deletions examples/protocol_buffers/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const commonjs = require('@rollup/plugin-commonjs');
const {nodeResolve} = require('@rollup/plugin-node-resolve');
// rollup.config.js
import typescript from '@rollup/plugin-typescript';

module.exports = {
plugins: [
nodeResolve(),
commonjs(),
],
export default {
plugins: [typescript({ allowJs: true })],
};
Loading

0 comments on commit 5f26d0f

Please sign in to comment.