Skip to content

Commit 879bf7b

Browse files
fix(deps): drop dependency on through2 (#400)
1 parent ef1aafe commit 879bf7b

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

packages/google-cloud-node/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
"google-gax": "^1.0.0",
4646
"protobufjs": "^6.8.6",
4747
"pumpify": "^1.5.1",
48-
"stream-events": "^1.0.4",
49-
"through2": "^3.0.0"
48+
"stream-events": "^1.0.4"
5049
},
5150
"devDependencies": {
5251
"codecov": "^3.0.2",

packages/google-cloud-node/src/helpers.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
const common = require('@google-cloud/common');
2020
const pumpify = require('pumpify');
2121
const streamEvents = require('stream-events');
22-
const through = require('through2');
22+
const {PassThrough} = require('stream');
2323

2424
/*!
2525
* Return a dictionary-like object with helpers to augment the Speech
@@ -94,22 +94,26 @@ module.exports = () => {
9494
// Format the user's input.
9595
// This entails that the user sends raw audio; it is wrapped in
9696
// the appropriate request structure.
97-
through.obj((audioContent, _, next) => {
98-
if (audioContent !== undefined) {
99-
next(null, {audioContent});
100-
return;
101-
}
102-
103-
next();
97+
new PassThrough({
98+
objectMode: true,
99+
transform: (audioContent, _, next) => {
100+
if (audioContent !== undefined) {
101+
next(null, {audioContent});
102+
return;
103+
}
104+
next();
105+
},
104106
}),
105107
requestStream,
106-
through.obj((response, enc, next) => {
107-
if (response.error) {
108-
next(new common.util.ApiError(response.error));
109-
return;
110-
}
111-
112-
next(null, response);
108+
new PassThrough({
109+
objectMode: true,
110+
transform: (response, enc, next) => {
111+
if (response.error) {
112+
next(new common.util.ApiError(response.error));
113+
return;
114+
}
115+
next(null, response);
116+
},
113117
}),
114118
]);
115119
});

packages/google-cloud-node/test/gapic-v1.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const assert = require('assert');
18-
const through2 = require('through2');
18+
const {PassThrough} = require('stream');
1919

2020
const speechModule = require('../src');
2121

@@ -311,13 +311,16 @@ function mockSimpleGrpcMethod(expectedRequest, response, error) {
311311

312312
function mockBidiStreamingGrpcMethod(expectedRequest, response, error) {
313313
return () => {
314-
const mockStream = through2.obj((chunk, enc, callback) => {
315-
assert.deepStrictEqual(chunk, expectedRequest);
316-
if (error) {
317-
callback(error);
318-
} else {
319-
callback(null, response);
320-
}
314+
const mockStream = new PassThrough({
315+
objectMode: true,
316+
transform: (chunk, enc, callback) => {
317+
assert.deepStrictEqual(chunk, expectedRequest);
318+
if (error) {
319+
callback(error);
320+
} else {
321+
callback(null, response);
322+
}
323+
},
321324
});
322325
return mockStream;
323326
};

packages/google-cloud-node/test/gapic-v1p1beta1.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const assert = require('assert');
18-
const through2 = require('through2');
18+
const {PassThrough} = require('stream');
1919

2020
const speechModule = require('../src');
2121

@@ -311,13 +311,16 @@ function mockSimpleGrpcMethod(expectedRequest, response, error) {
311311

312312
function mockBidiStreamingGrpcMethod(expectedRequest, response, error) {
313313
return () => {
314-
const mockStream = through2.obj((chunk, enc, callback) => {
315-
assert.deepStrictEqual(chunk, expectedRequest);
316-
if (error) {
317-
callback(error);
318-
} else {
319-
callback(null, response);
320-
}
314+
const mockStream = new PassThrough({
315+
objectMode: true,
316+
transform: (chunk, enc, callback) => {
317+
assert.deepStrictEqual(chunk, expectedRequest);
318+
if (error) {
319+
callback(error);
320+
} else {
321+
callback(null, response);
322+
}
323+
},
321324
});
322325
return mockStream;
323326
};

0 commit comments

Comments
 (0)