Skip to content

Commit

Permalink
fix: more robust stream rescoping (to fix bug in npm module)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoulb committed Jan 15, 2019
1 parent ea95ccd commit 34c7c62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
28 changes: 19 additions & 9 deletions lib/rescopeStream.js → lib/RescopedStream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { Writable } = require("stream");
const { check } = require("./blork");

/**
Expand All @@ -7,16 +8,25 @@ const { check } = require("./blork");
* @param {stream.Writable} stream The actual stream to write messages to.
* @param {string} scope The string scope for the stream (instances of the text `[semantic-release]` are replaced in the stream).
* @returns {stream.Writable} Object that's compatible with stream.Writable (implements a `write()` property).
*
* @internal
*/
function rescopeStream(stream, scope) {
// Check args.
check(scope, "scope: string");
return {
write(msg) {
stream.write(msg.replace("[semantic-release]", `[${scope}]`));
}
};
class RescopedStream extends Writable {
// Constructor.
constructor(stream, scope) {
super();
check(scope, "scope: string");
check(stream, "stream: stream");
this._stream = stream;
this._scope = scope;
}

// Custom write method.
write(msg) {
check(msg, "msg: string");
this._stream.write(msg.replace("[semantic-release]", `[${this._scope}]`));
}
}

// Exports.
module.exports = rescopeStream;
module.exports = RescopedStream;
6 changes: 3 additions & 3 deletions lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getConfig = require("./getConfig");
const getConfigSemantic = require("./getConfigSemantic");
const getManifest = require("./getManifest");
const cleanPath = require("./cleanPath");
const rescopeStream = require("./rescopeStream");
const RescopedStream = require("./RescopedStream");
const createInlinePluginCreator = require("./createInlinePluginCreator");

/**
Expand Down Expand Up @@ -163,7 +163,7 @@ async function releasePackage(pkg, createInlinePlugin, multiContext) {
pkg.result = await semanticRelease(options, {
cwd: dir,
env,
stdout: rescopeStream(stdout, name),
stderr: rescopeStream(stdout, name)
stdout: new RescopedStream(stdout, name),
stderr: new RescopedStream(stdout, name)
});
}

0 comments on commit 34c7c62

Please sign in to comment.