Mostly the same question as this, but for yarn 2. I put my shared dependencies at the top of the hierarchy. I believe I'm not using PnP currently.
.yarnrc.yaml
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-2.2.2.cjs
at the very top level I have typescript
installed (but I presume this could be any module with a binary) down in one of my "workspaces" I want to call tsc
, however it's command not found: tsc
I've also noticed some warnings like. graph@workspace:app-lib/graph/packages/app doesn't provide jest@>=24 <25 requested by ts-jest@npm:24.3.0
which is provided in the parent of app.
https://yarnpkg.com/advanced/qa#how-to-share-scripts-between-workspaces
Little-known Yarn feature: any script with a colon in its name (build:foo) can be called from any workspace. Another little-known feature: $INIT_CWD will always point to the directory running the script. Put together, you can write scripts that can be reused this way:
{
"dependencies": {
"typescript": "^3.8.0"
},
"scripts": {
"g:tsc": "cd $INIT_CWD && tsc"
}
}
Then, from any workspace that contains its own tsconfig.json, you'll be able to call TypeScript:
{
"scripts": {
"build": "yarn g:tsc"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With