-
Notifications
You must be signed in to change notification settings - Fork 3k
Add INIT_CWD environment variable when npm run scripts #12356
Conversation
We're not opposed to this on principle. The change should go in This will also need tests and documentation before it can land. |
I would stay w/ the original env var (all caps), but that's the right place, thank you. Now we just need a test and a patch to documentation so folks know that this is available. =) |
I've added the test and rename it back to INIT_CWD. |
Is this still being considered? I am not sure I understand why the integration tests failed. |
Just rebase to npm:latest |
Thanks! Any idea if/when it will make it to the main branch? |
@skiano It still needs tests and docs. @MichaelQQ You said "I've added the test" but I don't see any tests in your PR? We also need documentation for this feature. |
I forgot to push the test 😅 |
Looks great, thank you! I've landed this as 20c4622 in |
Credit: @MichaelQQ Reviewed-By: @iarna PR-URL: #12356
As the issue #12164 mentioned, npm run scripts sets the cwd to the project root path.
When we need to run scripts in subdir, we should use the script like "cd subdir && babel src -d lib"
In some cases, we want to use the same script in different subdir, so we should add different scripts like:
"cd subdir1 && babel src -d lib", "cd subdir2 && babel src -d lib", etc.
Therefore, I add a INIT_CWD environment variable, which is add when npm run script. In the same situation, we can have only one script "cd $INIT_CWD && babel src -d lib" or "babel $INIT_CWD/src -d $INIT_CWD/lib". Type npm run script in the subdir which I want to do it and all subdir can run the same script.