From 11da2154832fdaba7fc1a62590d6285f779960ca Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 23 May 2024 10:13:30 -0700 Subject: [PATCH] [test-util] Move core-tracing to peerDependencies (#29775) ### Packages impacted by this PR @azure-tools/test-utils ### Issues associated with this PR Resolves #29736 ### Describe the problem that is addressed by this PR When @azure-tools/test-utils moves to `npm` it will no longer default to the on-disk version of core-tracing. This impacts our `supportsTracing` test helper as it no longer sets the instrumenter on the same version as the client package. Imagine this flow: In this case, test-util and app-configuration are not talking to the same "module global" instrumenter. This PR fixes this by removing core-tracing from test-utils, setting it as a peerDependency instead. All packages that test tracing also implement tracing, and as such are already depending on core-tracing. This was verified locally, but I'll need to get it out to NPM before verification can complete ### Alternatives See #29709 for a few alternatives: 1. Pass the instrumenter through 2. Use mocks Both require updates to multiple packages and/or adding public API surface which is unnecessary. We can fallback to those options if we have to, but this is a promising alternative. --- common/tools/dev-tool/src/commands/run/bundle.ts | 1 + common/tools/dev-tool/src/util/resolveProject.ts | 1 + sdk/test-utils/test-utils/package.json | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/tools/dev-tool/src/commands/run/bundle.ts b/common/tools/dev-tool/src/commands/run/bundle.ts index 0ea2ac7f364c..1c98d12c4c01 100644 --- a/common/tools/dev-tool/src/commands/run/bundle.ts +++ b/common/tools/dev-tool/src/commands/run/bundle.ts @@ -100,6 +100,7 @@ export default leafCommand(commandInfo, async (options) => { ...nodeBuiltins, ...Object.keys(info.packageJson.dependencies), ...Object.keys(info.packageJson.devDependencies), + ...Object.keys(info.packageJson.peerDependencies ?? {}), ], preserveSymlinks: false, plugins: [nodeResolve(), sourcemaps()], diff --git a/common/tools/dev-tool/src/util/resolveProject.ts b/common/tools/dev-tool/src/util/resolveProject.ts index be9323461dcd..7d0f667e411f 100644 --- a/common/tools/dev-tool/src/util/resolveProject.ts +++ b/common/tools/dev-tool/src/util/resolveProject.ts @@ -60,6 +60,7 @@ declare global { private: boolean; dependencies: Record; + peerDependencies?: Record; devDependencies: Record; [METADATA_KEY]?: AzureSdkMetadata; diff --git a/sdk/test-utils/test-utils/package.json b/sdk/test-utils/test-utils/package.json index 6af07e902cde..b4d3d378f06b 100644 --- a/sdk/test-utils/test-utils/package.json +++ b/sdk/test-utils/test-utils/package.json @@ -58,7 +58,6 @@ "@azure-tools/test-recorder": "^3.0.0", "@azure/abort-controller": "^2.0.0", "@azure/core-rest-pipeline": "^1.1.0", - "@azure/core-tracing": "^1.0.0", "@opentelemetry/api": "^1.8.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.4", @@ -68,6 +67,9 @@ "mocha": "^10.0.0", "tslib": "^2.2.0" }, + "peerDependencies": { + "@azure/core-tracing": "^1.0.0" + }, "devDependencies": { "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0",