@bufbuild/protoplugin 2.11.0 → 2.12.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.
@@ -30,20 +30,20 @@ interface PluginInit<Options extends object> {
30
30
  * If your plugin does not recognize an option, it must throw an Error in
31
31
  * parseOptions.
32
32
  */
33
- parseOptions?: (rawOptions: {
33
+ parseOptions?: ((rawOptions: {
34
34
  key: string;
35
35
  value: string;
36
- }[]) => Options;
36
+ }[]) => Options) | undefined;
37
37
  /**
38
38
  * The earliest edition supported by this plugin. Defaults to the minimum
39
39
  * edition supported by @bufbuild/protobuf.
40
40
  */
41
- minimumEdition?: SupportedEdition;
41
+ minimumEdition?: SupportedEdition | undefined;
42
42
  /**
43
43
  * The latest edition supported by this plugin. Defaults to the maximum
44
44
  * edition supported by @bufbuild/protobuf.
45
45
  */
46
- maximumEdition?: SupportedEdition;
46
+ maximumEdition?: SupportedEdition | undefined;
47
47
  /**
48
48
  * A function which will generate TypeScript files based on proto input.
49
49
  * This function will be invoked by the plugin framework when the plugin runs.
@@ -61,7 +61,7 @@ interface PluginInit<Options extends object> {
61
61
  * JavaScript files. If not, the plugin framework will transpile the files
62
62
  * itself.
63
63
  */
64
- generateJs?: (schema: Schema<Options>, target: "js") => void;
64
+ generateJs?: ((schema: Schema<Options>, target: "js") => void) | undefined;
65
65
  /**
66
66
  * A optional function which will generate TypeScript declaration files
67
67
  * based on proto input. This function will be invoked by the plugin
@@ -72,7 +72,7 @@ interface PluginInit<Options extends object> {
72
72
  * declaration files. If not, the plugin framework will transpile the files
73
73
  * itself.
74
74
  */
75
- generateDts?: (schema: Schema<Options>, target: "dts") => void;
75
+ generateDts?: ((schema: Schema<Options>, target: "dts") => void) | undefined;
76
76
  /**
77
77
  * An optional function which will transpile a given set of files.
78
78
  *
@@ -86,7 +86,7 @@ interface PluginInit<Options extends object> {
86
86
  * transpiling to JS. If jsImportStyle is "legacy_commonjs", the function is
87
87
  * expected to use CommonJs require() and exports when transpiling to JS.
88
88
  */
89
- transpile?: (files: FileInfo[], transpileJs: boolean, transpileDts: boolean, jsImportStyle: "module" | "legacy_commonjs") => FileInfo[];
89
+ transpile?: ((files: FileInfo[], transpileJs: boolean, transpileDts: boolean, jsImportStyle: "module" | "legacy_commonjs") => FileInfo[]) | undefined;
90
90
  }
91
91
  /**
92
92
  * Create a new code generator plugin for ECMAScript.
@@ -58,7 +58,10 @@ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck)
58
58
  builder.push("syntax proto3)\n");
59
59
  break;
60
60
  default: {
61
- const editionString = wkt_1.Edition[file.edition];
61
+ // Report the raw edition from the descriptor so files using
62
+ // EDITION_UNSTABLE (which we collapse to maximumEdition internally)
63
+ // still render as "edition unstable".
64
+ const editionString = wkt_1.Edition[file.proto.edition];
62
65
  if (typeof editionString == "string") {
63
66
  const e = editionString.replace("EDITION_", "").toLowerCase();
64
67
  builder.push(`edition ${e})\n`);
@@ -39,5 +39,5 @@ export type ValidTypeImport = {
39
39
  export type JSDocBlock = {
40
40
  readonly kind: "es_jsdoc";
41
41
  text: string;
42
- indentation?: string;
42
+ indentation?: string | undefined;
43
43
  };
@@ -86,6 +86,11 @@ function getFilesToGenerate(request, minimumEdition, maximumEdition) {
86
86
  edition = wkt_1.Edition.EDITION_UNKNOWN;
87
87
  break;
88
88
  }
89
+ // EDITION_UNSTABLE is a sandbox for in-development features; accept
90
+ // it regardless of the plugin's min/max bounds.
91
+ if (edition === wkt_1.Edition.EDITION_UNSTABLE) {
92
+ continue;
93
+ }
89
94
  if (edition < minimumEdition) {
90
95
  throw new Error(`${file.name}: unsupported edition ${editionToString(edition)} - the earliest supported edition is ${editionToString(minimumEdition)}`);
91
96
  }
@@ -42,9 +42,11 @@ const vfs_1 = require("@typescript/vfs");
42
42
  * npm does not support that yet.
43
43
  */
44
44
  function createTranspiler(options, files) {
45
- const fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
46
- target: options.target,
47
- });
45
+ const fsMapOptions = {};
46
+ if (options.target) {
47
+ fsMapOptions.target = options.target;
48
+ }
49
+ const fsMap = (0, vfs_1.createDefaultMapFromNodeModules)(fsMapOptions);
48
50
  for (const file of files) {
49
51
  fsMap.set(file.name, file.content);
50
52
  }
