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
feat(core): refactor internal dependencies to support Yarn PnP #645
Conversation
Now that the dependencies are declared correctly I can't get the build to pass, most likely because the dependencies are circular. Would appreciate some input on this |
I don't follow what your problem is, this definitely nothing mergable - the whole purpose of the |
knex should not be installed like this, it is already transitive dependency of |
you should literally install only @darkbasic thoughts? |
I had to manually install knex because I needed to create a custom type for postgis and I needed a handle on |
Unfortunately I have no experience with yarn pnp because it doesn't play well with tsc, but I agree that you should always declare the dependencies that you use. For example if in the mariadb package you need to access @mikro-orm/core you will have to list it, even if you depend on @mikro-orm/mysql-base which already depends on it: otherwise you will rely on an undefined behaviour because there could be multiple versions racing to be hoisted. Lock files and yarn resolutions help a lot to fix those issues, but they are annoying nonetheless. I personally use an eslint rule to forbid extranous imports, so every time I try to import something which I didn't declare a direct dependency on I get an error. |
As I said, I am fine with reexporting knex, as it makes sense to me. I also don't like the usage of The bottom line is,
But that is the exact purpose of peer dependencies, if we want to ensure there is only one copy and not more. What you are proposing would make it actually worse for the regular users, or not? Every direct dependency would result in a new copy, even if the versions are matching, or not? |
As I said, the idea was to import only the driver package, rest should be transitive dependencies, nothing users should install themselves in the root project. Maybe that was wrong (although I am not very convinced), and we should require also the But knex should not be installed like this, it was never meant to be peer dependency. Would be great to see a repository demonstrating the problem first, before firing a PR like this (that basically reverts all the outcomes of #475, as with those changes the |
I think it's up to the package manager to hoist it or not, but I wouldn't rely on it. If a dep is meant to be a peer dep I agree that it would be better to omit it, but I would still declare it as a dev dependency to avoid undefined behaviour in the development environment (won't matter once packaged though). If it's a peer dep there is no chance for ub because the user will be forced to manually install it so there will be no need to hoist it because it already is. Anyway as I said I'm no pnp expert. |
The thing is it does, it just doesn't declare it mikro-orm/packages/core/src/MikroORM.ts Line 110 in 576e7fe
mikro-orm/packages/core/src/MikroORM.ts Line 119 in 576e7fe
mikro-orm/packages/core/src/MikroORM.ts Line 128 in 576e7fe
There is no guarantee that you'll get access to the transitive dependencies, it is undefined behaviour and just happens to work.
That is besides the point, I'll give a different example:
Which version of knex
@darkbasic If there are issues please report them back to us (yarn) and we'll take a look, it works perfectly fine for us https://github.com/yarnpkg/berry |
During development, the Btw I guess the logic behind adding new If one does not like this dynamic require, don't use the methods and go the other way (create schema generator directly and pass the By this logic, we would have to include every driver in the core package, as they are all required dynamically: I hope you all understand that this is not an option.
What I had in my mind is not to require user to install the peer deps like knex, they would still be transitive, but the child packages would state it is a peer dependency. So with the knex example, knex would be direct dependency of |
Didn't even spot that one, seems the solution to core is to require on behalf of the user using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Martin Adámek <banan23@gmail.com>
Perfect, and no worries 👍 |
Changed the title as I dont consider this as a fix (v4 is not yet released), hope it makes sense... |
Thanks again! |
No problem, thanks for this great ORM 👍 |
* fix(sqlite): add missing dependency fs-extra * fix(mariadb): add missing dependency @mikro-orm/core * fix(mariadb): add missing dependency @mikro-orm/knex * fix(core): add missing dependency @mikro-orm/entity-generator * fix(core): add missing dependency @mikro-orm/knex * fix(core): add missing dependency @mikro-orm/migrations * feat(knex): export knex * feat(knex): add requireModule helper * fix(sqlite): get knex from @mikro-orm/knex * fix(postgresql): get knex from @mikro-orm/knex * fix(mysql-base): get knex from @mikro-orm/knex * fix(mariadb): get knex from @mikro-orm/knex * chore: change root package name to avoid conflict * fix(cli): node_modules isn't guaranteed to exist * fix(core): add missing dependency tsconfig-paths * fix(core): add missing optional peer dependency ts-node * fix(core): require on behalf of the user * fix(core): get the schema generator from the driver * fix(core): require ts-node as config * fix(core): require tsconfig-paths from config * chore: update ignore comments * style(core): add spacing Co-authored-by: Martin Adámek <banan23@gmail.com> * refactor: add requireFrom helper * refactor: make core a peer dependency * docs(core): document requireFrom * refactor: move getSchemaGenerator to platform * fix(core): ensure absolute paths * refactor(mariadb): use knex from mysql-base * style: spaces not tabs Co-authored-by: Martin Adámek <banan23@gmail.com> * refactor(core): use path.resolve * test: fix cli helper tests * fix(core): handle folders in requireFrom * test: update getModuleVersion * test: mongodb throws on getSchemaGenerator Co-authored-by: Martin Adámek <banan23@gmail.com>
* fix(sqlite): add missing dependency fs-extra * fix(mariadb): add missing dependency @mikro-orm/core * fix(mariadb): add missing dependency @mikro-orm/knex * fix(core): add missing dependency @mikro-orm/entity-generator * fix(core): add missing dependency @mikro-orm/knex * fix(core): add missing dependency @mikro-orm/migrations * feat(knex): export knex * feat(knex): add requireModule helper * fix(sqlite): get knex from @mikro-orm/knex * fix(postgresql): get knex from @mikro-orm/knex * fix(mysql-base): get knex from @mikro-orm/knex * fix(mariadb): get knex from @mikro-orm/knex * chore: change root package name to avoid conflict * fix(cli): node_modules isn't guaranteed to exist * fix(core): add missing dependency tsconfig-paths * fix(core): add missing optional peer dependency ts-node * fix(core): require on behalf of the user * fix(core): get the schema generator from the driver * fix(core): require ts-node as config * fix(core): require tsconfig-paths from config * chore: update ignore comments * style(core): add spacing Co-authored-by: Martin Adámek <banan23@gmail.com> * refactor: add requireFrom helper * refactor: make core a peer dependency * docs(core): document requireFrom * refactor: move getSchemaGenerator to platform * fix(core): ensure absolute paths * refactor(mariadb): use knex from mysql-base * style: spaces not tabs Co-authored-by: Martin Adámek <banan23@gmail.com> * refactor(core): use path.resolve * test: fix cli helper tests * fix(core): handle folders in requireFrom * test: update getModuleVersion * test: mongodb throws on getSchemaGenerator Co-authored-by: Martin Adámek <banan23@gmail.com>
@B4nan Maybe it could be changed to |
We could do Btw I believe that WKT problem can be now solved without using knex raw, see https://mikro-orm.io/docs/custom-types/#advanced-example---pointtype-and-wkt |
Currently I am using custom types, but previously I was using this: import { Knex } from "@mikro-orm/knex";
const knex = Knex.default({ client: "mysql" }); |
What's the problem this PR addresses?
MikroORM is currently trying to use dependencies without declaring them which doesn't work under strict dependency environments (Yarn PnP) and makes us rely on hoisting which is really fragile.
Example:
Running
yarn add @mikro-orm/sqlite knex@0.19.0
will produce a tree where@mikro-orm/sqlite
won't get the same version ofknex
as@mikro-orm/knex
How did you fix it?
Add the undeclared dependencies and make sure the version of knex is required from
@mikro-orm/knex