Skip to content

Commit

Permalink
feat: support Node.js >= 14.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jul 28, 2023
1 parent 81a5724 commit 1c8c530
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
node-version: [14, 16, 18, 20]
os: [ubuntu-latest]

steps:
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@eggjs/tsconfig": "^1.0.0",
"@types/google-protobuf": "^3.15.5",
"@types/jest": "^27.0.2",
"@types/pump": "^1.1.1",
"eslint": "^8.31.0",
"eslint-config-egg": "^12.1.0",
"git-contributor": "^1.1.0",
Expand All @@ -56,9 +57,10 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.4.1",
"google-protobuf": "^3.19.0"
"google-protobuf": "^3.19.0",
"pump": "^3.0.0"
},
"engines": {
"node": ">=16.0.0"
"node": ">=14.21.3"
}
}
2 changes: 1 addition & 1 deletion src/client/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { debuglog } from 'node:util';
import { Transform, Readable } from 'node:stream';
import { pipeline as pipelinePromise } from 'node:stream/promises';
import { pipelinePromise } from '../utils';
import {
GetFileRequest as GetFileRequestPB,
GetFileResponse as GetFileResponsePB,
Expand Down
2 changes: 1 addition & 1 deletion src/client/Oss.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Readable, PassThrough, Writable } from 'node:stream';
import { pipeline as pipelinePromise } from 'node:stream/promises';
import { pipelinePromise } from '../utils';
import {
CopyObjectRequest,
DeleteObjectRequest,
Expand Down
19 changes: 16 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { setTimeout } from 'node:timers/promises';
import stream from 'node:stream';
import pump from 'pump';
import { Map as MapPB } from 'google-protobuf';
import { KV } from './types/common';

export async function sleep(ms: number) {
await setTimeout(ms);
// impl promise pipeline on Node.js 14
export const pipelinePromise = stream.promises?.pipeline ?? function pipeline(...args: any[]) {
return new Promise<void>((resolve, reject) => {
pump(...args, (err?: Error) => {
if (err) return reject(err);
resolve();
});
});
};

export function sleep(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}

// jspb.Message
Expand Down
2 changes: 1 addition & 1 deletion test/unit/client/File.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { strict as assert } from 'node:assert';
import { tmpdir } from 'node:os';
import { existsSync, createWriteStream, createReadStream } from 'node:fs';
import { mkdtemp, rm } from 'node:fs/promises';
import { pipeline } from 'node:stream/promises';
import { join } from 'node:path';
import { Client, utils } from '../../../src';
import { pipelinePromise as pipeline } from '../../../src/utils';

describe.skip('client/File.test.ts', () => {
let client: Client;
Expand Down

0 comments on commit 1c8c530

Please sign in to comment.