@bufbuild/protoc-gen-es 0.1.0 → 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 CHANGED
@@ -1,14 +1,7 @@
1
1
  # @bufbuild/protoc-gen-es
2
2
 
3
- This package provides the code generator plugin `protoc-gen-es`. The code it
4
- generates depends on [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
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
- ### With npm
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
- This will install the code generator plugin in `node_modules/.bin/protoc-gen-es`.
46
- Note that npm does not add the executable to your `$PATH`. You can do so with:
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
- ```shell
49
- PATH=$PATH:$(pwd)/node_modules/.bin
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
- ### With yarn
65
+ Add the following script to your `package.json`:
53
66
 
54
- ```shell
55
- yarn add @bufbuild/protoc-gen-es
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
- Note that yarn v2 does not use a `node_modules` directory anymore. To find the path
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
- You can always confirm successful installation with:
63
- ```shell
64
- protoc-gen-es --version
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:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Protocol Buffers code generator for ECMAScript",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "preferUnplugged": true,
22
22
  "dependencies": {
23
- "@bufbuild/protoplugin": "0.1.0"
23
+ "@bufbuild/protoplugin": "0.1.1"
24
24
  },
25
25
  "peerDependencies": {
26
- "@bufbuild/protobuf": "0.1.0"
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.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Protocol Buffers code generator for ECMAScript",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "preferUnplugged": true,
22
22
  "dependencies": {
23
- "@bufbuild/protoplugin": "0.1.0"
23
+ "@bufbuild/protoplugin": "0.1.1"
24
24
  },
25
25
  "peerDependencies": {
26
- "@bufbuild/protobuf": "0.1.0"
26
+ "@bufbuild/protobuf": "0.1.1"
27
27
  },
28
28
  "peerDependenciesMeta": {
29
29
  "@bufbuild/protobuf": {