@bufbuild/protoc-gen-es 0.0.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -26
- package/dist/cjs/package.json +4 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
# @bufbuild/protoc-gen-es
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Protocol Buffers for ECMAScript
|
|
7
|
-
|
|
8
|
-
A complete implementation of [Protocol Buffers](https://developers.google.com/protocol-buffers)
|
|
9
|
-
in TypeScript, suitable for web browsers and Node.js.
|
|
10
|
-
|
|
11
|
-
For example, the following definition:
|
|
3
|
+
The code generator for Protocol Buffers for ECMAScript. For example, the
|
|
4
|
+
following definition:
|
|
12
5
|
|
|
13
6
|
```protobuf
|
|
14
7
|
message Person {
|
|
@@ -31,45 +24,92 @@ pete = Person.fromBinary(bytes);
|
|
|
31
24
|
pete = Person.fromJsonString('{"name": "pete", "id": 123}');
|
|
32
25
|
```
|
|
33
26
|
|
|
34
|
-
Learn more at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
27
|
+
Learn more about the project at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
35
28
|
|
|
36
29
|
|
|
37
30
|
## Installation
|
|
38
31
|
|
|
39
|
-
|
|
32
|
+
`protoc-gen-es` is a code generator plugin for Protocol Buffer compilers,
|
|
33
|
+
like [buf](https://github.com/bufbuild/buf) and [protoc](https://github.com/protocolbuffers/protobuf/releases).
|
|
34
|
+
It generates base types - messages and enumerations - from your Protocol Buffer
|
|
35
|
+
schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
|
|
36
|
+
|
|
37
|
+
To install the plugin and the runtime library, run:
|
|
40
38
|
|
|
41
39
|
```shell
|
|
42
|
-
npm install @bufbuild/protoc-gen-es
|
|
40
|
+
npm install --save-dev @bufbuild/protoc-gen-es
|
|
41
|
+
npm install @bufbuild/protobuf
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
We use peer dependencies to ensure that code generator and runtime library are
|
|
45
|
+
compatible with each other. Note that yarn and pnpm only emit a warning in this case.
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
|
|
48
|
+
## Generating code
|
|
49
|
+
|
|
50
|
+
### With buf
|
|
51
|
+
|
|
52
|
+
Add a new configuration file `buf.gen.yaml`:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
# buf.gen.yaml defines a local generation template.
|
|
56
|
+
# For details, see https://docs.buf.build/configuration/v1/buf-gen-yaml
|
|
57
|
+
version: v1
|
|
58
|
+
plugins:
|
|
59
|
+
# This will invoke protoc-gen-es and write output to src/gen
|
|
60
|
+
- name: es
|
|
61
|
+
out: src/gen
|
|
62
|
+
opt: target=ts
|
|
50
63
|
```
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
Add the following script to your `package.json`:
|
|
53
66
|
|
|
54
|
-
```
|
|
55
|
-
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"name": "your-package",
|
|
70
|
+
"version": "1.0.0",
|
|
71
|
+
"scripts": {
|
|
72
|
+
"generate": "buf generate"
|
|
73
|
+
},
|
|
74
|
+
// ...
|
|
75
|
+
}
|
|
56
76
|
```
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
where yarn stores the executable, run `yarn bin protoc-gen-es` (it is "unplugged"
|
|
60
|
-
automatically).
|
|
78
|
+
To generate code for all protobuf files within your project, simply run:
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
```bash
|
|
81
|
+
npm run generate
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Note that `buf` can generate from various [inputs](https://docs.buf.build/reference/inputs),
|
|
85
|
+
not just local protobuf files.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### With protoc
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
PATH=$PATH:$(pwd)/node_modules/.bin \
|
|
92
|
+
protoc -I . \
|
|
93
|
+
--es_out src/gen \
|
|
94
|
+
--es_opt target=ts \
|
|
95
|
+
a.proto b.proto c.proto
|
|
65
96
|
```
|
|
66
97
|
|
|
98
|
+
Note that we are adding `node_modules/.bin` to the `$PATH`, so that the protocol
|
|
99
|
+
buffer compiler can find them. This happens automatically with npm scripts.
|
|
100
|
+
|
|
101
|
+
Since yarn v2 and above does not use a `node_modules` directory, you need to
|
|
102
|
+
change the variable a bit:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
|
|
106
|
+
```
|
|
67
107
|
|
|
68
108
|
## Plugin options
|
|
69
109
|
|
|
70
110
|
### `target`
|
|
71
111
|
|
|
72
|
-
This option controls whether the plugin generates JavaScript, TypeScript,
|
|
112
|
+
This option controls whether the plugin generates JavaScript, TypeScript,
|
|
73
113
|
or TypeScript declaration files.
|
|
74
114
|
|
|
75
115
|
Possible values:
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rm -rf ./dist/cjs/*",
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs"
|
|
20
20
|
},
|
|
21
21
|
"preferUnplugged": true,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bufbuild/protoplugin": "
|
|
23
|
+
"@bufbuild/protoplugin": "0.1.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "
|
|
26
|
+
"@bufbuild/protobuf": "0.1.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@bufbuild/protobuf": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rm -rf ./dist/cjs/*",
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs"
|
|
20
20
|
},
|
|
21
21
|
"preferUnplugged": true,
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bufbuild/protoplugin": "
|
|
23
|
+
"@bufbuild/protoplugin": "0.1.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "
|
|
26
|
+
"@bufbuild/protobuf": "0.1.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@bufbuild/protobuf": {
|