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

fix: Set INIT_CWD env in all before-* hooks #480

Merged
merged 1 commit into from
Apr 2, 2018

Conversation

rosen-vladimirov
Copy link
Contributor

In a long living process, where the project can be changed, we need to set
the INIT_CWD environment variable in all before-* hooks. Currently it is
set only in the before-watchPatterns hook. This way, when we use webpack
for a project and later we try to use webpack for another project, we try
to execute some operations based on the INIT_CWD directory, which still
points to our old project. In order to fix this unexpected behavior, set
the INIT_CWD in all before-* hooks, as some of them may be skipped based
on the state of the project.

PR Checklist

What is the current behavior?

Currently when you try to use webpack to build more than one project in the same process (for example in Sidekick), the INIT_CWD variable is set when the first project is built. When the next project should be build, the INIT_CWD env variable is already set and the hooks of the second project are not executed correctly as they search for their resources in the first project.

What is the new behavior?

Set INIT_CWD environment variable in all before-* hooks, so multiple projects can be build in the same process.

In a long living process, where the project can be changed, we need to set
the INIT_CWD environment variable in all before-* hooks. Currently it is
set only in the `before-watchPatterns` hook. This way, when we use webpack
for a project and later we try to use webpack for another project, we try
to execute some operations based on the INIT_CWD directory, which still
points to our old project. In order to fix this unexpected behavior, set
the INIT_CWD in all before-* hooks, as some of them may be skipped based
on the state of the project.

module.exports = function (hookArgs) {
if (isAndroid(hookArgs.platformInfo.platform)) {
cleanSnapshotArtefacts(hookArgs.platformInfo.projectData.projectDir);
const projectDir = hookArgs.platformInfo.projectData.projectDir;
setProcessInitDirectory(projectDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be outside of if statement? In case when command is executed for iOS platform setProcessInitDirectory method will not be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we will not execute any logic, so there's no need to reset the variable. I prefer setting it only when we will execute some work.

@manoldonev manoldonev merged commit b7ef84f into master Apr 2, 2018
@manoldonev manoldonev deleted the vladimirov/fix-init-dir branch April 2, 2018 13:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants