diff --git a/package.json b/package.json index c80f41edb..50982df07 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@types/fs-extra": "^8.0.1", "@types/mocha": "^8.0.0", "@types/ncp": "^2.0.1", - "@types/node": "^14.0.0", + "@types/node": ">=15.6.0", "@types/node-fetch": "^2.5.4", "@types/object-hash": "^2.1.0", "@types/proxyquire": "^1.3.28", diff --git a/src/index.ts b/src/index.ts index 3aec2ac47..e1eaf38fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -105,3 +105,4 @@ export { } from './clientInterface'; export {ServiceError, ChannelCredentials} from '@grpc/grpc-js'; +export {warn} from './warnings'; diff --git a/src/warnings.ts b/src/warnings.ts index 8f96733a2..bc1ffef2e 100644 --- a/src/warnings.ts +++ b/src/warnings.ts @@ -18,7 +18,8 @@ import {isBrowser} from './isbrowser'; const emittedWarnings = new Set(); -export function warn(code: string, message: string) { +// warnType is the type of warning (e.g. 'DeprecationWarning', 'ExperimentalWarning', etc.) +export function warn(code: string, message: string, warnType?: string) { // Only show a given warning once if (emittedWarnings.has(code)) { return; @@ -27,6 +28,10 @@ export function warn(code: string, message: string) { if (isBrowser()) { console.warn(message); + } else if (typeof warnType !== 'undefined') { + process.emitWarning(message, { + type: warnType, + }); } else { process.emitWarning(message); } diff --git a/test/unit/warning.ts b/test/unit/warning.ts index f47dafe36..8453e8105 100644 --- a/test/unit/warning.ts +++ b/test/unit/warning.ts @@ -42,4 +42,15 @@ describe('warnings', () => { stub.restore(); done(); }); + it('should include warning type if type is provided', done => { + const stub = sinon.stub(process, 'emitWarning'); + warn('codeD', 'messageD-1', 'WarningType1'); + assert( + stub.calledWith('messageD-1', { + type: 'WarningType1', + }) + ); + stub.restore(); + done(); + }); });