Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

yarn run: can I get the caller path?

I’m using Yarn 3’s workspaces.

If I have a script in a package.json

{
  "name": "myscripts",
  "scripts": {
    "migrate": "./migrate up -m src/migrations"

and in another package foo

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "name": "foo",
  "dependencies": {
    "myscripts": "workspace:*"

if I run migrate from the foo package

yarn run migrate

is there a way to get the folder of the foo package in my migrate script?

I want to use the path in my migrate script ./migrate up -m $CALLERS_PATH/migrations

>Solution :

The yarn docs here: https://yarnpkg.com/advanced/lifecycle-scripts indicate that scripts are invoked with an INIT_CWD env var set to the original cwd the script was invoked from.

You should be able to (in a shell script for example), reference the path with

./migrate up -m $INIT_CWD/migrations
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading