Skip to content

Commit 51dffd7

Browse files
authored
Merge pull request kubernetes-client#1898 from cjihrig/byline
deps: replace `byline` with `node:readline`
2 parents 92e3b2d + 1b98e7b commit 51dffd7

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"@types/tar": "^6.1.1",
6262
"@types/underscore": "^1.8.9",
6363
"@types/ws": "^8.5.4",
64-
"byline": "^5.0.0",
6564
"form-data": "^4.0.0",
6665
"isomorphic-ws": "^5.0.0",
6766
"js-yaml": "^4.1.0",
@@ -78,7 +77,6 @@
7877
"ws": "^8.18.0"
7978
},
8079
"devDependencies": {
81-
"@types/byline": "^4.2.31",
8280
"@types/chai": "^4.3.0",
8381
"@types/chai-as-promised": "^7.1.5",
8482
"@types/mocha": "^10.0.1",

src/watch.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import byline = require('byline');
2-
import { RequestOptions } from 'https';
1+
import { createInterface } from 'node:readline';
32
import fetch from 'node-fetch';
43
import { AbortSignal } from 'node-fetch/externals';
54
import { URL } from 'url';
@@ -52,26 +51,26 @@ export class Watch {
5251
done(err);
5352
}
5453
};
55-
const stream = byline.createStream();
56-
stream.on('error', doneCallOnce);
57-
stream.on('close', () => doneCallOnce(null));
58-
stream.on('finish', () => doneCallOnce(null));
59-
stream.on('data', (line) => {
60-
try {
61-
const data = JSON.parse(line.toString());
62-
callback(data.type, data.object, data);
63-
} catch (ignore) {
64-
// ignore parse errors
65-
}
66-
});
6754

6855
await fetch(watchURL, requestInit)
6956
.then((response) => {
7057
if (response.status === 200) {
7158
response.body.on('error', doneCallOnce);
7259
response.body.on('close', () => doneCallOnce(null));
7360
response.body.on('finish', () => doneCallOnce(null));
74-
response.body.pipe(stream);
61+
62+
const lines = createInterface(response.body);
63+
lines.on('error', doneCallOnce);
64+
lines.on('close', () => doneCallOnce(null));
65+
lines.on('finish', () => doneCallOnce(null));
66+
lines.on('line', (line) => {
67+
try {
68+
const data = JSON.parse(line.toString());
69+
callback(data.type, data.object, data);
70+
} catch (ignore) {
71+
// ignore parse errors
72+
}
73+
});
7574
} else {
7675
const error = new Error(response.statusText) as Error & {
7776
statusCode: number | undefined;

0 commit comments

Comments
 (0)