@bufbuild/protoplugin 1.0.0 → 1.1.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/dist/cjs/create-es-plugin.js +21 -8
- package/dist/cjs/ecmascript/custom-options.js +1 -1
- package/dist/cjs/ecmascript/gencommon.js +2 -2
- package/dist/cjs/ecmascript/generated-file.js +2 -2
- package/dist/cjs/ecmascript/import-path.js +1 -1
- package/dist/cjs/ecmascript/import-symbol.js +1 -1
- package/dist/cjs/ecmascript/index.js +1 -1
- package/dist/cjs/ecmascript/runtime-imports.js +1 -1
- package/dist/cjs/ecmascript/schema.js +3 -3
- package/dist/cjs/ecmascript/target.js +1 -1
- package/dist/cjs/ecmascript/transpile.js +1 -1
- package/dist/cjs/error.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/run-node.js +1 -1
- package/dist/esm/create-es-plugin.js +21 -8
- package/dist/esm/ecmascript/custom-options.js +1 -1
- package/dist/esm/ecmascript/gencommon.js +2 -2
- package/dist/esm/ecmascript/generated-file.js +2 -2
- package/dist/esm/ecmascript/import-path.js +1 -1
- package/dist/esm/ecmascript/import-symbol.js +1 -1
- package/dist/esm/ecmascript/index.js +1 -1
- package/dist/esm/ecmascript/runtime-imports.js +1 -1
- package/dist/esm/ecmascript/schema.js +3 -3
- package/dist/esm/ecmascript/target.js +1 -1
- package/dist/esm/ecmascript/transpile.js +1 -1
- package/dist/esm/error.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/run-node.js +1 -1
- package/dist/types/ecmascript/gencommon.d.ts +1 -1
- package/dist/types/ecmascript/generated-file.d.ts +1 -1
- package/dist/types/ecmascript/schema.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -30,8 +30,8 @@ function createEcmaScriptPlugin(init) {
|
|
|
30
30
|
version: init.version,
|
|
31
31
|
run(req) {
|
|
32
32
|
var _a;
|
|
33
|
-
const { targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, } = parseParameter(req.parameter, init.parseOption);
|
|
34
|
-
const { schema, getFileInfo } = (0, schema_js_1.createSchema)(req, targets,
|
|
33
|
+
const { targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, pluginParameter, } = parseParameter(req.parameter, init.parseOption);
|
|
34
|
+
const { schema, getFileInfo } = (0, schema_js_1.createSchema)(req, targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, init.name, init.version, pluginParameter);
|
|
35
35
|
const targetTs = schema.targets.includes("ts");
|
|
36
36
|
const targetJs = schema.targets.includes("js");
|
|
37
37
|
const targetDts = schema.targets.includes("dts");
|
|
@@ -104,7 +104,11 @@ function parseParameter(parameter, parseOption) {
|
|
|
104
104
|
let keepEmptyFiles = false;
|
|
105
105
|
const rewriteImports = [];
|
|
106
106
|
let importExtension = ".js";
|
|
107
|
-
|
|
107
|
+
const rawParameters = [];
|
|
108
|
+
for (const { key, value, raw } of splitParameter(parameter)) {
|
|
109
|
+
// Whether this key/value plugin parameter pair should be
|
|
110
|
+
// printed to the generated file preamble
|
|
111
|
+
let printToFile = true;
|
|
108
112
|
switch (key) {
|
|
109
113
|
case "target":
|
|
110
114
|
targets = [];
|
|
@@ -158,6 +162,9 @@ function parseParameter(parameter, parseOption) {
|
|
|
158
162
|
}
|
|
159
163
|
const [pattern, target] = parts;
|
|
160
164
|
rewriteImports.push({ pattern, target });
|
|
165
|
+
// rewrite_imports can be noisy and is more of an implementation detail
|
|
166
|
+
// so we strip it out of the preamble
|
|
167
|
+
printToFile = false;
|
|
161
168
|
break;
|
|
162
169
|
}
|
|
163
170
|
case "import_extension": {
|
|
@@ -191,7 +198,11 @@ function parseParameter(parameter, parseOption) {
|
|
|
191
198
|
}
|
|
192
199
|
break;
|
|
193
200
|
}
|
|
201
|
+
if (printToFile) {
|
|
202
|
+
rawParameters.push(raw);
|
|
203
|
+
}
|
|
194
204
|
}
|
|
205
|
+
const pluginParameter = rawParameters.join(",");
|
|
195
206
|
return {
|
|
196
207
|
targets,
|
|
197
208
|
tsNocheck,
|
|
@@ -199,17 +210,19 @@ function parseParameter(parameter, parseOption) {
|
|
|
199
210
|
rewriteImports,
|
|
200
211
|
importExtension,
|
|
201
212
|
keepEmptyFiles,
|
|
213
|
+
pluginParameter,
|
|
202
214
|
};
|
|
203
215
|
}
|
|
204
216
|
function splitParameter(parameter) {
|
|
205
217
|
if (parameter == undefined) {
|
|
206
218
|
return [];
|
|
207
219
|
}
|
|
208
|
-
return parameter.split(",").map((
|
|
209
|
-
const i =
|
|
220
|
+
return parameter.split(",").map((raw) => {
|
|
221
|
+
const i = raw.indexOf("=");
|
|
210
222
|
return {
|
|
211
|
-
key: i === -1 ?
|
|
212
|
-
value: i === -1 ? "" :
|
|
223
|
+
key: i === -1 ? raw : raw.substring(0, i),
|
|
224
|
+
value: i === -1 ? "" : raw.substring(i + 1),
|
|
225
|
+
raw,
|
|
213
226
|
};
|
|
214
227
|
});
|
|
215
228
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -37,7 +37,7 @@ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck)
|
|
|
37
37
|
};
|
|
38
38
|
writeLeadingComments(file.getSyntaxComments());
|
|
39
39
|
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
40
|
-
if (parameter !==
|
|
40
|
+
if (parameter !== "") {
|
|
41
41
|
builder.push(` with parameter "${parameter}"`);
|
|
42
42
|
}
|
|
43
43
|
builder.push("\n");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -22,7 +22,7 @@ function createGeneratedFile(name, importPath, rewriteImportPath, createTypeImpo
|
|
|
22
22
|
const el = [];
|
|
23
23
|
return {
|
|
24
24
|
preamble(file) {
|
|
25
|
-
preamble = (0, gencommon_js_1.makeFilePreamble)(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.
|
|
25
|
+
preamble = (0, gencommon_js_1.makeFilePreamble)(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.pluginParameter, preambleSettings.tsNocheck);
|
|
26
26
|
},
|
|
27
27
|
print(printableOrFragments, ...rest) {
|
|
28
28
|
let printables;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,7 @@ const generated_file_js_1 = require("./generated-file.js");
|
|
|
19
19
|
const runtime_imports_js_1 = require("./runtime-imports.js");
|
|
20
20
|
const import_symbol_js_1 = require("./import-symbol.js");
|
|
21
21
|
const import_path_js_1 = require("./import-path.js");
|
|
22
|
-
function createSchema(request, targets,
|
|
22
|
+
function createSchema(request, targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, pluginName, pluginVersion, pluginParameter) {
|
|
23
23
|
const descriptorSet = (0, protobuf_1.createDescriptorSet)(request.protoFile);
|
|
24
24
|
const filesToGenerate = findFilesToGenerate(descriptorSet, request);
|
|
25
25
|
const runtime = (0, runtime_imports_js_1.createRuntimeImports)(bootstrapWkt);
|
|
@@ -39,7 +39,7 @@ function createSchema(request, targets, pluginName, pluginVersion, tsNocheck, bo
|
|
|
39
39
|
const genFile = (0, generated_file_js_1.createGeneratedFile)(name, (0, import_path_js_1.deriveImportPath)(name), (importPath) => (0, import_path_js_1.rewriteImportPath)(importPath, rewriteImports, importExtension), createTypeImport, runtime, {
|
|
40
40
|
pluginName,
|
|
41
41
|
pluginVersion,
|
|
42
|
-
|
|
42
|
+
pluginParameter,
|
|
43
43
|
tsNocheck,
|
|
44
44
|
}, keepEmptyFiles);
|
|
45
45
|
generatedFiles.push(genFile);
|
package/dist/cjs/error.js
CHANGED
package/dist/cjs/index.js
CHANGED
package/dist/cjs/plugin.js
CHANGED
package/dist/cjs/run-node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -27,8 +27,8 @@ export function createEcmaScriptPlugin(init) {
|
|
|
27
27
|
version: init.version,
|
|
28
28
|
run(req) {
|
|
29
29
|
var _a;
|
|
30
|
-
const { targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, } = parseParameter(req.parameter, init.parseOption);
|
|
31
|
-
const { schema, getFileInfo } = createSchema(req, targets,
|
|
30
|
+
const { targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, pluginParameter, } = parseParameter(req.parameter, init.parseOption);
|
|
31
|
+
const { schema, getFileInfo } = createSchema(req, targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, init.name, init.version, pluginParameter);
|
|
32
32
|
const targetTs = schema.targets.includes("ts");
|
|
33
33
|
const targetJs = schema.targets.includes("js");
|
|
34
34
|
const targetDts = schema.targets.includes("dts");
|
|
@@ -100,7 +100,11 @@ function parseParameter(parameter, parseOption) {
|
|
|
100
100
|
let keepEmptyFiles = false;
|
|
101
101
|
const rewriteImports = [];
|
|
102
102
|
let importExtension = ".js";
|
|
103
|
-
|
|
103
|
+
const rawParameters = [];
|
|
104
|
+
for (const { key, value, raw } of splitParameter(parameter)) {
|
|
105
|
+
// Whether this key/value plugin parameter pair should be
|
|
106
|
+
// printed to the generated file preamble
|
|
107
|
+
let printToFile = true;
|
|
104
108
|
switch (key) {
|
|
105
109
|
case "target":
|
|
106
110
|
targets = [];
|
|
@@ -154,6 +158,9 @@ function parseParameter(parameter, parseOption) {
|
|
|
154
158
|
}
|
|
155
159
|
const [pattern, target] = parts;
|
|
156
160
|
rewriteImports.push({ pattern, target });
|
|
161
|
+
// rewrite_imports can be noisy and is more of an implementation detail
|
|
162
|
+
// so we strip it out of the preamble
|
|
163
|
+
printToFile = false;
|
|
157
164
|
break;
|
|
158
165
|
}
|
|
159
166
|
case "import_extension": {
|
|
@@ -187,7 +194,11 @@ function parseParameter(parameter, parseOption) {
|
|
|
187
194
|
}
|
|
188
195
|
break;
|
|
189
196
|
}
|
|
197
|
+
if (printToFile) {
|
|
198
|
+
rawParameters.push(raw);
|
|
199
|
+
}
|
|
190
200
|
}
|
|
201
|
+
const pluginParameter = rawParameters.join(",");
|
|
191
202
|
return {
|
|
192
203
|
targets,
|
|
193
204
|
tsNocheck,
|
|
@@ -195,17 +206,19 @@ function parseParameter(parameter, parseOption) {
|
|
|
195
206
|
rewriteImports,
|
|
196
207
|
importExtension,
|
|
197
208
|
keepEmptyFiles,
|
|
209
|
+
pluginParameter,
|
|
198
210
|
};
|
|
199
211
|
}
|
|
200
212
|
function splitParameter(parameter) {
|
|
201
213
|
if (parameter == undefined) {
|
|
202
214
|
return [];
|
|
203
215
|
}
|
|
204
|
-
return parameter.split(",").map((
|
|
205
|
-
const i =
|
|
216
|
+
return parameter.split(",").map((raw) => {
|
|
217
|
+
const i = raw.indexOf("=");
|
|
206
218
|
return {
|
|
207
|
-
key: i === -1 ?
|
|
208
|
-
value: i === -1 ? "" :
|
|
219
|
+
key: i === -1 ? raw : raw.substring(0, i),
|
|
220
|
+
value: i === -1 ? "" : raw.substring(i + 1),
|
|
221
|
+
raw,
|
|
209
222
|
};
|
|
210
223
|
});
|
|
211
224
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -34,7 +34,7 @@ export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsN
|
|
|
34
34
|
};
|
|
35
35
|
writeLeadingComments(file.getSyntaxComments());
|
|
36
36
|
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
37
|
-
if (parameter !==
|
|
37
|
+
if (parameter !== "") {
|
|
38
38
|
builder.push(` with parameter "${parameter}"`);
|
|
39
39
|
}
|
|
40
40
|
builder.push("\n");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,7 @@ export function createGeneratedFile(name, importPath, rewriteImportPath, createT
|
|
|
19
19
|
const el = [];
|
|
20
20
|
return {
|
|
21
21
|
preamble(file) {
|
|
22
|
-
preamble = makeFilePreamble(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.
|
|
22
|
+
preamble = makeFilePreamble(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.pluginParameter, preambleSettings.tsNocheck);
|
|
23
23
|
},
|
|
24
24
|
print(printableOrFragments, ...rest) {
|
|
25
25
|
let printables;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -16,7 +16,7 @@ import { createGeneratedFile } from "./generated-file.js";
|
|
|
16
16
|
import { createRuntimeImports } from "./runtime-imports.js";
|
|
17
17
|
import { createImportSymbol } from "./import-symbol.js";
|
|
18
18
|
import { deriveImportPath, makeImportPath, rewriteImportPath, } from "./import-path.js";
|
|
19
|
-
export function createSchema(request, targets,
|
|
19
|
+
export function createSchema(request, targets, tsNocheck, bootstrapWkt, rewriteImports, importExtension, keepEmptyFiles, pluginName, pluginVersion, pluginParameter) {
|
|
20
20
|
const descriptorSet = createDescriptorSet(request.protoFile);
|
|
21
21
|
const filesToGenerate = findFilesToGenerate(descriptorSet, request);
|
|
22
22
|
const runtime = createRuntimeImports(bootstrapWkt);
|
|
@@ -36,7 +36,7 @@ export function createSchema(request, targets, pluginName, pluginVersion, tsNoch
|
|
|
36
36
|
const genFile = createGeneratedFile(name, deriveImportPath(name), (importPath) => rewriteImportPath(importPath, rewriteImports, importExtension), createTypeImport, runtime, {
|
|
37
37
|
pluginName,
|
|
38
38
|
pluginVersion,
|
|
39
|
-
|
|
39
|
+
pluginParameter,
|
|
40
40
|
tsNocheck,
|
|
41
41
|
}, keepEmptyFiles);
|
|
42
42
|
generatedFiles.push(genFile);
|
package/dist/esm/error.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/plugin.js
CHANGED
package/dist/esm/run-node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, ScalarType } from "@bufbuild/protobuf";
|
|
2
2
|
import type { GeneratedFile, Printable } from "./generated-file.js";
|
|
3
3
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
4
|
-
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string
|
|
4
|
+
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
|
|
5
5
|
export declare function createJsDocBlock(text: string, indentation?: string): Printable;
|
|
6
6
|
export declare function makeJsDoc(desc: DescEnum | DescEnumValue | DescMessage | DescOneof | DescField | DescService | DescMethod, indentation?: string): Printable;
|
|
7
7
|
/**
|
|
@@ -71,7 +71,7 @@ type RewriteImportPathFn = (path: string) => string;
|
|
|
71
71
|
export declare function createGeneratedFile(name: string, importPath: string, rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, preambleSettings: {
|
|
72
72
|
pluginName: string;
|
|
73
73
|
pluginVersion: string;
|
|
74
|
-
|
|
74
|
+
pluginParameter: string;
|
|
75
75
|
tsNocheck: boolean;
|
|
76
76
|
}, keepEmpty: boolean): GeneratedFile & GenerateFileToFileInfo;
|
|
77
77
|
export {};
|
|
@@ -38,6 +38,6 @@ interface SchemaController {
|
|
|
38
38
|
schema: Schema;
|
|
39
39
|
getFileInfo: () => FileInfo[];
|
|
40
40
|
}
|
|
41
|
-
export declare function createSchema(request: CodeGeneratorRequest, targets: Target[],
|
|
41
|
+
export declare function createSchema(request: CodeGeneratorRequest, targets: Target[], tsNocheck: boolean, bootstrapWkt: boolean, rewriteImports: RewriteImports, importExtension: string, keepEmptyFiles: boolean, pluginName: string, pluginVersion: string, pluginParameter: string): SchemaController;
|
|
42
42
|
export declare function toResponse(files: FileInfo[]): CodeGeneratorResponse;
|
|
43
43
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@bufbuild/protobuf": "1.
|
|
38
|
+
"@bufbuild/protobuf": "1.1.0",
|
|
39
39
|
"@typescript/vfs": "^1.4.0",
|
|
40
40
|
"typescript": "4.5.2"
|
|
41
41
|
},
|