@bufbuild/protoplugin 0.0.9 → 0.0.10

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.
@@ -27,7 +27,6 @@ const error_js_1 = require("./error.js");
27
27
  * ```
28
28
  */
29
29
  function runNodeJs(plugin) {
30
- setBlockingStdout();
31
30
  const args = process.argv.slice(2);
32
31
  if ((args.length === 1 && args[0] === "-v") || args[0] === "--version") {
33
32
  process.stdout.write(`${plugin.name} ${plugin.version}\n`);
@@ -43,9 +42,9 @@ function runNodeJs(plugin) {
43
42
  .then((data) => {
44
43
  const req = protobuf_1.CodeGeneratorRequest.fromBinary(data);
45
44
  const res = plugin.run(req);
46
- process.stdout.write(res.toBinary());
47
- process.exit(0);
45
+ return writeBytes(process.stdout, res.toBinary());
48
46
  })
47
+ .then(() => process.exit(0))
49
48
  .catch((reason) => {
50
49
  const message = reason instanceof error_js_1.PluginOptionError
51
50
  ? reason.message
@@ -72,13 +71,17 @@ function readBytes(stream) {
72
71
  });
73
72
  }
74
73
  /**
75
- * Node.js buffers stdout, and process.exit() will truncate output.
76
- * As a workaround, we set the stream to blocking via a private API.
77
- * See https://github.com/timostamm/protobuf-ts/issues/134
78
- * See https://github.com/nodejs/node/issues/6456
74
+ * Write a chunk of bytes to a stream.
79
75
  */
80
- function setBlockingStdout() {
81
- var _a, _b;
82
- const stdout = process.stdout;
83
- (_b = (_a = stdout._handle) === null || _a === void 0 ? void 0 : _a.setBlocking) === null || _b === void 0 ? void 0 : _b.call(_a, true);
76
+ function writeBytes(stream, data) {
77
+ return new Promise((resolve, reject) => {
78
+ stream.write(data, (err) => {
79
+ if (err) {
80
+ reject(err);
81
+ }
82
+ else {
83
+ resolve();
84
+ }
85
+ });
86
+ });
84
87
  }
@@ -24,7 +24,6 @@ import { PluginOptionError, reasonToString } from "./error.js";
24
24
  * ```
25
25
  */
26
26
  export function runNodeJs(plugin) {
27
- setBlockingStdout();
28
27
  const args = process.argv.slice(2);
29
28
  if ((args.length === 1 && args[0] === "-v") || args[0] === "--version") {
30
29
  process.stdout.write(`${plugin.name} ${plugin.version}\n`);
@@ -40,9 +39,9 @@ export function runNodeJs(plugin) {
40
39
  .then((data) => {
41
40
  const req = CodeGeneratorRequest.fromBinary(data);
42
41
  const res = plugin.run(req);
43
- process.stdout.write(res.toBinary());
44
- process.exit(0);
42
+ return writeBytes(process.stdout, res.toBinary());
45
43
  })
44
+ .then(() => process.exit(0))
46
45
  .catch((reason) => {
47
46
  const message = reason instanceof PluginOptionError
48
47
  ? reason.message
@@ -68,13 +67,17 @@ function readBytes(stream) {
68
67
  });
69
68
  }
70
69
  /**
71
- * Node.js buffers stdout, and process.exit() will truncate output.
72
- * As a workaround, we set the stream to blocking via a private API.
73
- * See https://github.com/timostamm/protobuf-ts/issues/134
74
- * See https://github.com/nodejs/node/issues/6456
70
+ * Write a chunk of bytes to a stream.
75
71
  */
76
- function setBlockingStdout() {
77
- var _a, _b;
78
- const stdout = process.stdout;
79
- (_b = (_a = stdout._handle) === null || _a === void 0 ? void 0 : _a.setBlocking) === null || _b === void 0 ? void 0 : _b.call(_a, true);
72
+ function writeBytes(stream, data) {
73
+ return new Promise((resolve, reject) => {
74
+ stream.write(data, (err) => {
75
+ if (err) {
76
+ reject(err);
77
+ }
78
+ else {
79
+ resolve();
80
+ }
81
+ });
82
+ });
80
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
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": {
@@ -37,7 +37,7 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@bufbuild/protobuf": "^0.0.9"
40
+ "@bufbuild/protobuf": "0.0.10"
41
41
  },
42
42
  "devDependencies": {
43
43
  "typescript": "^4.7.4"