@bufbuild/protoplugin 1.7.2 → 1.8.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.
Files changed (45) hide show
  1. package/dist/cjs/ecmascript/file-preamble.d.ts +2 -0
  2. package/dist/cjs/ecmascript/file-preamble.js +74 -0
  3. package/dist/cjs/ecmascript/generated-file.d.ts +3 -3
  4. package/dist/cjs/ecmascript/generated-file.js +90 -31
  5. package/dist/cjs/ecmascript/index.d.ts +2 -6
  6. package/dist/cjs/ecmascript/index.js +10 -17
  7. package/dist/cjs/ecmascript/jsdoc.d.ts +6 -0
  8. package/dist/cjs/ecmascript/jsdoc.js +1 -0
  9. package/dist/cjs/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -6
  10. package/dist/cjs/ecmascript/{gencommon.js → legacy-gencommon.js} +50 -98
  11. package/dist/cjs/ecmascript/opaque-printables.d.ts +26 -0
  12. package/dist/{esm/ecmascript/export-declaration.js → cjs/ecmascript/opaque-printables.js} +2 -7
  13. package/dist/cjs/ecmascript/schema.d.ts +1 -1
  14. package/dist/cjs/ecmascript/schema.js +2 -2
  15. package/dist/cjs/error.d.ts +2 -0
  16. package/dist/cjs/error.js +9 -1
  17. package/dist/cjs/run-node.js +1 -1
  18. package/dist/esm/ecmascript/file-preamble.d.ts +2 -0
  19. package/dist/esm/ecmascript/file-preamble.js +70 -0
  20. package/dist/esm/ecmascript/generated-file.d.ts +3 -3
  21. package/dist/esm/ecmascript/generated-file.js +90 -31
  22. package/dist/esm/ecmascript/index.d.ts +2 -6
  23. package/dist/esm/ecmascript/index.js +2 -9
  24. package/dist/esm/ecmascript/jsdoc.d.ts +6 -0
  25. package/dist/esm/ecmascript/jsdoc.js +1 -0
  26. package/dist/esm/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -6
  27. package/dist/esm/ecmascript/{gencommon.js → legacy-gencommon.js} +49 -95
  28. package/dist/esm/ecmascript/opaque-printables.d.ts +26 -0
  29. package/dist/{cjs/ecmascript/export-declaration.js → esm/ecmascript/opaque-printables.js} +1 -11
  30. package/dist/esm/ecmascript/schema.d.ts +1 -1
  31. package/dist/esm/ecmascript/schema.js +1 -1
  32. package/dist/esm/error.d.ts +2 -0
  33. package/dist/esm/error.js +7 -0
  34. package/dist/esm/run-node.js +2 -2
  35. package/package.json +3 -14
  36. package/dist/cjs/ecmascript/export-declaration.d.ts +0 -7
  37. package/dist/esm/ecmascript/export-declaration.d.ts +0 -7
  38. package/dist/proxy/ecmascript/index.d.ts +0 -1
  39. package/dist/proxy/ecmascript/index.js +0 -1
  40. package/dist/proxy/index.d.ts +0 -1
  41. package/dist/proxy/index.js +0 -1
  42. /package/dist/cjs/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +0 -0
  43. /package/dist/cjs/ecmascript/{custom-options.js → legacy-custom-options.js} +0 -0
  44. /package/dist/esm/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +0 -0
  45. /package/dist/esm/ecmascript/{custom-options.js → legacy-custom-options.js} +0 -0
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,13 +11,4 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createExportDeclaration = void 0;
17
- function createExportDeclaration(declaration, name) {
18
- return {
19
- kind: "es_export_decl",
20
- declaration,
21
- name,
22
- };
23
- }
24
- exports.createExportDeclaration = createExportDeclaration;
14
+ export {};
@@ -3,7 +3,7 @@ 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 { ParsedParameter } from "./parameter";
6
+ import { ParsedParameter } from "./parameter.js";
7
7
  /**
8
8
  * Schema describes the files and types that the plugin is requested to
9
9
  * generate.
@@ -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
- import { makeFilePreamble } from "./gencommon";
19
+ import { makeFilePreamble } from "./file-preamble.js";
20
20
  export function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
21
21
  const descriptorSet = createDescriptorSet(request.protoFile, {
22
22
  featureSetDefaults,
@@ -1,4 +1,6 @@
1
1
  export declare class PluginOptionError extends Error {
2
+ name: string;
2
3
  constructor(option: string, reason?: unknown);
3
4
  }
4
5
  export declare function reasonToString(reason: unknown): string;
6
+ export declare function isPluginOptionError(arg: unknown): arg is PluginOptionError;
package/dist/esm/error.js CHANGED
@@ -17,6 +17,7 @@ export class PluginOptionError extends Error {
17
17
  super(detail.length > 0
18
18
  ? `invalid option "${option}": ${detail}`
19
19
  : `invalid option "${option}"`);
20
+ this.name = "PluginOptionError";
20
21
  }
21
22
  }
22
23
  export function reasonToString(reason) {
@@ -28,3 +29,9 @@ export function reasonToString(reason) {
28
29
  }
29
30
  return String(reason);
30
31
  }
32
+ export function isPluginOptionError(arg) {
33
+ if (!(arg instanceof Error)) {
34
+ return false;
35
+ }
36
+ return arg.name === "PluginOptionError";
37
+ }
@@ -12,7 +12,7 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { CodeGeneratorRequest } from "@bufbuild/protobuf";
15
- import { PluginOptionError, reasonToString } from "./error.js";
15
+ import { isPluginOptionError, reasonToString } from "./error.js";
16
16
  /**
17
17
  * Run a plugin with Node.js.
18
18
  *
@@ -43,7 +43,7 @@ export function runNodeJs(plugin) {
43
43
  })
44
44
  .then(() => process.exit(0))
45
45
  .catch((reason) => {
46
- const message = reason instanceof PluginOptionError
46
+ const message = isPluginOptionError(reason)
47
47
  ? reason.message
48
48
  : reasonToString(reason);
49
49
  process.stderr.write(`${plugin.name}: ${message}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "1.7.2",
3
+ "version": "1.8.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": {
@@ -10,10 +10,9 @@
10
10
  },
11
11
  "scripts": {
12
12
  "clean": "rm -rf ./dist/*",
13
- "build": "npm run build:cjs && npm run build:esm && npm run build:proxy",
13
+ "build": "npm run build:cjs && npm run build:esm",
14
14
  "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\"}'",
15
15
  "build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
16
- "build:proxy": "node ../../scripts/gen-esm-proxy.mjs . ecmascript",
17
16
  "attw": "attw --pack"
18
17
  },
19
18
  "type": "module",
@@ -21,20 +20,10 @@
21
20
  "main": "./dist/cjs/index.js",
22
21
  "exports": {
23
22
  ".": {
24
- "node": {
25
- "import": "./dist/proxy/index.js",
26
- "require": "./dist/cjs/index.js"
27
- },
28
- "module": "./dist/esm/index.js",
29
23
  "import": "./dist/esm/index.js",
30
24
  "require": "./dist/cjs/index.js"
31
25
  },
32
26
  "./ecmascript": {
33
- "node": {
34
- "import": "./dist/proxy/ecmascript/index.js",
35
- "require": "./dist/cjs/ecmascript/index.js"
36
- },
37
- "module": "./dist/esm/ecmascript/index.js",
38
27
  "import": "./dist/esm/ecmascript/index.js",
39
28
  "require": "./dist/cjs/ecmascript/index.js"
40
29
  }
@@ -47,7 +36,7 @@
47
36
  }
48
37
  },
49
38
  "dependencies": {
50
- "@bufbuild/protobuf": "1.7.2",
39
+ "@bufbuild/protobuf": "1.8.0",
51
40
  "@typescript/vfs": "^1.4.0",
52
41
  "typescript": "4.5.2"
53
42
  },
@@ -1,7 +0,0 @@
1
- import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
2
- export type ExportDeclaration = {
3
- readonly kind: "es_export_decl";
4
- declaration: string;
5
- name: string | DescMessage | DescEnum | DescExtension;
6
- };
7
- export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
@@ -1,7 +0,0 @@
1
- import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
2
- export type ExportDeclaration = {
3
- readonly kind: "es_export_decl";
4
- declaration: string;
5
- name: string | DescMessage | DescEnum | DescExtension;
6
- };
7
- export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
@@ -1 +0,0 @@
1
- export * from "../../cjs/ecmascript/index.js";
@@ -1 +0,0 @@
1
- export * from "../../cjs/ecmascript/index.js";
@@ -1 +0,0 @@
1
- export * from "../cjs/index.js";
@@ -1 +0,0 @@
1
- export * from "../cjs/index.js";