From e907d199c5d70383b1437d139dceeafaf08076b4 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 9 Oct 2024 11:12:20 -0700 Subject: [PATCH] grpc-js: Use util.promisify instead of fs/promises for Node 12 compatibility --- packages/grpc-js/package.json | 2 +- packages/grpc-js/src/certificate-provider.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index ffa8539c7..46dc7efd7 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/grpc-js", - "version": "1.12.1", + "version": "1.12.2", "description": "gRPC Library for Node - pure JS implementation", "homepage": "https://grpc.io/", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", diff --git a/packages/grpc-js/src/certificate-provider.ts b/packages/grpc-js/src/certificate-provider.ts index e8bcaed8f..60d4cfa3f 100644 --- a/packages/grpc-js/src/certificate-provider.ts +++ b/packages/grpc-js/src/certificate-provider.ts @@ -15,9 +15,10 @@ * */ -import * as fs from 'fs/promises'; +import * as fs from 'fs'; import * as logging from './logging'; import { LogVerbosity } from './constants'; +import { promisify } from 'util'; const TRACER_NAME = 'certificate_provider'; @@ -56,6 +57,8 @@ export interface FileWatcherCertificateProviderConfig { refreshIntervalMs: number; } +const readFilePromise = promisify(fs.readFile); + export class FileWatcherCertificateProvider implements CertificateProvider { private refreshTimer: NodeJS.Timeout | null = null; private fileResultPromise: Promise<[PromiseSettledResult, PromiseSettledResult, PromiseSettledResult]> | null = null; @@ -82,9 +85,9 @@ export class FileWatcherCertificateProvider implements CertificateProvider { return; } this.fileResultPromise = Promise.allSettled([ - this.config.certificateFile ? fs.readFile(this.config.certificateFile) : Promise.reject(), - this.config.privateKeyFile ? fs.readFile(this.config.privateKeyFile) : Promise.reject(), - this.config.caCertificateFile ? fs.readFile(this.config.caCertificateFile) : Promise.reject() + this.config.certificateFile ? readFilePromise(this.config.certificateFile) : Promise.reject(), + this.config.privateKeyFile ? readFilePromise(this.config.privateKeyFile) : Promise.reject(), + this.config.caCertificateFile ? readFilePromise(this.config.caCertificateFile) : Promise.reject() ]); this.fileResultPromise.then(([certificateResult, privateKeyResult, caCertificateResult]) => { if (!this.refreshTimer) {