Skip to content

Commit

Permalink
refactor: deprecate index.bzl (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Sep 27, 2023
1 parent 37feb71 commit 0393598
Show file tree
Hide file tree
Showing 59 changed files with 4,999 additions and 3,341 deletions.
3 changes: 0 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ build --incompatible_strict_action_env
run --incompatible_strict_action_env
test --incompatible_strict_action_env

build --deleted_packages=examples/bazel
query --deleted_packages=examples/bazel

try-import %workspace%/user.bazelrc
4 changes: 4 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ build --noshow_progress
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
test --test_output=errors

# This directory is configured in GitHub actions to be persisted between runs.
common --disk_cache=~/.cache/bazel/disk
common --repository_cache=~/.cache/bazel/repo
4 changes: 1 addition & 3 deletions .github/workflows/ci.nix.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# This directory is configured in GitHub actions to be persisted between runs.
build --disk_cache=~/.cache/bazel
build --repository_cache=~/.cache/bazel-repo

1 change: 1 addition & 0 deletions .github/workflows/ci.windows.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# This directory is configured in GitHub actions to be persisted between runs.
startup --output_user_root=C:/tmp
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
push:
tags:
- "*.*.*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: bazel build package
- run: rsync --copy-links --recursive --times --group --no-perms --chmod=ugo=rwX ./bazel-bin/package/package/ ./tmp_pkg
- run: npm version ${{ github.ref_name }}
working-directory: ./tmp_pkg
- run: npm publish --dry-run
working-directory: ./tmp_pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASE_TOKEN }}
24 changes: 15 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node_version: [14.x, 16.x]
os: [ubuntu-latest, windows-latest]
node_version: [16.x, 18.x, 20.x]
protoc_version: [3.x]
folder:
- '.'
- 'examples/grpc'
- 'examples/pure'
exclude:
- os: windows-latest
node_version: 16.x
- os: windows-latest
node_version: 18.x
- os: windows-latest
folder: .

steps:
- uses: actions/checkout@v2
Expand All @@ -39,25 +47,23 @@ jobs:
with:
path: |
"~/.cache/bazel"
"~/.cache/bazel-repo"
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-

- run: |
type .github/workflows/ci.bazelrc >> user.bazelrc
type .github/workflows/ci.windows.bazelrc >> user.bazelrc
Add-Content user.bazelrc "`ntest --test_tag_filters=-no-${{ matrix.os }}"
if: ${{ matrix.os == 'windows-latest' }}
- run: |
cat .github/workflows/ci.bazelrc >> user.bazelrc
cat .github/workflows/ci.nix.bazelrc >> user.bazelrc
echo "test --test_tag_filters=-no-${{ matrix.os }}" >> user.bazelrc
if: ${{ matrix.os != 'windows-latest' }}
- name: install dependencies
run: yarn --frozen-lockfile
- run: npm ci && npm rebuild
working-directory: ${{ matrix.folder }}
if: ${{ matrix.folder != '.' }}

- name: test
run: yarn test --test_tag_filters=-no-${{ matrix.os }}
- run: npm test
working-directory: ${{ matrix.folder }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ bazel-*

.DS_Store
user.bazelrc

tmp_pkg
23 changes: 4 additions & 19 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@bazel_gazelle//:def.bzl", "gazelle")

package(default_visibility = ["//visibility:public"])
exports_files(["README.md"])

# gazelle:prefix github.com/thesayyn/protoc-gen-ts
gazelle(name = "gazelle")

gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-from_file=private/go.mod",
"-to_macro=private/deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)

pkg_npm(
name = "package",
package_name = "protoc-gen-ts",
srcs = [
"README.md",
"index.bzl",
"package.json",
"//bin:protoc-gen-ts.js",
],
deps = [
"//src:pkg",
],
)
)
45 changes: 15 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

Compile `.proto` files to plain TypeScript. Supports gRPC Node and gRPC Web.

## Key Differences
## Usage

- No `d.ts` files. Just plain typescript sources with actual code.
- Fields as **getter** **setters**.
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)
- **fromObject** and **toObject** methods to work with json data.
- Support for gRPC Node and gRPC Web.
- You get what you define in proto files. No such prefixes as "getField" or "getFieldList".
- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).
```properties
npm install -g protoc-gen-ts

protoc -I=sourcedir --ts_out=dist myproto.proto
```

## Example

Expand Down Expand Up @@ -97,37 +94,25 @@ const change = Change.fromObject({
console.log(change.author instanceof Author) // true
```


## Usage with `@grpc/grpc-js` or `grpc`

There is a seperate documentation for the usage of protoc-gen-ts along with either `@grpc/grpc-js` or `grpc`. By default
this generated gRPC interfaces will use `@grpc/grpc-js`.

Checkout [rpcs](docs/rpc.md).

## Usage

### Without Bazel
```properties
npm install -g protoc-gen-ts

protoc -I=sourcedir --ts_out=dist myproto.proto
```
### With Bazel
```py
# Add protoc-gen-ts to dependencies section of your package.json file.

load("@npm//protoc-gen-ts:index.bzl", "ts_proto_library")
## Key Differences

ts_proto_library(
name = "protos",
deps = [
":some_proto_library_target"
]
)
- No `d.ts` files. Just plain typescript sources with actual code.
- Fields as **getter** **setters**.
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)
- **fromObject** and **toObject** methods to work with json data.
- Support for gRPC Node and gRPC Web.
- You get what you define in proto files. No such prefixes as "getField" or "getFieldList".
- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).

# Checkout the examples/bazel directory for an example.
```

## Supported Options

Expand Down
11 changes: 5 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ http_archive(
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
build_bazel_rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
node_repositories(node_version = "16.3.0")

yarn_install(
npm_install(
name = "npm",
exports_directories_only = False,
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
package_lock_json = "//:package-lock.json",
)

load("@build_bazel_rules_nodejs//toolchains/cypress:cypress_repositories.bzl", "cypress_repositories")
Expand Down Expand Up @@ -74,8 +73,8 @@ http_archive(
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

load("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
load("//private:deps.bzl", "go_dependencies")
# gazelle:repository_macro private/deps.bzl%go_dependencies
go_dependencies()


Expand Down
21 changes: 0 additions & 21 deletions bin/BUILD.bazel

This file was deleted.

2 changes: 0 additions & 2 deletions bin/protoc-gen-ts.js

This file was deleted.

3 changes: 3 additions & 0 deletions examples/grpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
src/test.ts
48 changes: 0 additions & 48 deletions examples/grpc/BUILD.bazel

This file was deleted.

3 changes: 0 additions & 3 deletions examples/grpc/README.md

This file was deleted.

Loading

0 comments on commit 0393598

Please sign in to comment.