@bufbuild/protoplugin 1.5.1 → 1.7.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 +2 -2
- package/dist/cjs/create-es-plugin.d.ts +23 -3
- package/dist/cjs/create-es-plugin.js +26 -135
- package/dist/cjs/ecmascript/custom-options.d.ts +8 -0
- package/dist/cjs/ecmascript/custom-options.js +7 -1
- package/dist/cjs/ecmascript/export-declaration.d.ts +7 -0
- package/dist/cjs/ecmascript/export-declaration.js +24 -0
- package/dist/cjs/ecmascript/gencommon.d.ts +4 -5
- package/dist/cjs/ecmascript/gencommon.js +2 -76
- package/dist/cjs/ecmascript/generated-file.d.ts +48 -13
- package/dist/cjs/ecmascript/generated-file.js +82 -19
- package/dist/cjs/ecmascript/import-path.js +1 -1
- package/dist/cjs/ecmascript/import-symbol.js +1 -1
- package/dist/cjs/ecmascript/index.d.ts +22 -7
- package/dist/cjs/ecmascript/index.js +31 -9
- package/dist/cjs/ecmascript/jsdoc.d.ts +8 -0
- package/dist/cjs/ecmascript/jsdoc.js +93 -0
- package/dist/cjs/ecmascript/parameter.d.ts +13 -0
- package/dist/cjs/ecmascript/parameter.js +161 -0
- package/dist/cjs/ecmascript/reify-wkt.js +1 -1
- package/dist/cjs/ecmascript/runtime-imports.d.ts +1 -0
- package/dist/cjs/ecmascript/runtime-imports.js +2 -1
- package/dist/cjs/ecmascript/schema.d.ts +5 -6
- package/dist/cjs/ecmascript/schema.js +24 -37
- package/dist/cjs/ecmascript/target.js +1 -1
- package/dist/cjs/ecmascript/transpile.d.ts +1 -1
- package/dist/cjs/ecmascript/transpile.js +5 -2
- package/dist/cjs/error.js +1 -1
- package/dist/cjs/index.d.ts +5 -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.d.ts +23 -3
- package/dist/esm/create-es-plugin.js +27 -136
- package/dist/esm/ecmascript/custom-options.d.ts +8 -0
- package/dist/esm/ecmascript/custom-options.js +7 -1
- package/dist/esm/ecmascript/export-declaration.d.ts +7 -0
- package/dist/esm/ecmascript/export-declaration.js +20 -0
- package/dist/esm/ecmascript/gencommon.d.ts +4 -5
- package/dist/esm/ecmascript/gencommon.js +1 -73
- package/dist/esm/ecmascript/generated-file.d.ts +48 -13
- package/dist/esm/ecmascript/generated-file.js +83 -20
- package/dist/esm/ecmascript/import-path.js +1 -1
- package/dist/esm/ecmascript/import-symbol.js +1 -1
- package/dist/esm/ecmascript/index.d.ts +22 -7
- package/dist/esm/ecmascript/index.js +24 -3
- package/dist/esm/ecmascript/jsdoc.d.ts +8 -0
- package/dist/esm/ecmascript/jsdoc.js +89 -0
- package/dist/esm/ecmascript/parameter.d.ts +13 -0
- package/dist/esm/ecmascript/parameter.js +157 -0
- package/dist/esm/ecmascript/reify-wkt.js +1 -1
- package/dist/esm/ecmascript/runtime-imports.d.ts +1 -0
- package/dist/esm/ecmascript/runtime-imports.js +2 -1
- package/dist/esm/ecmascript/schema.d.ts +5 -6
- package/dist/esm/ecmascript/schema.js +24 -36
- package/dist/esm/ecmascript/target.js +1 -1
- package/dist/esm/ecmascript/transpile.d.ts +1 -1
- package/dist/esm/ecmascript/transpile.js +5 -2
- package/dist/esm/error.js +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/run-node.js +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CodeGeneratorRequest, DescFile } from "@bufbuild/protobuf";
|
|
2
|
-
import {
|
|
2
|
+
import { FeatureSetDefaults } from "@bufbuild/protobuf";
|
|
3
3
|
import type { FileInfo, GeneratedFile } from "./generated-file.js";
|
|
4
4
|
import { RuntimeImports } from "./runtime-imports.js";
|
|
5
5
|
import type { Target } from "./target.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ParsedParameter } from "./parameter";
|
|
7
7
|
/**
|
|
8
8
|
* Schema describes the files and types that the plugin is requested to
|
|
9
9
|
* generate.
|
|
@@ -34,10 +34,9 @@ export interface Schema {
|
|
|
34
34
|
*/
|
|
35
35
|
readonly proto: CodeGeneratorRequest;
|
|
36
36
|
}
|
|
37
|
-
interface SchemaController {
|
|
38
|
-
schema: Schema;
|
|
37
|
+
interface SchemaController extends Schema {
|
|
39
38
|
getFileInfo: () => FileInfo[];
|
|
39
|
+
prepareGenerate(target: Target): void;
|
|
40
40
|
}
|
|
41
|
-
export declare function createSchema(request: CodeGeneratorRequest,
|
|
42
|
-
export declare function toResponse(files: FileInfo[]): CodeGeneratorResponse;
|
|
41
|
+
export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string, featureSetDefaults: FeatureSetDefaults | undefined): SchemaController;
|
|
43
42
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2024 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.
|
|
@@ -11,63 +11,51 @@
|
|
|
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 {
|
|
14
|
+
import { codegenInfo, createDescriptorSet, } from "@bufbuild/protobuf";
|
|
15
15
|
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
|
-
|
|
20
|
-
|
|
19
|
+
import { makeFilePreamble } from "./gencommon";
|
|
20
|
+
export function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
|
|
21
|
+
const descriptorSet = createDescriptorSet(request.protoFile, {
|
|
22
|
+
featureSetDefaults,
|
|
23
|
+
});
|
|
21
24
|
const filesToGenerate = findFilesToGenerate(descriptorSet, request);
|
|
22
|
-
const runtime = createRuntimeImports(bootstrapWkt);
|
|
25
|
+
const runtime = createRuntimeImports(parameter.bootstrapWkt);
|
|
23
26
|
const createTypeImport = (desc) => {
|
|
24
27
|
const name = codegenInfo.localName(desc);
|
|
25
|
-
const from = makeImportPath(desc.file, bootstrapWkt, filesToGenerate);
|
|
28
|
+
const from = makeImportPath(desc.file, parameter.bootstrapWkt, filesToGenerate);
|
|
26
29
|
return createImportSymbol(name, from);
|
|
27
30
|
};
|
|
31
|
+
const createPreamble = (descFile) => makeFilePreamble(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
|
|
32
|
+
let target;
|
|
28
33
|
const generatedFiles = [];
|
|
29
|
-
|
|
30
|
-
targets,
|
|
34
|
+
return {
|
|
35
|
+
targets: parameter.targets,
|
|
31
36
|
runtime,
|
|
32
37
|
proto: request,
|
|
33
38
|
files: filesToGenerate,
|
|
34
39
|
allFiles: descriptorSet.files,
|
|
35
40
|
generateFile(name) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, keepEmptyFiles);
|
|
41
|
+
if (target === undefined) {
|
|
42
|
+
throw new Error("prepareGenerate() must be called before generateFile()");
|
|
43
|
+
}
|
|
44
|
+
const genFile = createGeneratedFile(name, deriveImportPath(name), target === "js" ? parameter.jsImportStyle : "module", // ts and dts always use import/export, only js may use commonjs
|
|
45
|
+
(importPath) => rewriteImportPath(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, createPreamble);
|
|
42
46
|
generatedFiles.push(genFile);
|
|
43
47
|
return genFile;
|
|
44
48
|
},
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
schema,
|
|
48
49
|
getFileInfo() {
|
|
49
|
-
return generatedFiles
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [fileInfo];
|
|
56
|
-
});
|
|
50
|
+
return generatedFiles
|
|
51
|
+
.map((f) => f.getFileInfo())
|
|
52
|
+
.filter((fi) => parameter.keepEmptyFiles || fi.content.length > 0);
|
|
53
|
+
},
|
|
54
|
+
prepareGenerate(newTarget) {
|
|
55
|
+
target = newTarget;
|
|
57
56
|
},
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
|
-
export function toResponse(files) {
|
|
61
|
-
return new CodeGeneratorResponse({
|
|
62
|
-
supportedFeatures: protoInt64.parse(CodeGeneratorResponse_Feature.PROTO3_OPTIONAL),
|
|
63
|
-
file: files.map((f) => {
|
|
64
|
-
if (f.preamble !== undefined) {
|
|
65
|
-
f.content = f.preamble + "\n" + f.content;
|
|
66
|
-
}
|
|
67
|
-
return f;
|
|
68
|
-
}),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
59
|
function findFilesToGenerate(descriptorSet, request) {
|
|
72
60
|
const missing = request.fileToGenerate.filter((fileToGenerate) => descriptorSet.files.every((file) => fileToGenerate !== file.name + ".proto"));
|
|
73
61
|
if (missing.length) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { FileInfo } from "./generated-file.js";
|
|
2
|
-
export declare function transpile(files: FileInfo[], transpileJs: boolean, transpileDts: boolean): FileInfo[];
|
|
2
|
+
export declare function transpile(files: FileInfo[], transpileJs: boolean, transpileDts: boolean, jsImportStyle: "module" | "legacy_commonjs"): FileInfo[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2024 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.
|
|
@@ -76,8 +76,11 @@ function createTranspiler(options, files) {
|
|
|
76
76
|
host: host.compilerHost,
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
export function transpile(files, transpileJs, transpileDts) {
|
|
79
|
+
export function transpile(files, transpileJs, transpileDts, jsImportStyle) {
|
|
80
80
|
const options = Object.assign(Object.assign({}, defaultOptions), { declaration: transpileDts, emitDeclarationOnly: transpileDts && !transpileJs });
|
|
81
|
+
if (jsImportStyle == "legacy_commonjs") {
|
|
82
|
+
options.module = ts.ModuleKind.CommonJS;
|
|
83
|
+
}
|
|
81
84
|
// Create the transpiler (a ts.Program object)
|
|
82
85
|
const program = createTranspiler(options, files);
|
|
83
86
|
const results = [];
|
package/dist/esm/error.js
CHANGED
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { Schema as SchemaInternal } from "./ecmascript/schema.js";
|
|
1
2
|
export { Plugin } from "./plugin.js";
|
|
2
|
-
export { Schema } from "./ecmascript/schema.js";
|
|
3
3
|
export { runNodeJs } from "./run-node.js";
|
|
4
4
|
export { createEcmaScriptPlugin } from "./create-es-plugin.js";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Please use Schema from @bufbuild/protoplugin/ecmascript instead
|
|
7
|
+
*/
|
|
8
|
+
export type Schema = SchemaInternal;
|
package/dist/esm/index.js
CHANGED
package/dist/esm/plugin.js
CHANGED
package/dist/esm/run-node.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@bufbuild/protobuf": "1.
|
|
50
|
+
"@bufbuild/protobuf": "1.7.0",
|
|
51
51
|
"@typescript/vfs": "^1.4.0",
|
|
52
52
|
"typescript": "4.5.2"
|
|
53
53
|
},
|