@bufbuild/protoc-gen-es 2.2.1 → 2.2.3
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 +2 -6
- package/dist/cjs/package.json +4 -4
- package/dist/cjs/src/protoc-gen-es-plugin.js +9 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -9,17 +9,13 @@ The code generator plugin for Protocol Buffers for ECMAScript. Learn more about
|
|
|
9
9
|
schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
|
|
10
10
|
It's compatible with Protocol Buffer compilers like [buf](https://github.com/bufbuild/buf) and [protoc](https://github.com/protocolbuffers/protobuf/releases).
|
|
11
11
|
|
|
12
|
-
To install the
|
|
12
|
+
To install the runtime library and the plugin, run:
|
|
13
13
|
|
|
14
14
|
```shell
|
|
15
|
-
npm install --save-dev @bufbuild/protoc-gen-es
|
|
16
15
|
npm install @bufbuild/protobuf
|
|
16
|
+
npm install --save-dev @bufbuild/protoc-gen-es
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
We use peer dependencies to ensure that the code generator and runtime library are
|
|
20
|
-
compatible with each other. Note that npm installs them automatically, but Yarn
|
|
21
|
-
and pnpm do not.
|
|
22
|
-
|
|
23
19
|
## Generating code
|
|
24
20
|
|
|
25
21
|
### With buf
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
6
|
"keywords": [
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"preferUnplugged": true,
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@bufbuild/protobuf": "^2.2.
|
|
34
|
-
"@bufbuild/protoplugin": "2.2.
|
|
33
|
+
"@bufbuild/protobuf": "^2.2.3",
|
|
34
|
+
"@bufbuild/protoplugin": "2.2.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@bufbuild/protobuf": "2.2.
|
|
37
|
+
"@bufbuild/protobuf": "2.2.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@bufbuild/protobuf": {
|
|
@@ -447,19 +447,16 @@ function generateMessageJsonShape(f, message, target) {
|
|
|
447
447
|
else {
|
|
448
448
|
f.print(exp, " = {");
|
|
449
449
|
for (const field of message.fields) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
jsonName = f.string(jsonName);
|
|
459
|
-
}
|
|
460
|
-
f.print(" ", jsonName, "?: ", (0, util_1.fieldJsonType)(field), ";");
|
|
461
|
-
break;
|
|
450
|
+
f.print(f.jsDoc(field, " "));
|
|
451
|
+
let jsonName = field.jsonName;
|
|
452
|
+
const startWithNumber = /^[0-9]/;
|
|
453
|
+
const containsSpecialChar = /[^a-zA-Z0-9_$]/;
|
|
454
|
+
if (jsonName === ""
|
|
455
|
+
|| startWithNumber.test(jsonName)
|
|
456
|
+
|| containsSpecialChar.test(jsonName)) {
|
|
457
|
+
jsonName = f.string(jsonName);
|
|
462
458
|
}
|
|
459
|
+
f.print(" ", jsonName, "?: ", (0, util_1.fieldJsonType)(field), ";");
|
|
463
460
|
if (message.fields.indexOf(field) < message.fields.length - 1) {
|
|
464
461
|
f.print();
|
|
465
462
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
6
|
"keywords": [
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"preferUnplugged": true,
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@bufbuild/protobuf": "^2.2.
|
|
34
|
-
"@bufbuild/protoplugin": "2.2.
|
|
33
|
+
"@bufbuild/protobuf": "^2.2.3",
|
|
34
|
+
"@bufbuild/protoplugin": "2.2.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@bufbuild/protobuf": "2.2.
|
|
37
|
+
"@bufbuild/protobuf": "2.2.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@bufbuild/protobuf": {
|