@bufbuild/protoplugin
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -30,3 +30,2 @@ "use strict"; | ||
function runNodeJs(plugin) { | ||
setBlockingStdout(); | ||
const args = process.argv.slice(2); | ||
@@ -47,5 +46,5 @@ if ((args.length === 1 && args[0] === "-v") || args[0] === "--version") { | ||
const res = plugin.run(req); | ||
process.stdout.write(res.toBinary()); | ||
process.exit(0); | ||
return writeBytes(process.stdout, res.toBinary()); | ||
}) | ||
.then(() => process.exit(0)) | ||
.catch((reason) => { | ||
@@ -77,11 +76,15 @@ const message = reason instanceof error_js_1.PluginOptionError | ||
/** | ||
* Node.js buffers stdout, and process.exit() will truncate output. | ||
* As a workaround, we set the stream to blocking via a private API. | ||
* See https://github.com/timostamm/protobuf-ts/issues/134 | ||
* See https://github.com/nodejs/node/issues/6456 | ||
* Write a chunk of bytes to a stream. | ||
*/ | ||
function setBlockingStdout() { | ||
var _a, _b; | ||
const stdout = process.stdout; | ||
(_b = (_a = stdout._handle) === null || _a === void 0 ? void 0 : _a.setBlocking) === null || _b === void 0 ? void 0 : _b.call(_a, true); | ||
function writeBytes(stream, data) { | ||
return new Promise((resolve, reject) => { | ||
stream.write(data, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} |
@@ -27,3 +27,2 @@ // Copyright 2021-2022 Buf Technologies, Inc. | ||
export function runNodeJs(plugin) { | ||
setBlockingStdout(); | ||
const args = process.argv.slice(2); | ||
@@ -44,5 +43,5 @@ if ((args.length === 1 && args[0] === "-v") || args[0] === "--version") { | ||
const res = plugin.run(req); | ||
process.stdout.write(res.toBinary()); | ||
process.exit(0); | ||
return writeBytes(process.stdout, res.toBinary()); | ||
}) | ||
.then(() => process.exit(0)) | ||
.catch((reason) => { | ||
@@ -73,11 +72,15 @@ const message = reason instanceof PluginOptionError | ||
/** | ||
* Node.js buffers stdout, and process.exit() will truncate output. | ||
* As a workaround, we set the stream to blocking via a private API. | ||
* See https://github.com/timostamm/protobuf-ts/issues/134 | ||
* See https://github.com/nodejs/node/issues/6456 | ||
* Write a chunk of bytes to a stream. | ||
*/ | ||
function setBlockingStdout() { | ||
var _a, _b; | ||
const stdout = process.stdout; | ||
(_b = (_a = stdout._handle) === null || _a === void 0 ? void 0 : _a.setBlocking) === null || _b === void 0 ? void 0 : _b.call(_a, true); | ||
function writeBytes(stream, data) { | ||
return new Promise((resolve, reject) => { | ||
stream.write(data, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} |
{ | ||
"name": "@bufbuild/protoplugin", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"license": "(Apache-2.0 AND BSD-3-Clause)", | ||
@@ -40,3 +40,3 @@ "description": "Helps to create your own Protocol Buffers code generators.", | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^0.0.9" | ||
"@bufbuild/protobuf": "0.0.10" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
2445
92996
+ Added@bufbuild/protobuf@0.0.10(transitive)
- Removed@bufbuild/protobuf@0.0.9(transitive)
Updated@bufbuild/protobuf@0.0.10