Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Add INIT_CWD environment variable when npm run scripts #12356

Closed
wants to merge 4 commits into from

Conversation

MichaelQQ
Copy link
Contributor

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.

@iarna
Copy link
Contributor

iarna commented Apr 27, 2016

We're not opposed to this on principle. The change should go in lib/utils/lifecycle.js however. (See where it sets env.npm_lifecycle_event, as that seems like the right place for this sort of thing).

This will also need tests and documentation before it can land.

@iarna
Copy link
Contributor

iarna commented May 9, 2016

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. =)

@MichaelQQ
Copy link
Contributor Author

I've added the test and rename it back to INIT_CWD.

@skiano
Copy link

skiano commented Jan 18, 2017

Is this still being considered? I am not sure I understand why the integration tests failed.

@MichaelQQ
Copy link
Contributor Author

Just rebase to npm:latest

@skiano
Copy link

skiano commented Jan 19, 2017

Thanks! Any idea if/when it will make it to the main branch?

@iarna
Copy link
Contributor

iarna commented Jun 30, 2017

@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.

@MichaelQQ
Copy link
Contributor Author

I forgot to push the test 😅
I've added the documentation for INIT_CWD. Please check it. Thank you. 🙇

@iarna
Copy link
Contributor

iarna commented Jul 18, 2017

Looks great, thank you! I've landed this as 20c4622 in release-next with a bit of a rewrite to the documentation. It'll be out in a week or two in our next npm release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants