-
-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: circular dependencies #3081
base: master
Are you sure you want to change the base?
Conversation
pool.js and pool_connection.js required index.js, and index.js required pool.js and pool_connection.js. Circular dependency can cause all sorts of problems. This fix aims to provide a step towards fixing a problem with @opentelemetry/instrumentation-mysql2, which looses several exports when using its patched require. For instance, `format` is lost and can cause an instrumented application to crash.
index.js and promise.js require each other. Circular dependency can cause all sorts of problems. This commit aims to fix a problem with @opentelemetry/instrumentation-mysql2, which looses several exports when using its patched require. For instance, `format` is lost and can cause an instrumented application to crash.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3081 +/- ##
==========================================
+ Coverage 88.13% 88.16% +0.02%
==========================================
Files 71 74 +3
Lines 12890 12919 +29
Branches 1355 1358 +3
==========================================
+ Hits 11361 11390 +29
Misses 1529 1529
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks, @tpraxl 🚀 I remember experiencing an error with Just a small recommendation, moving from |
@wellwelwel You have a point there. In that case however, it feels weird to arbitrarily stuff some exported functions together in lib/common.js . It made sense when we were talking about commons for index.js and promise.js, but in lib, I would split common.js up into the following files and get rid of common.js
I'm working on it and will push the result |
The proposal to put common.js into lib was good, but it felt weird to arbitrarily stuff just some exported functions in lib/common.js. This made sense when common.js was meant to provide commons for index.js and promise.js. But in the lib, this felt like a weird scope. I therefore split common.js into - lib/create_connection.js - lib/create_pool.js - lib/create_pool_cluster.js Also made `require` more consistent in all affected files: all `require` files now have a js suffix when they refer to a single local file.
Hey @tpraxl, I tested your changes with
import mysql from 'mysql2/promise';
mysql.createPool({});
import { defineConfig } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
export default defineConfig({
input: 'index.js',
output: {
file: 'dist.js',
},
plugins: [nodeResolve(), commonjs(), json()],
});
{
"type": "module",
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"rollup": "^4.24.0"
},
"dependencies": {
"mysql2": "file:../node-mysql2"
}
} I'll try to investigate this further. |
Thanks for your finding. No need to investigate further IMHO, I would propose to extract See https://github.com/tpraxl/node-mysql2/pull/1/files If these changes are OK for you, I'll merge them into fix/circular-dependencies and update this PR. |
@wellwelwel are you fine with my changes? |
This commit addresses circular dependencies between index.js and promise.js, as well as within files in the lib directory such as pool.js and pool_connection.js.
It introduces a new common.js module to centralize shared functionalities, thus breaking the direct dependencies among these files.
This approach resolves issues with the @opentelemetry/instrumentation-mysql2 package, which was losing several exports due to the circular dependencies.
You can reproduce the problem with this simple test repo:
https://github.com/tpraxl/test-esm-mysql-otel
Follow the instructions in the README.md to see the respective warnings.
To verify that this PR fixes the issue, check it out, run
npm i && npm pack
and install the fixed version into the test repo usingnpm i $PATH_TO_MYSQL2/mysql2-3.11.3.tgz
. Runnpm start
again in the checked out test repo to see the warnings vanish.This PR would fix open-telemetry/opentelemetry-js-contrib#1511