Skip to content
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: release 7.0.0 #2

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3d29969
fix: make parsedOptions appear in method JSON representation (#1506)
alexander-fenster Nov 13, 2020
aea41b8
chore: release 6.10.2 (#1454)
release-please[bot] Nov 16, 2020
08855f6
build(deps): bump bl from 1.2.2 to 1.2.3 (#1510)
dependabot[bot] Dec 1, 2020
e8860ab
chore(deps): update dependency gulp-sourcemaps to v3 (#1508)
renovate[bot] Dec 1, 2020
52d4f00
build: use action for publishing (#1518)
bcoe Dec 7, 2020
b4cae07
fix!: encoding of empty Buffers (#1514)
vicb Dec 7, 2020
da34f43
feat!: move command line tool to a new package named protobufjs-cli (…
taylorcode Jan 16, 2021
7f46dbe
fix: typo in pbjs help text (#1552)
MikeRalphson Mar 12, 2021
95b5681
deps(security): address elliptic security warning (#1564)
bcoe Mar 13, 2021
40a6b35
docs: fix pbjs link in README (#1578)
senthilkumarkj Apr 9, 2021
d01394a
feat: add --no-service option for pbjs static target (#1577)
mdouglass Apr 14, 2021
94e9ef0
deps: set @types/node to >= (#1575)
indutny Apr 14, 2021
6c4d307
feat: proto3 optional support (#1584)
alexander-fenster Apr 15, 2021
90afe44
fix: fromObject should not initialize oneof members (#1597)
alexander-fenster Apr 29, 2021
af1b449
fix: allow for an optional semicolon where there is an optional comma…
jeffory-orrok Apr 29, 2021
57fc524
Fix typo in roots.js (#1608)
eltociear May 3, 2021
9011aac
fix: handling properly fields with leading and trailing comments afte…
ykolbin May 8, 2021
6e713ba
feat: add null-defaults option (#1611)
sloonz May 8, 2021
f5b893c
fix: support for options with `repeated_value: [ "foo", "bar" ]` (#1574)
doochik May 14, 2021
d13d5d5
feat: add getTypeUrl method to generated code (#1463)
taylorcode May 21, 2021
2170c78
chore: release 7.0.0
github-actions[bot] Feb 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed .github/publish.yml
Empty file.
2 changes: 0 additions & 2 deletions .github/release-please.yml

This file was deleted.

88 changes: 88 additions & 0 deletions .github/workflows/release-submodule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
on:
push:
branches:
- master
name: release-please-monorepo
jobs:
changeFinder:
runs-on: ubuntu-latest
outputs:
nodePaths: ${{ steps.interrogate.outputs.nodePaths }}
steps:
- uses: actions/checkout@v2
- id: interrogate
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const allowlist = ['cli'];
const {execSync} = require('child_process');
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const latestRelease = await github.repos.getLatestRelease({
owner,
repo
});
console.log(`latest release: ${latestRelease.data.tag_name}`);
execSync('git pull --tags');
execSync(`git reset --hard ${latestRelease.data.tag_name}`);
const status = execSync(`git diff --name-only origin/master`, { encoding: 'utf-8'});
console.log(status);
const changes = status.split('\n');
let nodePaths = new Set();
for (const change of changes) {
const library = change.split('/')[0];
if (allowlist.includes(library)) {
nodePaths.add(library);
}
}
nodePaths = Array.from(nodePaths);
console.log(`::set-output name=nodePaths::${JSON.stringify(nodePaths)}`);
release-pr:
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.changeFinder.outputs.nodePaths)}}
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: release-please
with:
path: ${{ matrix.package }}
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: ${{ matrix.package }}
monorepo-tags: true
command: release-pr
release-please-release:
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
package: ${{fromJson(needs.changeFinder.outputs.nodePaths)}}
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: tag-release
with:
path: ${{ matrix.package }}
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
monorepo-tags: true
package-name: ${{ matrix.package }}
command: github-release
- uses: actions/checkout@v2
if: ${{ steps.tag-release.outputs.release_created }}
- uses: actions/setup-node@v1
if: ${{ steps.tag-release.outputs.release_created }}
with:
node-version: 14
registry-url: 'https://wombat-dressing-room.appspot.com/'
- name: publish
if: ${{ steps.tag-release.outputs.release_created }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_SUBMODULE_TOKEN}}
run: |
cd ${{ matrix.package }}
npm install
npm publish --access=public
40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- master
name: release-please
jobs:
release-please-pr:
runs-on: ubuntu-latest
steps:
- id: release-pr
uses: GoogleCloudPlatform/release-please-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: protobufjs
command: release-pr
release-please-release:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: tag-release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: protobufjs
command: github-release
- uses: actions/checkout@v2
if: ${{ steps.tag-release.outputs.release_created }}
- uses: actions/setup-node@v1
if: ${{ steps.tag-release.outputs.release_created }}
with:
node-version: 14
registry-url: 'https://wombat-dressing-room.appspot.com/'
- name: publish
if: ${{ steps.tag-release.outputs.release_created }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: |
npm install
npm publish
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
node-version: "12"
- name: "Install dependencies"
run: npm install
run: npm install && (cd cli && npm install)
- name: "Build distribution files"
run: npm run build
test:
Expand Down
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Changelog

## [7.0.0](https://www.github.com/jawid-h/protobuf.js/compare/v6.10.2...v7.0.0) (2022-02-28)


### ⚠ BREAKING CHANGES

* move command line tool to a new package named protobufjs-cli (#1234)
* encoding of empty Buffers (#1514)

### Features

* add --no-service option for pbjs static target ([#1577](https://www.github.com/jawid-h/protobuf.js/issues/1577)) ([d01394a](https://www.github.com/jawid-h/protobuf.js/commit/d01394a1463062824c066b653aad53c449752202))
* add getTypeUrl method to generated code ([#1463](https://www.github.com/jawid-h/protobuf.js/issues/1463)) ([d13d5d5](https://www.github.com/jawid-h/protobuf.js/commit/d13d5d5688052e366aa2e9169f50dfca376b32cf))
* add null-defaults option ([#1611](https://www.github.com/jawid-h/protobuf.js/issues/1611)) ([6e713ba](https://www.github.com/jawid-h/protobuf.js/commit/6e713baf54bd987ae52cbf92a4f2742c70201dc0))
* move command line tool to a new package named protobufjs-cli ([#1234](https://www.github.com/jawid-h/protobuf.js/issues/1234)) ([da34f43](https://www.github.com/jawid-h/protobuf.js/commit/da34f43ccd51ad97017e139f137521782f5ef119))
* proto3 optional support ([#1584](https://www.github.com/jawid-h/protobuf.js/issues/1584)) ([6c4d307](https://www.github.com/jawid-h/protobuf.js/commit/6c4d30716a9a756dcdc21d64f9c9d069315fc5b1))


### Bug Fixes

* allow for an optional semicolon where there is an optional comma in parseOptionValue ([#1571](https://www.github.com/jawid-h/protobuf.js/issues/1571)) ([af1b449](https://www.github.com/jawid-h/protobuf.js/commit/af1b449602b360091e191a58abde2f246d8b0f1d))
* encoding of empty Buffers ([#1514](https://www.github.com/jawid-h/protobuf.js/issues/1514)) ([b4cae07](https://www.github.com/jawid-h/protobuf.js/commit/b4cae07440387399e097058e15e50608a0e764fd)), closes [#1500](https://www.github.com/jawid-h/protobuf.js/issues/1500) [#885](https://www.github.com/jawid-h/protobuf.js/issues/885)
* fromObject should not initialize oneof members ([#1597](https://www.github.com/jawid-h/protobuf.js/issues/1597)) ([90afe44](https://www.github.com/jawid-h/protobuf.js/commit/90afe4412de8070b0c0681e5905a6e0213072a85))
* handling properly fields with leading and trailing comments after field with trailing comment ([#1593](https://www.github.com/jawid-h/protobuf.js/issues/1593)) ([9011aac](https://www.github.com/jawid-h/protobuf.js/commit/9011aac161e1bf8eaa3cbf0f17e8f321b6e0d9c4))
* support for options with `repeated_value: [ "foo", "bar" ]` ([#1574](https://www.github.com/jawid-h/protobuf.js/issues/1574)) ([f5b893c](https://www.github.com/jawid-h/protobuf.js/commit/f5b893c03e9694bbe7da7c4001cc74b06039eb9c))
* typo in pbjs help text ([#1552](https://www.github.com/jawid-h/protobuf.js/issues/1552)) ([7f46dbe](https://www.github.com/jawid-h/protobuf.js/commit/7f46dbeb538a6277035a896e1ab5e1a070e28681))

### [6.10.2](https://www.github.com/protobufjs/protobuf.js/compare/v6.10.1...v6.10.2) (2020-11-13)


### Bug Fixes

* es6 export enum ([#1446](https://www.github.com/protobufjs/protobuf.js/issues/1446)) ([9f33784](https://www.github.com/protobufjs/protobuf.js/commit/9f33784350b1efc2e774bbfc087cbd2c47828748))
* make parsedOptions appear in method JSON representation ([#1506](https://www.github.com/protobufjs/protobuf.js/issues/1506)) ([3d29969](https://www.github.com/protobufjs/protobuf.js/commit/3d29969865f2119550d9dc88391846469da9fa7f))
* utf8 -> utf16 decoding bug on surrogate pairs ([#1486](https://www.github.com/protobufjs/protobuf.js/issues/1486)) ([75172cd](https://www.github.com/protobufjs/protobuf.js/commit/75172cd11be137bbabd2fba7a02b15067695ebad))

### [6.10.1](https://www.github.com/protobufjs/protobuf.js/compare/v6.10.0...v6.10.1) (2020-07-16)


Expand Down
181 changes: 7 additions & 174 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ Contents
* [Using services](#using-services)
* [Usage with TypeScript](#usage-with-typescript)<br />

* [Command line](#command-line)<br />
How to use the command line utility.

* [pbjs for JavaScript](#pbjs-for-javascript)
* [pbts for TypeScript](#pbts-for-typescript)
* [Reflection vs. static code](#reflection-vs-static-code)
* [Command line API](#command-line-api)<br />

* [Additional documentation](#additional-documentation)<br />
A list of available documentation resources.

Expand All @@ -60,6 +52,12 @@ $> npm install protobufjs [--save --save-prefix=~]
var protobuf = require("protobufjs");
```

The command line utility lives in the protobufjs-cli package and must be installed separately:

```
$> npm install protobufjs-cli [--save --save-prefix=~]
```

**Note** that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on `~6.A.B` instead of `^6.A.B` (hence the `--save-prefix` above).

### Browsers
Expand All @@ -84,7 +82,7 @@ The library supports CommonJS and AMD loaders and also exports globally as `prot

Where bundle size is a factor, there are additional stripped-down versions of the [full library][dist-full] (~19kb gzipped) available that exclude certain functionality:

* When working with JSON descriptors (i.e. generated by [pbjs](#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
* When working with JSON descriptors (i.e. generated by [pbjs](cli/README.md#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:

```js
var protobuf = require("protobufjs/light");
Expand Down Expand Up @@ -597,171 +595,6 @@ Other notes:

**ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/dcodeIO/protobuf.js/blob/master/examples/js-decorators.js) as well.

Command line
------------

**Note** that moving the CLI to [its own package](./cli) is a work in progress. At the moment, it's still part of the main package.

The command line interface (CLI) can be used to translate between file formats and to generate static code as well as TypeScript definitions.

### pbjs for JavaScript

```
Translates between file formats and generates static code.

-t, --target Specifies the target format. Also accepts a path to require a custom target.

json JSON representation
json-module JSON representation as a module
proto2 Protocol Buffers, Version 2
proto3 Protocol Buffers, Version 3
static Static code without reflection (non-functional on its own)
static-module Static code without reflection as a module

-p, --path Adds a directory to the include path.

-o, --out Saves to a file instead of writing to stdout.

--sparse Exports only those types referenced from a main file (experimental).

Module targets only:

-w, --wrap Specifies the wrapper to use. Also accepts a path to require a custom wrapper.

default Default wrapper supporting both CommonJS and AMD
commonjs CommonJS wrapper
amd AMD wrapper
es6 ES6 wrapper (implies --es6)
closure A closure adding to protobuf.roots where protobuf is a global

-r, --root Specifies an alternative protobuf.roots name.

-l, --lint Linter configuration. Defaults to protobuf.js-compatible rules:

eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins

--es6 Enables ES6 syntax (const/let instead of var)

Proto sources only:

--keep-case Keeps field casing instead of converting to camel case.

Static targets only:

--no-create Does not generate create functions used for reflection compatibility.
--no-encode Does not generate encode functions.
--no-decode Does not generate decode functions.
--no-verify Does not generate verify functions.
--no-convert Does not generate convert functions like from/toObject
--no-delimited Does not generate delimited encode/decode functions.
--no-beautify Does not beautify generated code.
--no-comments Does not output any JSDoc comments.

--force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
--force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
--force-message Enforces the use of message instances instead of plain objects.

usage: pbjs [options] file1.proto file2.json ... (or pipe) other | pbjs [options] -
```

For production environments it is recommended to bundle all your .proto files to a single .json file, which minimizes the number of network requests and avoids any parser overhead (hint: works with just the **light** library):

```
$> pbjs -t json file1.proto file2.proto > bundle.json
```

Now, either include this file in your final bundle:

```js
var root = protobuf.Root.fromJSON(require("./bundle.json"));
```

or load it the usual way:

```js
protobuf.load("bundle.json", function(err, root) {
...
});
```

Generated static code, on the other hand, works with just the **minimal** library. For example

```
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
```

will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`.

**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.


### pbts for TypeScript

```
Generates TypeScript definitions from annotated JavaScript files.

-o, --out Saves to a file instead of writing to stdout.

-g, --global Name of the global object in browser environments, if any.

--no-comments Does not output any JSDoc comments.

Internal flags:

-n, --name Wraps everything in a module of the specified name.

-m, --main Whether building the main library without any imports.

usage: pbts [options] file1.js file2.js ... (or) other | pbts [options] -
```

Picking up on the example above, the following not only generates static code to a CommonJS module `compiled.js` but also its respective TypeScript definitions to `compiled.d.ts`:

```
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
$> pbts -o compiled.d.ts compiled.js
```

Additionally, TypeScript definitions of static modules are compatible with their reflection-based counterparts (i.e. as exported by JSON modules), as long as the following conditions are met:

1. Instead of using `new SomeMessage(...)`, always use `SomeMessage.create(...)` because reflection objects do not provide a constructor.
2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well (i.e. to be able to use `MyMessage.MyEnum` instead of `root.lookup("MyMessage.MyEnum")`).

For example, the following generates a JSON module `bundle.js` and a `bundle.d.ts`, but no static code:

```
$> pbjs -t json-module -w commonjs -o bundle.js file1.proto file2.proto
$> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
```

### Reflection vs. static code

While using .proto files directly requires the full library respectively pure reflection/JSON the light library, pretty much all code but the relatively short descriptors is shared.

Static code, on the other hand, requires just the minimal library, but generates additional source code without any reflection features. This also implies that there is a break-even point where statically generated code becomes larger than descriptor-based code once the amount of code generated exceeds the size of the full respectively light library.

There is no significant difference performance-wise as the code generated statically is pretty much the same as generated at runtime and both are largely interchangeable as seen in the previous section.

| Source | Library | Advantages | Tradeoffs
|--------|---------|------------|-----------
| .proto | full | Easily editable<br />Interoperability with other libraries<br />No compile step | Some parsing and possibly network overhead
| JSON | light | Easily editable<br />No parsing overhead<br />Single bundle (no network overhead) | protobuf.js specific<br />Has a compile step
| static | minimal | Works where `eval` access is restricted<br />Fully documented<br />Small footprint for small protos | Can be hard to edit<br />No reflection<br />Has a compile step

### Command line API

Both utilities can be used programmatically by providing command line arguments and a callback to their respective `main` functions:

```js
var pbjs = require("protobufjs/cli/pbjs"); // or require("protobufjs/cli").pbjs / .pbts

pbjs.main([ "--target", "json-module", "path/to/myproto.proto" ], function(err, output) {
if (err)
throw err;
// do something with output
});
```

Additional documentation
------------------------

Expand Down
6 changes: 0 additions & 6 deletions bin/pbjs

This file was deleted.

Loading