Yarn tip: You can alias a package by using yarn add fake-name@npm:left-pad
.
Now you can use require("fake-name")
to require left-pad.
This could be useful for module level dependency injection or inversion of control...
but not for dependencies of your dependencies. See test 3.
So we'll try it with get-query-param which depends on query-string v5.0.0 which we will replace with qs.
Create a new project with yarn init
.
yarn add query-string@npm:qs
yarn add get-query-param
get-query-param
got its own copy of query-string
in
node_modules/get-query-param/node_modules/query-string
.
yarn add query-string@npm:qs get-query-param
get-query-param
got its own copy of query-string
in
node_modules/get-query-param/node_modules/query-string
.
- Clone get-query-param to
../get-query-param2
, change the package name and movequery-string
fromdependencies
topeerDependencies
in itspackage.json
. yarn add query-string@npm:qs
yarn add file:./../get-query-param2
- copy
test.js
fromnode_modules/get-query-param2
to project root and modify its import, then runyarn add ava
, addscripts: { test: 'ava -v'}
to your ownpackage.json
and then runyarn test
.
get-query-param2
uses qs
as its query-serializer
and all tests pass.
Interesting. So the only way to fix this is by forking the packages that list the package you're trying to alias and moving it to
peerDependencies
?