@bufbuild/protoplugin 1.5.0 → 1.5.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/dist/cjs/create-es-plugin.d.ts +3 -4
- package/dist/cjs/create-es-plugin.js +7 -7
- package/dist/cjs/ecmascript/gencommon.js +19 -1
- package/dist/cjs/error.js +4 -3
- package/dist/esm/create-es-plugin.d.ts +3 -4
- package/dist/esm/create-es-plugin.js +7 -7
- package/dist/esm/ecmascript/gencommon.js +20 -2
- package/dist/esm/error.js +4 -3
- package/package.json +14 -6
|
@@ -11,10 +11,10 @@ interface PluginInit {
|
|
|
11
11
|
*/
|
|
12
12
|
version: string;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* An optional parsing function which can be used to parse your own plugin
|
|
15
|
+
* options.
|
|
16
16
|
*/
|
|
17
|
-
parseOption?:
|
|
17
|
+
parseOption?: (key: string, value: string) => void;
|
|
18
18
|
/**
|
|
19
19
|
* A function which will generate TypeScript files based on proto input.
|
|
20
20
|
* This function will be invoked by the plugin framework when the plugin runs.
|
|
@@ -54,7 +54,6 @@ interface PluginInit {
|
|
|
54
54
|
*/
|
|
55
55
|
transpile?: (files: FileInfo[], transpileJs: boolean, transpileDts: boolean) => FileInfo[];
|
|
56
56
|
}
|
|
57
|
-
type PluginOptionParseFn = (key: string, value: string | undefined) => void;
|
|
58
57
|
/**
|
|
59
58
|
* Create a new code generator plugin for ECMAScript.
|
|
60
59
|
* The plugin can generate JavaScript, TypeScript, or TypeScript declaration
|
|
@@ -122,7 +122,7 @@ function parseParameter(parameter, parseOption) {
|
|
|
122
122
|
}
|
|
123
123
|
break;
|
|
124
124
|
default:
|
|
125
|
-
throw new error_js_1.PluginOptionError(
|
|
125
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
value.split("+");
|
|
@@ -138,7 +138,7 @@ function parseParameter(parameter, parseOption) {
|
|
|
138
138
|
tsNocheck = false;
|
|
139
139
|
break;
|
|
140
140
|
default:
|
|
141
|
-
throw new error_js_1.PluginOptionError(
|
|
141
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
142
142
|
}
|
|
143
143
|
break;
|
|
144
144
|
case "bootstrap_wkt":
|
|
@@ -152,13 +152,13 @@ function parseParameter(parameter, parseOption) {
|
|
|
152
152
|
bootstrapWkt = false;
|
|
153
153
|
break;
|
|
154
154
|
default:
|
|
155
|
-
throw new error_js_1.PluginOptionError(
|
|
155
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
156
156
|
}
|
|
157
157
|
break;
|
|
158
158
|
case "rewrite_imports": {
|
|
159
159
|
const parts = value.split(":");
|
|
160
160
|
if (parts.length !== 2) {
|
|
161
|
-
throw new error_js_1.PluginOptionError(
|
|
161
|
+
throw new error_js_1.PluginOptionError(raw, "must be in the form of <pattern>:<target>");
|
|
162
162
|
}
|
|
163
163
|
const [pattern, target] = parts;
|
|
164
164
|
rewriteImports.push({ pattern, target });
|
|
@@ -182,19 +182,19 @@ function parseParameter(parameter, parseOption) {
|
|
|
182
182
|
keepEmptyFiles = false;
|
|
183
183
|
break;
|
|
184
184
|
default:
|
|
185
|
-
throw new error_js_1.PluginOptionError(
|
|
185
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
186
186
|
}
|
|
187
187
|
break;
|
|
188
188
|
}
|
|
189
189
|
default:
|
|
190
190
|
if (parseOption === undefined) {
|
|
191
|
-
throw new error_js_1.PluginOptionError(
|
|
191
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
192
192
|
}
|
|
193
193
|
try {
|
|
194
194
|
parseOption(key, value);
|
|
195
195
|
}
|
|
196
196
|
catch (e) {
|
|
197
|
-
throw new error_js_1.PluginOptionError(
|
|
197
|
+
throw new error_js_1.PluginOptionError(raw, e);
|
|
198
198
|
}
|
|
199
199
|
break;
|
|
200
200
|
}
|
|
@@ -45,7 +45,25 @@ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck)
|
|
|
45
45
|
if (file.proto.package !== undefined) {
|
|
46
46
|
builder.push(`package ${file.proto.package}, `);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
switch (file.edition) {
|
|
49
|
+
case protobuf_1.Edition.EDITION_PROTO2:
|
|
50
|
+
builder.push(`syntax proto2)\n`);
|
|
51
|
+
break;
|
|
52
|
+
case protobuf_1.Edition.EDITION_PROTO3:
|
|
53
|
+
builder.push(`syntax proto3)\n`);
|
|
54
|
+
break;
|
|
55
|
+
default: {
|
|
56
|
+
const editionString = protobuf_1.Edition[file.edition];
|
|
57
|
+
if (typeof editionString == "string") {
|
|
58
|
+
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
59
|
+
builder.push(`edition ${e})\n`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
builder.push(`unknown edition\n`);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
49
67
|
builder.push("/* eslint-disable */\n");
|
|
50
68
|
if (tsNoCheck) {
|
|
51
69
|
builder.push("// @ts-nocheck\n");
|
package/dist/cjs/error.js
CHANGED
|
@@ -16,9 +16,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.reasonToString = exports.PluginOptionError = void 0;
|
|
17
17
|
class PluginOptionError extends Error {
|
|
18
18
|
constructor(option, reason) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const detail = reason !== undefined ? reasonToString(reason) : "";
|
|
20
|
+
super(detail.length > 0
|
|
21
|
+
? `invalid option "${option}": ${detail}`
|
|
22
|
+
: `invalid option "${option}"`);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.PluginOptionError = PluginOptionError;
|
|
@@ -11,10 +11,10 @@ interface PluginInit {
|
|
|
11
11
|
*/
|
|
12
12
|
version: string;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* An optional parsing function which can be used to parse your own plugin
|
|
15
|
+
* options.
|
|
16
16
|
*/
|
|
17
|
-
parseOption?:
|
|
17
|
+
parseOption?: (key: string, value: string) => void;
|
|
18
18
|
/**
|
|
19
19
|
* A function which will generate TypeScript files based on proto input.
|
|
20
20
|
* This function will be invoked by the plugin framework when the plugin runs.
|
|
@@ -54,7 +54,6 @@ interface PluginInit {
|
|
|
54
54
|
*/
|
|
55
55
|
transpile?: (files: FileInfo[], transpileJs: boolean, transpileDts: boolean) => FileInfo[];
|
|
56
56
|
}
|
|
57
|
-
type PluginOptionParseFn = (key: string, value: string | undefined) => void;
|
|
58
57
|
/**
|
|
59
58
|
* Create a new code generator plugin for ECMAScript.
|
|
60
59
|
* The plugin can generate JavaScript, TypeScript, or TypeScript declaration
|
|
@@ -118,7 +118,7 @@ function parseParameter(parameter, parseOption) {
|
|
|
118
118
|
}
|
|
119
119
|
break;
|
|
120
120
|
default:
|
|
121
|
-
throw new PluginOptionError(
|
|
121
|
+
throw new PluginOptionError(raw);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
value.split("+");
|
|
@@ -134,7 +134,7 @@ function parseParameter(parameter, parseOption) {
|
|
|
134
134
|
tsNocheck = false;
|
|
135
135
|
break;
|
|
136
136
|
default:
|
|
137
|
-
throw new PluginOptionError(
|
|
137
|
+
throw new PluginOptionError(raw);
|
|
138
138
|
}
|
|
139
139
|
break;
|
|
140
140
|
case "bootstrap_wkt":
|
|
@@ -148,13 +148,13 @@ function parseParameter(parameter, parseOption) {
|
|
|
148
148
|
bootstrapWkt = false;
|
|
149
149
|
break;
|
|
150
150
|
default:
|
|
151
|
-
throw new PluginOptionError(
|
|
151
|
+
throw new PluginOptionError(raw);
|
|
152
152
|
}
|
|
153
153
|
break;
|
|
154
154
|
case "rewrite_imports": {
|
|
155
155
|
const parts = value.split(":");
|
|
156
156
|
if (parts.length !== 2) {
|
|
157
|
-
throw new PluginOptionError(
|
|
157
|
+
throw new PluginOptionError(raw, "must be in the form of <pattern>:<target>");
|
|
158
158
|
}
|
|
159
159
|
const [pattern, target] = parts;
|
|
160
160
|
rewriteImports.push({ pattern, target });
|
|
@@ -178,19 +178,19 @@ function parseParameter(parameter, parseOption) {
|
|
|
178
178
|
keepEmptyFiles = false;
|
|
179
179
|
break;
|
|
180
180
|
default:
|
|
181
|
-
throw new PluginOptionError(
|
|
181
|
+
throw new PluginOptionError(raw);
|
|
182
182
|
}
|
|
183
183
|
break;
|
|
184
184
|
}
|
|
185
185
|
default:
|
|
186
186
|
if (parseOption === undefined) {
|
|
187
|
-
throw new PluginOptionError(
|
|
187
|
+
throw new PluginOptionError(raw);
|
|
188
188
|
}
|
|
189
189
|
try {
|
|
190
190
|
parseOption(key, value);
|
|
191
191
|
}
|
|
192
192
|
catch (e) {
|
|
193
|
-
throw new PluginOptionError(
|
|
193
|
+
throw new PluginOptionError(raw, e);
|
|
194
194
|
}
|
|
195
195
|
break;
|
|
196
196
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { codegenInfo, LongType, ScalarType, } from "@bufbuild/protobuf";
|
|
14
|
+
import { codegenInfo, Edition, LongType, ScalarType, } from "@bufbuild/protobuf";
|
|
15
15
|
const { localName, getUnwrappedFieldType, scalarDefaultValue } = codegenInfo;
|
|
16
16
|
export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
17
17
|
const builder = [];
|
|
@@ -42,7 +42,25 @@ export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsN
|
|
|
42
42
|
if (file.proto.package !== undefined) {
|
|
43
43
|
builder.push(`package ${file.proto.package}, `);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
switch (file.edition) {
|
|
46
|
+
case Edition.EDITION_PROTO2:
|
|
47
|
+
builder.push(`syntax proto2)\n`);
|
|
48
|
+
break;
|
|
49
|
+
case Edition.EDITION_PROTO3:
|
|
50
|
+
builder.push(`syntax proto3)\n`);
|
|
51
|
+
break;
|
|
52
|
+
default: {
|
|
53
|
+
const editionString = Edition[file.edition];
|
|
54
|
+
if (typeof editionString == "string") {
|
|
55
|
+
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
56
|
+
builder.push(`edition ${e})\n`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
builder.push(`unknown edition\n`);
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
46
64
|
builder.push("/* eslint-disable */\n");
|
|
47
65
|
if (tsNoCheck) {
|
|
48
66
|
builder.push("// @ts-nocheck\n");
|
package/dist/esm/error.js
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
export class PluginOptionError extends Error {
|
|
15
15
|
constructor(option, reason) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const detail = reason !== undefined ? reasonToString(reason) : "";
|
|
17
|
+
super(detail.length > 0
|
|
18
|
+
? `invalid option "${option}": ${detail}`
|
|
19
|
+
: `invalid option "${option}"`);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
export function reasonToString(reason) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "Helps to create your own Protocol Buffers code generators.",
|
|
6
6
|
"repository": {
|
|
@@ -21,14 +21,22 @@
|
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
+
"node": {
|
|
25
|
+
"import": "./dist/proxy/index.js",
|
|
26
|
+
"require": "./dist/cjs/index.js"
|
|
27
|
+
},
|
|
24
28
|
"module": "./dist/esm/index.js",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.js"
|
|
27
31
|
},
|
|
28
32
|
"./ecmascript": {
|
|
33
|
+
"node": {
|
|
34
|
+
"import": "./dist/proxy/ecmascript/index.js",
|
|
35
|
+
"require": "./dist/cjs/ecmascript/index.js"
|
|
36
|
+
},
|
|
29
37
|
"module": "./dist/esm/ecmascript/index.js",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
38
|
+
"import": "./dist/esm/ecmascript/index.js",
|
|
39
|
+
"require": "./dist/cjs/ecmascript/index.js"
|
|
32
40
|
}
|
|
33
41
|
},
|
|
34
42
|
"typesVersions": {
|
|
@@ -39,7 +47,7 @@
|
|
|
39
47
|
}
|
|
40
48
|
},
|
|
41
49
|
"dependencies": {
|
|
42
|
-
"@bufbuild/protobuf": "1.5.
|
|
50
|
+
"@bufbuild/protobuf": "1.5.1",
|
|
43
51
|
"@typescript/vfs": "^1.4.0",
|
|
44
52
|
"typescript": "4.5.2"
|
|
45
53
|
},
|