Skip to content

Commit

Permalink
Code review responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Nov 10, 2021
1 parent 11d7039 commit 353c816
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ on:
branches:
- '*'
pull_request:
branches: [main]
branches: ['*']

jobs:
build:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x, 16.x]
node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 17.x]
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}
Expand Down
35 changes: 21 additions & 14 deletions bin/peggy-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function readStream(inputStream) {
inputStream.on("data", data => { input.push(data); });
inputStream.on("end", () => resolve(Buffer.concat(input).toString()));
inputStream.on("error", er => {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(er);
reject(er);
});
Expand Down Expand Up @@ -71,26 +72,27 @@ export class PeggyCLI extends Command {
super("peggy");

/** @type {Stdio} */
this.std = Object.assign({
this.std = {
in: process.stdin,
out: process.stdout,
err: process.stderr,
}, stdio);
...stdio,
};

/** @type object */
/** @type {peggy.BuildOptionsBase} */
this.argv = {};
this.colors = this.std.err.isTTY;
/** @type string? */
/** @type {string?} */
this.inputFile = null;
/** @type string? */
/** @type {string?} */
this.outputFile = null;
/** @type object */
/** @type {object} */
this.progOptions = {};
/** @type string? */
/** @type {string?} */
this.testFile = null;
/** @type string? */
/** @type {string?} */
this.testGrammarSource = null;
/** @type string? */
/** @type {string?} */
this.testText = null;

this
Expand Down Expand Up @@ -219,8 +221,11 @@ export class PeggyCLI extends Command {
try {
mod = require(id);
} catch (e) {
if (e.code !== "MODULE_NOT_FOUND") { throw e; }
this.error(`Requiring "${id}": ${e.message}`);
if (e.code !== "MODULE_NOT_FOUND") {
this.error(`requiring:\n${e.stack}`);
} else {
this.error(`requiring "${id}": ${e.message}`);
}
}
return mod;
});
Expand Down Expand Up @@ -342,14 +347,14 @@ export class PeggyCLI extends Command {
this._displayError(opts.exitCode, opts.code, `Error ${message}`);
}

print(strm, ...args) {
strm.write(util.formatWithOptions({
print(stream, ...args) {
stream.write(util.formatWithOptions({
colors: this.colors,
depth: Infinity,
maxArrayLength: Infinity,
maxStringLength: Infinity,
}, ...args));
strm.write("\n");
stream.write("\n");
}

verbose(...args) {
Expand Down Expand Up @@ -409,6 +414,7 @@ export class PeggyCLI extends Command {
return new Promise((resolve, reject) => {
const outputStream = fs.createWriteStream(this.outputFile);
outputStream.on("error", er => {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(er);
reject(er);
});
Expand Down Expand Up @@ -451,6 +457,7 @@ export class PeggyCLI extends Command {
"utf8",
err => {
if (err) {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(err);
reject(err);
} else {
Expand Down
35 changes: 21 additions & 14 deletions bin/peggy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,7 @@ function readStream(inputStream) {
inputStream.on("data", data => { input.push(data); });
inputStream.on("end", () => resolve(Buffer.concat(input).toString()));
inputStream.on("error", er => {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(er);
reject(er);
});
Expand Down Expand Up @@ -2973,26 +2974,27 @@ class PeggyCLI extends commander.exports.Command {
super("peggy");

/** @type {Stdio} */
this.std = Object.assign({
this.std = {
in: process.stdin,
out: process.stdout,
err: process.stderr,
}, stdio);
...stdio,
};

/** @type object */
/** @type {peggy.BuildOptionsBase} */
this.argv = {};
this.colors = this.std.err.isTTY;
/** @type string? */
/** @type {string?} */
this.inputFile = null;
/** @type string? */
/** @type {string?} */
this.outputFile = null;
/** @type object */
/** @type {object} */
this.progOptions = {};
/** @type string? */
/** @type {string?} */
this.testFile = null;
/** @type string? */
/** @type {string?} */
this.testGrammarSource = null;
/** @type string? */
/** @type {string?} */
this.testText = null;

this
Expand Down Expand Up @@ -3121,8 +3123,11 @@ class PeggyCLI extends commander.exports.Command {
try {
mod = require(id);
} catch (e) {
if (e.code !== "MODULE_NOT_FOUND") { throw e; }
this.error(`Requiring "${id}": ${e.message}`);
if (e.code !== "MODULE_NOT_FOUND") {
this.error(`requiring:\n${e.stack}`);
} else {
this.error(`requiring "${id}": ${e.message}`);
}
}
return mod;
});
Expand Down Expand Up @@ -3244,14 +3249,14 @@ class PeggyCLI extends commander.exports.Command {
this._displayError(opts.exitCode, opts.code, `Error ${message}`);
}

print(strm, ...args) {
strm.write(util__default["default"].formatWithOptions({
print(stream, ...args) {
stream.write(util__default["default"].formatWithOptions({
colors: this.colors,
depth: Infinity,
maxArrayLength: Infinity,
maxStringLength: Infinity,
}, ...args));
strm.write("\n");
stream.write("\n");
}

verbose(...args) {
Expand Down Expand Up @@ -3311,6 +3316,7 @@ class PeggyCLI extends commander.exports.Command {
return new Promise((resolve, reject) => {
const outputStream = fs__default["default"].createWriteStream(this.outputFile);
outputStream.on("error", er => {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(er);
reject(er);
});
Expand Down Expand Up @@ -3353,6 +3359,7 @@ class PeggyCLI extends commander.exports.Command {
"utf8",
err => {
if (err) {
// Stack isn't filled in on this error for some reason.
Error.captureStackTrace(err);
reject(err);
} else {
Expand Down
Loading

0 comments on commit 353c816

Please sign in to comment.