@bufbuild/protoc-gen-es 2.10.2 → 2.11.0
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,13 +1,10 @@
|
|
|
1
1
|
# @bufbuild/protoc-gen-es
|
|
2
2
|
|
|
3
|
-
The code generator plugin for Protocol Buffers for ECMAScript. Learn more about the project at
|
|
4
|
-
[github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
3
|
+
The code generator plugin for Protocol Buffers for ECMAScript. Learn more about the project at [github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
5
4
|
|
|
6
5
|
## Installation
|
|
7
6
|
|
|
8
|
-
`protoc-gen-es` generates base types—messages and enumerations—from your Protocol Buffer
|
|
9
|
-
schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
|
|
10
|
-
It's compatible with Protocol Buffer compilers like [buf](https://github.com/bufbuild/buf) and [protoc](https://github.com/protocolbuffers/protobuf/releases).
|
|
7
|
+
`protoc-gen-es` generates base types—messages and enumerations—from your Protocol Buffer schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf). It's compatible with Protocol Buffer compilers like [buf](https://github.com/bufbuild/buf) and [protoc](https://github.com/protocolbuffers/protobuf/releases).
|
|
11
8
|
|
|
12
9
|
To install the runtime library and the plugin, run:
|
|
13
10
|
|
|
@@ -29,6 +26,8 @@ Add a new `buf.gen.yaml` configuration file:
|
|
|
29
26
|
```yaml
|
|
30
27
|
# Learn more: https://buf.build/docs/configuration/v2/buf-gen-yaml
|
|
31
28
|
version: v2
|
|
29
|
+
inputs:
|
|
30
|
+
- directory: proto
|
|
32
31
|
plugins:
|
|
33
32
|
# This will invoke protoc-gen-es and write output to src/gen
|
|
34
33
|
- local: protoc-gen-es
|
|
@@ -51,17 +50,15 @@ not just local Protobuf files.
|
|
|
51
50
|
|
|
52
51
|
```bash
|
|
53
52
|
PATH=$PATH:$(pwd)/node_modules/.bin \
|
|
54
|
-
protoc
|
|
53
|
+
protoc --proto_path proto \
|
|
55
54
|
--es_out src/gen \
|
|
56
55
|
--es_opt target=ts \
|
|
57
|
-
a.proto b.proto c.proto
|
|
56
|
+
proto/a.proto proto/b.proto proto/c.proto
|
|
58
57
|
```
|
|
59
58
|
|
|
60
|
-
Note that `node_modules/.bin` needs to be added to the `$PATH` so that the Protobuf compiler can find the plugin. This
|
|
61
|
-
happens automatically with npm scripts.
|
|
59
|
+
Note that `node_modules/.bin` needs to be added to the `$PATH` so that the Protobuf compiler can find the plugin. This happens automatically with npm scripts and with `npx`.
|
|
62
60
|
|
|
63
|
-
If you use Yarn, versions v2 and above don't use a `node_modules` directory, so you need to change the variable a
|
|
64
|
-
bit:
|
|
61
|
+
If you use Yarn, versions v2 and above don't use a `node_modules` directory, so you need to change the variable a bit:
|
|
65
62
|
|
|
66
63
|
```shellsession
|
|
67
64
|
PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
|
|
@@ -71,8 +68,7 @@ PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
|
|
|
71
68
|
|
|
72
69
|
### `target`
|
|
73
70
|
|
|
74
|
-
This option controls whether the plugin generates JavaScript, TypeScript, or TypeScript declaration files. Possible
|
|
75
|
-
values:
|
|
71
|
+
This option controls whether the plugin generates JavaScript, TypeScript, or TypeScript declaration files. Possible values:
|
|
76
72
|
|
|
77
73
|
- `target=js`: Generates a `_pb.js` file for every `.proto` input file.
|
|
78
74
|
- `target=ts`: Generates a `_pb.ts` file for every `.proto` input file.
|
|
@@ -80,15 +76,11 @@ values:
|
|
|
80
76
|
|
|
81
77
|
You can pass multiple values by separating them with `+`—for example, `target=js+dts`.
|
|
82
78
|
|
|
83
|
-
By default, it generates JavaScript and TypeScript declaration files, which produces the smallest code size and is the
|
|
84
|
-
most compatible with various bundler configurations. If you prefer to generate TypeScript, use `target=ts`.
|
|
79
|
+
By default, it generates JavaScript and TypeScript declaration files, which produces the smallest code size and is the most compatible with various bundler configurations. If you prefer to generate TypeScript, use `target=ts`.
|
|
85
80
|
|
|
86
81
|
### `import_extension`
|
|
87
82
|
|
|
88
|
-
By default, `protoc-gen-es` doesn't add file extensions to import paths. However, some
|
|
89
|
-
environments require an import extension. For example, using ECMAScript modules in Node.js
|
|
90
|
-
requires the `.js` extension, and Deno requires `.ts`. With this plugin option, you can add `.js`/`.ts` extensions in
|
|
91
|
-
import paths with the given value. Possible values:
|
|
83
|
+
By default, `protoc-gen-es` doesn't add file extensions to import paths. However, some environments require an import extension. For example, using ECMAScript modules in Node.js requires the `.js` extension, and Deno requires `.ts`. With this plugin option, you can add `.js`/`.ts` extensions in import paths with the given value. Possible values:
|
|
92
84
|
|
|
93
85
|
- `import_extension=none`: Doesn't add an extension. (Default)
|
|
94
86
|
- `import_extension=js`: Adds the `.js` extension.
|
|
@@ -96,37 +88,33 @@ import paths with the given value. Possible values:
|
|
|
96
88
|
|
|
97
89
|
### `js_import_style`
|
|
98
90
|
|
|
99
|
-
By default, `protoc-gen-es` generates ECMAScript `import` and `export` statements. For use cases where CommonJS is
|
|
100
|
-
difficult to avoid, this option can be used to generate CommonJS `require()` calls. Possible values:
|
|
91
|
+
By default, `protoc-gen-es` generates ECMAScript `import` and `export` statements. For use cases where CommonJS is difficult to avoid, this option can be used to generate CommonJS `require()` calls. Possible values:
|
|
101
92
|
|
|
102
93
|
- `js_import_style=module`: Generates ECMAScript `import`/`export` statements. (Default)
|
|
103
94
|
- `js_import_style=legacy_commonjs`: Generates CommonJS `require()` calls.
|
|
104
95
|
|
|
105
96
|
### `keep_empty_files=true`
|
|
106
97
|
|
|
107
|
-
By default, `protoc-gen-es` omits empty files from the plugin output. This option disables pruning of empty files to
|
|
108
|
-
allow for smooth interoperation with Bazel and similar tooling that requires all output files to be declared ahead of
|
|
109
|
-
time. Unless you use Bazel, you probably don't need this option.
|
|
98
|
+
By default, `protoc-gen-es` omits empty files from the plugin output. This option disables pruning of empty files to allow for smooth interoperation with Bazel and similar tooling that requires all output files to be declared ahead of time. Unless you use Bazel, you probably don't need this option.
|
|
110
99
|
|
|
111
100
|
### `ts_nocheck=true`
|
|
112
101
|
|
|
113
|
-
`protoc-gen-es` generates valid TypeScript for current versions of the TypeScript compiler with standard settings.
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
`protoc-gen-es` generates valid TypeScript for current versions of the TypeScript compiler with standard settings. If you use compiler settings that yield an error for generated code, setting this option generates an annotation at the top of each file to skip type checks: `// @ts-nocheck`.
|
|
103
|
+
|
|
104
|
+
### `elide_plugin_version=true`
|
|
105
|
+
|
|
106
|
+
By default, [protoc-gen-es] inserts its version number at the top of each generated file. To remove the version number, set `elide_plugin_version=true`. Be aware that we recommend to keep plugin and runtime versions in sync, and that this option can make it more difficult to spot a mismatch.
|
|
116
107
|
|
|
117
108
|
### `json_types=true`
|
|
118
109
|
|
|
119
|
-
Generates JSON types for every Protobuf message and enumeration. Calling `toJson()` automatically returns the JSON type
|
|
120
|
-
if available. Learn more about [JSON types](https://github.com/bufbuild/protobuf-es/blob/main/MANUAL.md#json-types).
|
|
110
|
+
Generates JSON types for every Protobuf message and enumeration. Calling `toJson()` automatically returns the JSON type if available. Learn more about [JSON types](https://github.com/bufbuild/protobuf-es/blob/main/MANUAL.md#json-types).
|
|
121
111
|
|
|
122
112
|
### `valid_types` (experimental)
|
|
123
113
|
|
|
124
114
|
Generates a Valid type for every Protobuf message. Possible values:
|
|
125
115
|
|
|
126
|
-
- `valid_types=legacy_required`: Message fields with the `required` label, or the Edition feature
|
|
127
|
-
|
|
128
|
-
- `valid_types=protovalidate_required`: Message fields with protovalidate's [`required` rule](https://buf.build/docs/reference/protovalidate/rules/field_rules/#required)
|
|
129
|
-
rule are generated as non-optional properties.
|
|
116
|
+
- `valid_types=legacy_required`: Message fields with the `required` label, or the Edition feature `features.field_presence=LEGACY_REQUIRED`, are generated as non-optional properties.
|
|
117
|
+
- `valid_types=protovalidate_required`: Message fields with protovalidate's [`required` rule](https://buf.build/docs/reference/protovalidate/rules/field_rules/#required) rule are generated as non-optional properties.
|
|
130
118
|
|
|
131
119
|
You can combine both options with `+`—for example, `valid_types=legacy_required+protovalidate_required`.
|
|
132
120
|
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
6
|
"keywords": [
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"preferUnplugged": true,
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@bufbuild/protobuf": "2.
|
|
36
|
-
"@bufbuild/protoplugin": "2.
|
|
35
|
+
"@bufbuild/protobuf": "2.11.0",
|
|
36
|
+
"@bufbuild/protoplugin": "2.11.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"upstream-protobuf": "*"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@bufbuild/protobuf": "2.
|
|
42
|
+
"@bufbuild/protobuf": "2.11.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"@bufbuild/protobuf": {
|
package/dist/cjs/src/util.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
6
|
"keywords": [
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"preferUnplugged": true,
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@bufbuild/protobuf": "2.
|
|
36
|
-
"@bufbuild/protoplugin": "2.
|
|
35
|
+
"@bufbuild/protobuf": "2.11.0",
|
|
36
|
+
"@bufbuild/protoplugin": "2.11.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"upstream-protobuf": "*"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@bufbuild/protobuf": "2.
|
|
42
|
+
"@bufbuild/protobuf": "2.11.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"@bufbuild/protobuf": {
|