Skip to content
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

yarn plug and play and optional peerDependencies #3059

Closed
kapouer opened this issue Feb 19, 2019 · 2 comments · Fixed by #3081
Closed

yarn plug and play and optional peerDependencies #3059

kapouer opened this issue Feb 19, 2019 · 2 comments · Fixed by #3081

Comments

@kapouer
Copy link
Contributor

@kapouer kapouer commented Feb 19, 2019

Hi,

yarn --pnp is a really interesting thing to speedup module loading:
https://yarnpkg.com/en/docs/pnp
however it needs all modules to declare what they depend on to be able to work properly.

In the case of modules like knex, where one of the dependencies is declared by a parent module, the plug and play system fails (e.g. knex won't find pg).
pg, mysql2, sqlite3 (...) should be in peerDependencies, but optional.

This is precisely what yarn's peerDependenciesMeta field do:
yarnpkg/yarn@011a634

However i suppose it needs to be available in npm too before it can be added to knex's package.json.

Meanwhile, a simple solution would be to be able to pass knex the driver module itself, like

var pg = require('knex')({
  client: 'pg',
  driver: require('pg'),
  connection: process.env.PG_CONNECTION_STRING,
  searchPath: ['knex', 'public'],
});
@elhigu

This comment has been minimized.

Copy link
Member

@elhigu elhigu commented Mar 3, 2019

That is interesting... If it can be setup to package.json without breaking npm functionality, I don't see why it couldn't be added. I don't think that just having peerDependenciesMeta attribute there will break anything.

However I still didn't understand how that should work in a way that only needed DB driver package would be included... could you elaborate it more how knex's package.json and parent projects package.json should look in that case?

kapouer added a commit to kapouer/knex that referenced this issue Mar 3, 2019
kapouer added a commit to kapouer/knex that referenced this issue Mar 3, 2019
kapouer added a commit to kapouer/knex that referenced this issue Oct 29, 2019
kibertoad added a commit that referenced this issue Oct 29, 2019
@kibertoad

This comment has been minimized.

Copy link
Collaborator

@kibertoad kibertoad commented Oct 29, 2019

Released in 0.20.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.