Skip to content

Commit

Permalink
fix duplicate script
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Nov 25, 2020
1 parent 66fc905 commit 128df12
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
51 changes: 51 additions & 0 deletions docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,54 @@ You either forgot to call `yarn build` or did a direct import (`import foobar fr
Don't forget to build the code.
If you write a test for package "React Hooks", and discover and fix a bug in package "GraphQL", you'll need to rebuild the "GraphQL" package to get the freshest version.
#### Weird behaviour when linking with React, Apollo, Mongoose.
Define Peer Dependencies correctly. Many packages have side effects that are problematic if you duplicate them. Those packages should be
peer-dependencies in the relevant `package.json`. You may add them at the root of the project too in development.
##### Example with Mongoose
###### Make it a peer dependency
In `packages/mongo/package.json`:
```
peerDependencies: {
mongoose: "> 5"
}
```
The end application will have only 1 version of Mongoose thanks to this.
In `./package.json`:
```
devDependencies: {
"mongoose": "^5.10.16"
}
```
###### Setup for local install
This install `mongoose` as a global dev dependency so we can write unit tests for instance.
And now enable local development:
In `scripts/link-duplicates`:
```
cd ./node_modules/@apollo/client && yarn link && cd ../..
```
When you link the packages for local development, the `mongoose` from `vulcan-npm` will be used. This prevents potential conflicts.
In your app:
```
yarn link mongoose
```
It forces your app to use the `mongoose` install from `vulcan-npm`.
This guarantees that you use one and only one version of Mongoose.
Note: we'd like to simplify this process in the future, maybe by detecting peer dependencies automatically.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"babel-plugin-transform-define": "^2.0.0",
"jest": "^26.4.2",
"lerna": "^3.22.1",
"mongoose": "^5.10.16",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"typescript": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/link-duplicates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# This guarantees we use the same peer dependencies when running the packages
cd ./node_modules/react && yarn link && cd ../..
cd ./node_modules/react-dom && yarn link && cd ../..
cd ./node_modules/@apollo/client && yarn link && cd ../..
cd ./node_modules/@apollo/client && yarn link && cd ../../..
cd ./node_modules/mongoose && yarn link && cd ../..
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7507,7 +7507,7 @@ mongodb@3.6.2:
optionalDependencies:
saslprep "^1.0.0"

mongodb@3.6.3, mongodb@^3.6.2:
mongodb@3.6.3:
version "3.6.3"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.6.3.tgz#eddaed0cc3598474d7a15f0f2a5b04848489fd05"
integrity sha512-rOZuR0QkodZiM+UbQE5kDsJykBqWi0CL4Ec2i1nrGrUI3KO11r6Fbxskqmq3JK2NH7aW4dcccBuUujAP0ERl5w==
Expand All @@ -7525,10 +7525,10 @@ mongoose-legacy-pluralize@1.0.2:
resolved "https://registry.yarnpkg.com/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz#3ba9f91fa507b5186d399fb40854bff18fb563e4"
integrity sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==

mongoose@^5.10.15:
version "5.10.15"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.10.15.tgz#5e559467890e0883d2a1ff0470a7467a1b47e52d"
integrity sha512-3QUWCpMRdFCPIBZkjG/B2OkfMY2WLkR+hv335o4T2mn3ta9kx8qVvXeUDojp3OHMxBZVUyCA+hDyyP4/aKmHuA==
mongoose@^5.10.16:
version "5.10.16"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.10.16.tgz#2b5c2ad8cc52166684261f779d882ffeb2d5b68f"
integrity sha512-rgfK1lvAQdCZ0buPju7Wny3suls5A1GjYRsv+jrQBVA0N/OhtGKHjr5RXJs0rxQhodwNVfc7O8g4bwDqW4R0sQ==
dependencies:
bson "^1.1.4"
kareem "2.3.1"
Expand Down

0 comments on commit 128df12

Please sign in to comment.