From 66a39fac603dbd0ab40afa5266236850124cd21b Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Wed, 7 Feb 2024 12:27:46 -0800 Subject: [PATCH] fix: assert oldMethod existence, and pin typescript version (#1549) * fix: assert oldMethod existence, and pin typescript version --- package.json | 2 +- src/cls/async-hooks.ts | 6 +++++- src/index.ts | 6 +++--- test/test-span-data.ts | 9 +++++---- test/utils.ts | 6 +++--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4abe7be77..03f34240d 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "timekeeper": "^2.0.0", "tmp": "0.2.1", "ts-node": "^10.7.0", - "typescript": "^5.1.6" + "typescript": "5.1.6" }, "dependencies": { "@google-cloud/common": "^5.0.0", diff --git a/src/cls/async-hooks.ts b/src/cls/async-hooks.ts index 369ce917e..696c19e4f 100644 --- a/src/cls/async-hooks.ts +++ b/src/cls/async-hooks.ts @@ -192,7 +192,11 @@ export class AsyncHooksCLS implements CLS { if (ee[method]) { shimmer.wrap(ee, method, oldMethod => { return function (this: {}, event: string, cb: Func) { - return oldMethod.call(this, event, that.bindWithCurrentContext(cb)); + return oldMethod!.call( + this, + event, + that.bindWithCurrentContext(cb) + ); }; }); } diff --git a/src/index.ts b/src/index.ts index aa417e85c..0db070bf0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,9 +51,9 @@ let traceAgent: StackdriverTracer; function initConfig(userConfig: Forceable): TopLevelConfig { let envSetConfig = {}; if (process.env.GCLOUD_TRACE_CONFIG) { - envSetConfig = require(path.resolve( - process.env.GCLOUD_TRACE_CONFIG! - )) as Config; + envSetConfig = require( + path.resolve(process.env.GCLOUD_TRACE_CONFIG!) + ) as Config; } // Configuration order of precedence: // 1. Environment Variables diff --git a/test/test-span-data.ts b/test/test-span-data.ts index c384f10c4..6bfaa093a 100644 --- a/test/test-span-data.ts +++ b/test/test-span-data.ts @@ -216,10 +216,11 @@ describe('SpanData', () => { for (const sourceMapType of sourceMapTypes) { it(`uses source maps when available in stack traces: ${sourceMapType}`, () => { - const {applyGeneric} = - require(`./fixtures/source-maps-test/${sourceMapType}`) as { - applyGeneric: (fn: () => T) => T; - }; + const {applyGeneric} = require( + `./fixtures/source-maps-test/${sourceMapType}` + ) as { + applyGeneric: (fn: () => T) => T; + }; const spanData = applyGeneric( () => new CommonSpanData(trace, 'name', '0', 0) ); diff --git a/test/utils.ts b/test/utils.ts index 67b5cd400..519e13dcb 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -191,9 +191,9 @@ function getFixturesForModule(moduleName: string): Array> { return moduleNameMatches && versionCompatible; }) .map(key => { - const version = - require(`./plugins/fixtures/${key}/node_modules/${moduleName}/package.json`) - .version as string; + const version = require( + `./plugins/fixtures/${key}/node_modules/${moduleName}/package.json` + ).version as string; const parsedVersion = semver.parse(version)!; const getModule: () => T = () => require(`./plugins/fixtures/${key}`); // Convenience function -- returns if.skip if the selected module's