@bufbuild/protoplugin 1.3.1 → 1.3.2
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/{types → cjs}/ecmascript/index.d.ts +1 -1
- package/dist/esm/create-es-plugin.d.ts +64 -0
- package/dist/esm/ecmascript/custom-options.d.ts +32 -0
- package/dist/esm/ecmascript/gencommon.d.ts +21 -0
- package/dist/esm/ecmascript/generated-file.d.ts +81 -0
- package/dist/esm/ecmascript/import-path.d.ts +65 -0
- package/dist/esm/ecmascript/import-symbol.d.ts +39 -0
- package/dist/esm/ecmascript/index.d.ts +8 -0
- package/dist/esm/ecmascript/runtime-imports.d.ts +23 -0
- package/dist/esm/ecmascript/schema.d.ts +43 -0
- package/dist/esm/ecmascript/target.d.ts +4 -0
- package/dist/esm/ecmascript/transpile.d.ts +2 -0
- package/dist/esm/error.d.ts +4 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/plugin.d.ts +18 -0
- package/dist/esm/run-node.d.ts +12 -0
- package/package.json +25 -12
- /package/dist/{types → cjs}/create-es-plugin.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/custom-options.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/gencommon.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/generated-file.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/import-path.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/import-symbol.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/runtime-imports.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/schema.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/target.d.ts +0 -0
- /package/dist/{types → cjs}/ecmascript/transpile.d.ts +0 -0
- /package/dist/{types → cjs}/error.d.ts +0 -0
- /package/dist/{types → cjs}/index.d.ts +0 -0
- /package/dist/{types → cjs}/plugin.d.ts +0 -0
- /package/dist/{types → cjs}/run-node.d.ts +0 -0
|
@@ -3,6 +3,6 @@ export { Schema } from "./schema.js";
|
|
|
3
3
|
export { RuntimeImports } from "./runtime-imports.js";
|
|
4
4
|
export { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
|
|
5
5
|
export { ImportSymbol } from "./import-symbol.js";
|
|
6
|
-
export declare const localName: typeof import("@bufbuild/protobuf/dist/
|
|
6
|
+
export declare const localName: typeof import("@bufbuild/protobuf/dist/cjs/private/names.js").localName, reifyWkt: typeof import("@bufbuild/protobuf/dist/cjs/private/reify-wkt.js").reifyWkt;
|
|
7
7
|
export { createJsDocBlock, getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, makeJsDoc, literalString, } from "./gencommon.js";
|
|
8
8
|
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Schema } from "./ecmascript/schema.js";
|
|
2
|
+
import type { FileInfo } from "./ecmascript/generated-file.js";
|
|
3
|
+
import type { Plugin } from "./plugin.js";
|
|
4
|
+
interface PluginInit {
|
|
5
|
+
/**
|
|
6
|
+
* Name of this code generator plugin.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Version of this code generator plugin.
|
|
11
|
+
*/
|
|
12
|
+
version: string;
|
|
13
|
+
/**
|
|
14
|
+
* A optional parsing function which can be used to customize parameter
|
|
15
|
+
* parsing of the plugin.
|
|
16
|
+
*/
|
|
17
|
+
parseOption?: PluginOptionParseFn;
|
|
18
|
+
/**
|
|
19
|
+
* A function which will generate TypeScript files based on proto input.
|
|
20
|
+
* This function will be invoked by the plugin framework when the plugin runs.
|
|
21
|
+
*
|
|
22
|
+
* Note that this is required to be provided for plugin initialization.
|
|
23
|
+
*/
|
|
24
|
+
generateTs: (schema: Schema, target: "ts") => void;
|
|
25
|
+
/**
|
|
26
|
+
* A optional function which will generate JavaScript files based on proto
|
|
27
|
+
* input. This function will be invoked by the plugin framework when the
|
|
28
|
+
* plugin runs.
|
|
29
|
+
*
|
|
30
|
+
* If this function is not provided, the plugin framework will then check if
|
|
31
|
+
* a transpile function is provided. If so, it will be invoked to transpile
|
|
32
|
+
* JavaScript files. If not, the plugin framework will transpile the files
|
|
33
|
+
* itself.
|
|
34
|
+
*/
|
|
35
|
+
generateJs?: (schema: Schema, target: "js") => void;
|
|
36
|
+
/**
|
|
37
|
+
* A optional function which will generate TypeScript declaration files
|
|
38
|
+
* based on proto input. This function will be invoked by the plugin
|
|
39
|
+
* framework when the plugin runs.
|
|
40
|
+
*
|
|
41
|
+
* If this function is not provided, the plugin framework will then check if
|
|
42
|
+
* a transpile function is provided. If so, it will be invoked to transpile
|
|
43
|
+
* declaration files. If not, the plugin framework will transpile the files
|
|
44
|
+
* itself.
|
|
45
|
+
*/
|
|
46
|
+
generateDts?: (schema: Schema, target: "dts") => void;
|
|
47
|
+
/**
|
|
48
|
+
* A optional function which will transpile a given set of files.
|
|
49
|
+
*
|
|
50
|
+
* This funcion is meant to be used in place of either generateJs,
|
|
51
|
+
* generateDts, or both. However, those functions will take precedence.
|
|
52
|
+
* This means that if generateJs, generateDts, and this transpile function
|
|
53
|
+
* are all provided, this transpile function will be ignored.
|
|
54
|
+
*/
|
|
55
|
+
transpile?: (files: FileInfo[], transpileJs: boolean, transpileDts: boolean) => FileInfo[];
|
|
56
|
+
}
|
|
57
|
+
type PluginOptionParseFn = (key: string, value: string | undefined) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new code generator plugin for ECMAScript.
|
|
60
|
+
* The plugin can generate JavaScript, TypeScript, or TypeScript declaration
|
|
61
|
+
* files.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createEcmaScriptPlugin(init: PluginInit): Plugin;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnyDesc } from "@bufbuild/protobuf";
|
|
2
|
+
import { Message, MessageType, ScalarType } from "@bufbuild/protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the value of a custom option with a scalar type.
|
|
5
|
+
*
|
|
6
|
+
* If no option is found, returns undefined.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, extensionNumber: number, scalarType: T): ScalarValue<T> | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value of a custom message option for the given descriptor and
|
|
11
|
+
* extension number.
|
|
12
|
+
* The msgType param is then used to deserialize the message for returning to
|
|
13
|
+
* the caller.
|
|
14
|
+
*
|
|
15
|
+
* If no options are found, returns undefined.
|
|
16
|
+
*
|
|
17
|
+
* If the message option is unable to be read or deserialized, an error will
|
|
18
|
+
* be thrown.
|
|
19
|
+
*/
|
|
20
|
+
export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, extensionNumber: number, msgType: MessageType<T>): T | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the value of a custom enum option for the given descriptor and
|
|
23
|
+
* extension number.
|
|
24
|
+
*
|
|
25
|
+
* If no options are found, returns undefined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findCustomEnumOption(desc: AnyDesc, extensionNumber: number): number | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* ScalarValue is a conditional type that pairs a ScalarType value with its concrete type.
|
|
30
|
+
*/
|
|
31
|
+
type ScalarValue<T> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? bigint | string : T extends ScalarType.SINT64 ? bigint | string : T extends ScalarType.SFIXED64 ? bigint | string : T extends ScalarType.UINT64 ? bigint | string : T extends ScalarType.FIXED64 ? bigint | string : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DescEnum, DescEnumValue, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, ScalarType } from "@bufbuild/protobuf";
|
|
2
|
+
import type { GeneratedFile, Printable } from "./generated-file.js";
|
|
3
|
+
import type { ImportSymbol } from "./import-symbol.js";
|
|
4
|
+
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
|
|
5
|
+
export declare function createJsDocBlock(text: string, indentation?: string): Printable;
|
|
6
|
+
export declare function makeJsDoc(desc: DescEnum | DescEnumValue | DescMessage | DescOneof | DescField | DescService | DescMethod, indentation?: string): Printable;
|
|
7
|
+
/**
|
|
8
|
+
* Returns an expression for the TypeScript typing of a field,
|
|
9
|
+
* and whether the property should be optional.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getFieldTyping(field: DescField, file: GeneratedFile): {
|
|
12
|
+
typing: Printable;
|
|
13
|
+
optional: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function scalarTypeScriptType(type: ScalarType): Printable;
|
|
16
|
+
export declare function literalString(value: string): string;
|
|
17
|
+
export declare function getFieldExplicitDefaultValue(field: DescField, protoInt64Symbol: ImportSymbol): Printable | undefined;
|
|
18
|
+
export declare function getFieldIntrinsicDefaultValue(field: DescField): {
|
|
19
|
+
defaultValue: Printable | undefined;
|
|
20
|
+
typingInferrable: boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { DescEnum, DescFile, DescMessage } from "@bufbuild/protobuf";
|
|
2
|
+
import type { ImportSymbol } from "./import-symbol.js";
|
|
3
|
+
import type { RuntimeImports } from "./runtime-imports.js";
|
|
4
|
+
/**
|
|
5
|
+
* All types that can be passed to GeneratedFile.print()
|
|
6
|
+
*/
|
|
7
|
+
export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | DescMessage | DescEnum | Printable[];
|
|
8
|
+
/**
|
|
9
|
+
* FileInfo represents an intermediate type using for transpiling TypeScript internally.
|
|
10
|
+
*/
|
|
11
|
+
export interface FileInfo {
|
|
12
|
+
name: string;
|
|
13
|
+
content: string;
|
|
14
|
+
preamble?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents a JavaScript, TypeScript, or TypeScript declaration file.
|
|
18
|
+
*/
|
|
19
|
+
export interface GeneratedFile {
|
|
20
|
+
/**
|
|
21
|
+
* Create a standard preamble the includes comments at the top of the
|
|
22
|
+
* protobuf source file (like a license header), as well as information
|
|
23
|
+
* about the code generator and its version.
|
|
24
|
+
*
|
|
25
|
+
* The preamble is always placed at the very top of the generated file,
|
|
26
|
+
* above import statements.
|
|
27
|
+
*
|
|
28
|
+
* A file with a preamble but no other content is still considered empty,
|
|
29
|
+
* and will not be generated unless the plugin option keep_empty_files=true
|
|
30
|
+
* is set.
|
|
31
|
+
*/
|
|
32
|
+
preamble(file: DescFile): void;
|
|
33
|
+
/**
|
|
34
|
+
* Add a line of code to the file.
|
|
35
|
+
*
|
|
36
|
+
* - string: Prints the string verbatim.
|
|
37
|
+
* - number or boolean: Prints a literal.
|
|
38
|
+
* - bigint: Prints an expression using protoInt64.parse().
|
|
39
|
+
* - Uint8Array: Prints an expression that re-created the array.
|
|
40
|
+
* - ImportSymbol: Adds an import statement and prints the name of the symbol.
|
|
41
|
+
* - DescMessage or DescEnum: Imports the type if necessary, and prints the name.
|
|
42
|
+
*/
|
|
43
|
+
print(...printables: Printable[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Add a line of code to the file with tagged template literal and
|
|
46
|
+
* an optional array of Printables.
|
|
47
|
+
* See print(Printable[]) for behavior when printing Printable items.
|
|
48
|
+
*/
|
|
49
|
+
print(fragments: TemplateStringsArray, ...printables: Printable[]): void;
|
|
50
|
+
/**
|
|
51
|
+
* Reserves an identifier in this file.
|
|
52
|
+
*/
|
|
53
|
+
export(name: string): ImportSymbol;
|
|
54
|
+
/**
|
|
55
|
+
* Import a message or enumeration generated by protoc-gen-es.
|
|
56
|
+
*/
|
|
57
|
+
import(type: DescMessage | DescEnum): ImportSymbol;
|
|
58
|
+
/**
|
|
59
|
+
* Import any symbol from a file or package.
|
|
60
|
+
*
|
|
61
|
+
* The import path can point to a package, for example `@foo/bar/baz.js`, or
|
|
62
|
+
* to a file, for example `./bar/baz.js`.
|
|
63
|
+
*
|
|
64
|
+
* Note that while paths to a file begin with a `./`, they must be
|
|
65
|
+
* relative to the project root. The import path is automatically made
|
|
66
|
+
* relative to the current file.
|
|
67
|
+
*/
|
|
68
|
+
import(name: string, from: string): ImportSymbol;
|
|
69
|
+
}
|
|
70
|
+
export interface GenerateFileToFileInfo {
|
|
71
|
+
getFileInfo(): FileInfo | undefined;
|
|
72
|
+
}
|
|
73
|
+
type CreateTypeImportFn = (desc: DescMessage | DescEnum) => ImportSymbol;
|
|
74
|
+
type RewriteImportPathFn = (path: string) => string;
|
|
75
|
+
export declare function createGeneratedFile(name: string, importPath: string, rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, preambleSettings: {
|
|
76
|
+
pluginName: string;
|
|
77
|
+
pluginVersion: string;
|
|
78
|
+
pluginParameter: string;
|
|
79
|
+
tsNocheck: boolean;
|
|
80
|
+
}, keepEmpty: boolean): GeneratedFile & GenerateFileToFileInfo;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DescFile } from "@bufbuild/protobuf";
|
|
2
|
+
/**
|
|
3
|
+
* A configuration for rewriting import paths, a feature mainly used for
|
|
4
|
+
* remote code generation in the BSR npm registry, which makes it possible
|
|
5
|
+
* to serve the output of a BSR module and a plugin in an individual package.
|
|
6
|
+
*
|
|
7
|
+
* All plugins based on @bufbuild/protoplugin support the option
|
|
8
|
+
* "rewrite_imports", which is parsed into this type. The option can be given
|
|
9
|
+
* multiple times, in the form of `rewrite_imports=<pattern>:<target>`.
|
|
10
|
+
*
|
|
11
|
+
* The pattern is a very reduced subset of glob:
|
|
12
|
+
* - `*` matches zero or more characters except `/`.
|
|
13
|
+
* - `**` matches zero or more path elements, where an element is one or more
|
|
14
|
+
* characters with a trailing `/`.
|
|
15
|
+
*
|
|
16
|
+
* The target is typically a npm package name, for example `@scope/pkg`.
|
|
17
|
+
*
|
|
18
|
+
* If any generated file imports from a path matching one of the patterns, the
|
|
19
|
+
* import path is rewritten to the corresponding target, by prepending the
|
|
20
|
+
* target to the import path (after replacing any leading ./ or ../ from the
|
|
21
|
+
* import path with / first).
|
|
22
|
+
*
|
|
23
|
+
* Note that the pattern is matched against the import path before it is made
|
|
24
|
+
* relative to the file importing it. The first matching pattern wins.
|
|
25
|
+
*
|
|
26
|
+
* For example, the pattern `./foo/**\/*_pb.js` (escaped for block comment!)
|
|
27
|
+
* matches:
|
|
28
|
+
* - ./foo/bar_pb.js
|
|
29
|
+
* - ./foo/bar/baz_pb.js
|
|
30
|
+
*
|
|
31
|
+
* But neither of:
|
|
32
|
+
* - ./bar_pb.js
|
|
33
|
+
* - ./foo/bar_xx.js
|
|
34
|
+
*
|
|
35
|
+
* With the target `@scope/pkg`, the import path `./foo/bar_pb.js` is
|
|
36
|
+
* transformed to `@scope/pkg/foo/bar_pb.js`.
|
|
37
|
+
*/
|
|
38
|
+
export type RewriteImports = {
|
|
39
|
+
pattern: string;
|
|
40
|
+
target: string;
|
|
41
|
+
}[];
|
|
42
|
+
/**
|
|
43
|
+
* Apply import rewrites to the given import path, and change all .js extensions
|
|
44
|
+
* to the given import extension.
|
|
45
|
+
*/
|
|
46
|
+
export declare function rewriteImportPath(importPath: string, rewriteImports: RewriteImports, importExtension: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the import path for files generated by the base type generator
|
|
49
|
+
* protoc-gen-es.
|
|
50
|
+
*/
|
|
51
|
+
export declare function makeImportPath(file: DescFile, bootstrapWkt: boolean, filesToGenerate: DescFile[]): string;
|
|
52
|
+
export declare const relativePathRE: RegExp;
|
|
53
|
+
/**
|
|
54
|
+
* Derives an ECMAScript module import path from a file path. For example,
|
|
55
|
+
* the path `foo/bar.ts` is transformed into `./foo/bar.js`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function deriveImportPath(filename: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Makes an import path relative to the file importing it. For example,
|
|
60
|
+
* consider the following files:
|
|
61
|
+
* - foo/foo.js
|
|
62
|
+
* - baz.js
|
|
63
|
+
* If foo.js wants to import baz.js, we return ../baz.js
|
|
64
|
+
*/
|
|
65
|
+
export declare function makeImportPathRelative(importer: string, importPath: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An import symbol represents an ECMAScript import.
|
|
3
|
+
*/
|
|
4
|
+
export type ImportSymbol = {
|
|
5
|
+
readonly kind: "es_symbol";
|
|
6
|
+
/**
|
|
7
|
+
* The name to import.
|
|
8
|
+
*/
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The import path.
|
|
12
|
+
*
|
|
13
|
+
* The path can point to a package, for example `@foo/bar/baz.js`, or
|
|
14
|
+
* to a file, for example `./bar/baz.js`.
|
|
15
|
+
*
|
|
16
|
+
* Note that while paths to a file begin with a `./`, they must be
|
|
17
|
+
* relative to the project root.
|
|
18
|
+
*/
|
|
19
|
+
readonly from: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether this is a type-only import - an import that only exists in
|
|
22
|
+
* TypeScript.
|
|
23
|
+
*/
|
|
24
|
+
readonly typeOnly: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Create a copy of this import, and make it type-only for TypeScript.
|
|
27
|
+
*/
|
|
28
|
+
toTypeOnly(): ImportSymbol;
|
|
29
|
+
/**
|
|
30
|
+
* The unique ID based on name and from, disregarding typeOnly.
|
|
31
|
+
*/
|
|
32
|
+
readonly id: EsSymbolId;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a new import symbol.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createImportSymbol(name: string, from: string, typeOnly?: boolean): ImportSymbol;
|
|
38
|
+
type EsSymbolId = string;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Target } from "./target.js";
|
|
2
|
+
export { Schema } from "./schema.js";
|
|
3
|
+
export { RuntimeImports } from "./runtime-imports.js";
|
|
4
|
+
export { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
|
|
5
|
+
export { ImportSymbol } from "./import-symbol.js";
|
|
6
|
+
export declare const localName: typeof import("@bufbuild/protobuf/dist/cjs/private/names.js").localName, reifyWkt: typeof import("@bufbuild/protobuf/dist/cjs/private/reify-wkt.js").reifyWkt;
|
|
7
|
+
export { createJsDocBlock, getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, makeJsDoc, literalString, } from "./gencommon.js";
|
|
8
|
+
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ImportSymbol } from "./import-symbol.js";
|
|
2
|
+
export interface RuntimeImports {
|
|
3
|
+
proto2: ImportSymbol;
|
|
4
|
+
proto3: ImportSymbol;
|
|
5
|
+
Message: ImportSymbol;
|
|
6
|
+
PartialMessage: ImportSymbol;
|
|
7
|
+
PlainMessage: ImportSymbol;
|
|
8
|
+
FieldList: ImportSymbol;
|
|
9
|
+
MessageType: ImportSymbol;
|
|
10
|
+
BinaryReadOptions: ImportSymbol;
|
|
11
|
+
BinaryWriteOptions: ImportSymbol;
|
|
12
|
+
JsonReadOptions: ImportSymbol;
|
|
13
|
+
JsonWriteOptions: ImportSymbol;
|
|
14
|
+
JsonValue: ImportSymbol;
|
|
15
|
+
JsonObject: ImportSymbol;
|
|
16
|
+
protoDouble: ImportSymbol;
|
|
17
|
+
protoInt64: ImportSymbol;
|
|
18
|
+
ScalarType: ImportSymbol;
|
|
19
|
+
MethodKind: ImportSymbol;
|
|
20
|
+
MethodIdempotency: ImportSymbol;
|
|
21
|
+
IMessageTypeRegistry: ImportSymbol;
|
|
22
|
+
}
|
|
23
|
+
export declare function createRuntimeImports(bootstrapWkt: boolean): RuntimeImports;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CodeGeneratorRequest, DescFile } from "@bufbuild/protobuf";
|
|
2
|
+
import { CodeGeneratorResponse } from "@bufbuild/protobuf";
|
|
3
|
+
import type { FileInfo, GeneratedFile } from "./generated-file.js";
|
|
4
|
+
import { RuntimeImports } from "./runtime-imports.js";
|
|
5
|
+
import type { Target } from "./target.js";
|
|
6
|
+
import { RewriteImports } from "./import-path.js";
|
|
7
|
+
/**
|
|
8
|
+
* Schema describes the files and types that the plugin is requested to
|
|
9
|
+
* generate.
|
|
10
|
+
*/
|
|
11
|
+
export interface Schema {
|
|
12
|
+
/**
|
|
13
|
+
* The files we are asked to generate.
|
|
14
|
+
*/
|
|
15
|
+
readonly files: readonly DescFile[];
|
|
16
|
+
/**
|
|
17
|
+
* All files contained in the code generator request.
|
|
18
|
+
*/
|
|
19
|
+
readonly allFiles: readonly DescFile[];
|
|
20
|
+
/**
|
|
21
|
+
* The plugin option `target`. A code generator should support all targets.
|
|
22
|
+
*/
|
|
23
|
+
readonly targets: readonly Target[];
|
|
24
|
+
/**
|
|
25
|
+
* Provides some symbols from the runtime library @bufbuild/protobuf.
|
|
26
|
+
*/
|
|
27
|
+
readonly runtime: RuntimeImports;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a new file with the given name.
|
|
30
|
+
*/
|
|
31
|
+
generateFile(name: string): GeneratedFile;
|
|
32
|
+
/**
|
|
33
|
+
* The original google.protobuf.compiler.CodeGeneratorRequest.
|
|
34
|
+
*/
|
|
35
|
+
readonly proto: CodeGeneratorRequest;
|
|
36
|
+
}
|
|
37
|
+
interface SchemaController {
|
|
38
|
+
schema: Schema;
|
|
39
|
+
getFileInfo: () => FileInfo[];
|
|
40
|
+
}
|
|
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
|
+
export declare function toResponse(files: FileInfo[]): CodeGeneratorResponse;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CodeGeneratorRequest, CodeGeneratorResponse } from "@bufbuild/protobuf";
|
|
2
|
+
/**
|
|
3
|
+
* Represents any code generator plugin.
|
|
4
|
+
*/
|
|
5
|
+
export interface Plugin {
|
|
6
|
+
/**
|
|
7
|
+
* Name of this code generator plugin.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Version of this code generator plugin.
|
|
12
|
+
*/
|
|
13
|
+
version: string;
|
|
14
|
+
/**
|
|
15
|
+
* Run this plugin for the given request.
|
|
16
|
+
*/
|
|
17
|
+
run(request: CodeGeneratorRequest): CodeGeneratorResponse;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin } from "./plugin.js";
|
|
2
|
+
/**
|
|
3
|
+
* Run a plugin with Node.js.
|
|
4
|
+
*
|
|
5
|
+
* ```
|
|
6
|
+
* #!/usr/bin/env node
|
|
7
|
+
* const {runNodeJs} = require("@bufbuild/protoplugin");
|
|
8
|
+
* const {myPlugin} = require("./protoc-gen-x-plugin.js");
|
|
9
|
+
* runNodeJs(myPlugin);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function runNodeJs(plugin: Plugin): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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": {
|
|
@@ -10,32 +10,45 @@
|
|
|
10
10
|
},
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"scripts": {
|
|
13
|
-
"clean": "rm -rf ./dist/cjs/* ./dist/esm/*
|
|
14
|
-
"build": "npm run build:cjs && npm run build:esm
|
|
15
|
-
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
16
|
-
"build:esm
|
|
13
|
+
"clean": "rm -rf ./dist/cjs/* ./dist/esm/*",
|
|
14
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
15
|
+
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
16
|
+
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
|
|
17
|
+
"attw": "attw --pack"
|
|
17
18
|
},
|
|
19
|
+
"main": "./dist/cjs/index.js",
|
|
18
20
|
"type": "module",
|
|
19
21
|
"exports": {
|
|
20
22
|
".": {
|
|
21
|
-
"import":
|
|
22
|
-
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/esm/index.d.ts",
|
|
25
|
+
"default": "./dist/esm/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/cjs/index.d.ts",
|
|
29
|
+
"default": "./dist/cjs/index.js"
|
|
30
|
+
}
|
|
23
31
|
},
|
|
24
32
|
"./ecmascript": {
|
|
25
|
-
"import":
|
|
26
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/ecmascript/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/ecmascript/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/ecmascript/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/ecmascript/index.js"
|
|
40
|
+
}
|
|
27
41
|
}
|
|
28
42
|
},
|
|
29
|
-
"types": "./dist/types/index.d.ts",
|
|
30
43
|
"typesVersions": {
|
|
31
44
|
"*": {
|
|
32
45
|
"ecmascript": [
|
|
33
|
-
"./dist/
|
|
46
|
+
"./dist/cjs/ecmascript/index.d.ts"
|
|
34
47
|
]
|
|
35
48
|
}
|
|
36
49
|
},
|
|
37
50
|
"dependencies": {
|
|
38
|
-
"@bufbuild/protobuf": "1.3.
|
|
51
|
+
"@bufbuild/protobuf": "1.3.2",
|
|
39
52
|
"@typescript/vfs": "^1.4.0",
|
|
40
53
|
"typescript": "4.5.2"
|
|
41
54
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|