Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: replace byline with node:readline #1898

Open
wants to merge 1 commit into
base: release-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@types/tar": "^6.1.1",
"@types/underscore": "^1.8.9",
"@types/ws": "^8.5.4",
"byline": "^5.0.0",
"form-data": "^4.0.0",
"isomorphic-ws": "^5.0.0",
"js-yaml": "^4.1.0",
Expand All @@ -78,7 +77,6 @@
"ws": "^8.13.0"
},
"devDependencies": {
"@types/byline": "^4.2.31",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
Expand Down
29 changes: 14 additions & 15 deletions src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import byline = require('byline');
import { RequestOptions } from 'https';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unrelated to this PR, but the code was unused.

import { createInterface } from 'node:readline';
import fetch from 'node-fetch';
import { AbortSignal } from 'node-fetch/externals';
import { URL } from 'url';
Expand Down Expand Up @@ -52,26 +51,26 @@ export class Watch {
done(err);
}
};
const stream = byline.createStream();
stream.on('error', doneCallOnce);
stream.on('close', () => doneCallOnce(null));
stream.on('finish', () => doneCallOnce(null));
stream.on('data', (line) => {
try {
const data = JSON.parse(line.toString());
callback(data.type, data.object, data);
} catch (ignore) {
// ignore parse errors
}
});

await fetch(watchURL, requestInit)
.then((response) => {
if (response.status === 200) {
response.body.on('error', doneCallOnce);
response.body.on('close', () => doneCallOnce(null));
response.body.on('finish', () => doneCallOnce(null));
response.body.pipe(stream);

const lines = createInterface(response.body);
lines.on('error', doneCallOnce);
lines.on('close', () => doneCallOnce(null));
lines.on('finish', () => doneCallOnce(null));
lines.on('line', (line) => {
try {
const data = JSON.parse(line.toString());
callback(data.type, data.object, data);
} catch (ignore) {
// ignore parse errors
}
});
} else {
const error = new Error(response.statusText) as Error & {
statusCode: number | undefined;
Expand Down