@@ -30,20 +30,20 @@ interface PluginInit<Options extends object> {
30
30
  * If your plugin does not recognize an option, it must throw an Error in
31
31
  * parseOptions.
32
32
  */
33
- parseOptions?: (rawOptions: {
33
+ parseOptions?: ((rawOptions: {
34
34
  key: string;
35
35
  value: string;
36
- }[]) => Options;
36
+ }[]) => Options) | undefined;
37
37
  /**
38
38
  * The earliest edition supported by this plugin. Defaults to the minimum
39
39
  * edition supported by @bufbuild/protobuf.
40
40
  */
41
- minimumEdition?: SupportedEdition;
41
+ minimumEdition?: SupportedEdition | undefined;
42
42
  /**
43
43
  * The latest edition supported by this plugin. Defaults to the maximum
44
44
  * edition supported by @bufbuild/protobuf.
45
45
  */
46
- maximumEdition?: SupportedEdition;
46
+ maximumEdition?: SupportedEdition | undefined;
47
47
  /**
48
48
  * A function which will generate TypeScript files based on proto input.
49
49
  * This function will be invoked by the plugin framework when the plugin runs.
@@ -61,7 +61,7 @@ interface PluginInit<Options extends object> {
61
61
  * JavaScript files. If not, the plugin framework will transpile the files
62
62
  * itself.
63
63
  */
64
- generateJs?: (schema: Schema<Options>, target: "js") => void;
64
+ generateJs?: ((schema: Schema<Options>, target: "js") => void) | undefined;
65
65
  /**
66
66
  * A optional function which will generate TypeScript declaration files
67
67
  * based on proto input. This function will be invoked by the plugin
@@ -72,7 +72,7 @@ interface PluginInit<Options extends object> {
72
72
  * declaration files. If not, the plugin framework will transpile the files
73
73
  * itself.
74
74
  */
75
- generateDts?: (schema: Schema<Options>, target: "dts") => void;
75
+ generateDts?: ((schema: Schema<Options>, target: "dts") => void) | undefined;
76
76
  /**
77
77
  * An optional function which will transpile a given set of files.
78
78
  *
@@ -86,7 +86,7 @@ interface PluginInit<Options extends object> {
86
86
  * transpiling to JS. If jsImportStyle is "legacy_commonjs", the function is
87
87
  * expected to use CommonJs require() and exports when transpiling to JS.
88
88
  */
89
- transpile?: (files: FileInfo[], transpileJs: boolean, transpileDts: boolean, jsImportStyle: "module" | "legacy_commonjs") => FileInfo[];
89
+ transpile?: ((files: FileInfo[], transpileJs: boolean, transpileDts: boolean, jsImportStyle: "module" | "legacy_commonjs") => FileInfo[]) | undefined;
90
90
  }
91
91
  /**
92
92
  * Create a new code generator plugin for ECMAScript.
@@ -55,7 +55,10 @@ export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsN
55
55
  builder.push("syntax proto3)\n");
56
56
  break;
57
57
  default: {
58
- const editionString = Edition[file.edition];
58
+ // Report the raw edition from the descriptor so files using
59
+ // EDITION_UNSTABLE (which we collapse to maximumEdition internally)
60
+ // still render as "edition unstable".
61
+ const editionString = Edition[file.proto.edition];
59
62
  if (typeof editionString == "string") {
60
63
  const e = editionString.replace("EDITION_", "").toLowerCase();
61
64
  builder.push(`edition ${e})\n`);
@@ -39,5 +39,5 @@ export type ValidTypeImport = {
39
39
  export type JSDocBlock = {
40
40
  readonly kind: "es_jsdoc";
41
41
  text: string;
42
- indentation?: string;
42
+ indentation?: string | undefined;
43
43
  };
@@ -83,6 +83,11 @@ function getFilesToGenerate(request, minimumEdition, maximumEdition) {
83
83
  edition = Edition.EDITION_UNKNOWN;
84
84
  break;
85
85
  }
86
+ // EDITION_UNSTABLE is a sandbox for in-development features; accept
87
+ // it regardless of the plugin's min/max bounds.
88
+ if (edition === Edition.EDITION_UNSTABLE) {
89
+ continue;
90
+ }
86
91
  if (edition < minimumEdition) {
87
92
  throw new Error(`${file.name}: unsupported edition ${editionToString(edition)} - the earliest supported edition is ${editionToString(minimumEdition)}`);
88
93
  }
@@ -36,9 +36,11 @@ import { createDefaultMapFromNodeModules, createSystem, createVirtualCompilerHos
36
36
  * npm does not support that yet.
37
37
  */
38
38
  function createTranspiler(options, files) {
39
- const fsMap = createDefaultMapFromNodeModules({
40
- target: options.target,
41
- });
39
+ const fsMapOptions = {};
40
+ if (options.target) {
41
+ fsMapOptions.target = options.target;
42
+ }
43
+ const fsMap = createDefaultMapFromNodeModules(fsMapOptions);
42
44
  for (const file of files) {
43
45
  fsMap.set(file.name, file.content);
44
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Helps to create your own Protocol Buffers code generators.",
6
6
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@bufbuild/protobuf": "2.11.0",
38
+ "@bufbuild/protobuf": "2.12.0",
39
39
  "@typescript/vfs": "^1.6.2",
40
40
  "typescript": "5.4.5"
41
41
  },