Skip to content

Commit

Permalink
Merge pull request kubernetes-client#1898 from cjihrig/byline
Browse files Browse the repository at this point in the history
deps: replace `byline` with `node:readline`
  • Loading branch information
k8s-ci-robot authored Oct 1, 2024
2 parents 92e3b2d + 1b98e7b commit 51dffd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
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.18.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';
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

0 comments on commit 51dffd7

Please sign in to comment.