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

Commit b7ef84f

Browse files
rosen-vladimirovmanoldonev
authored andcommitted
fix: Set INIT_CWD env in all before-* hooks (#480)
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.
1 parent 87dd53d commit b7ef84f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Diff for: lib/before-cleanApp.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const { cleanSnapshotArtefacts } = require("../snapshot/android/project-snapshot-generator");
22
const { isAndroid } = require("../projectHelpers");
3+
const { setProcessInitDirectory } = require("./utils");
34

45
module.exports = function (hookArgs) {
56
if (isAndroid(hookArgs.platformInfo.platform)) {
6-
cleanSnapshotArtefacts(hookArgs.platformInfo.projectData.projectDir);
7+
const projectDir = hookArgs.platformInfo.projectData.projectDir;
8+
setProcessInitDirectory(projectDir);
9+
cleanSnapshotArtefacts(projectDir);
710
}
811
}

Diff for: lib/before-prepareJS.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { runWebpackCompiler } = require("./compiler");
2+
const { setProcessInitDirectory } = require("./utils");
23

34
module.exports = function ($logger, hookArgs) {
45
const env = hookArgs.config.env || {};
@@ -10,6 +11,10 @@ module.exports = function ($logger, hookArgs) {
1011
bundle: appFilesUpdaterOptions.bundle,
1112
release: appFilesUpdaterOptions.release,
1213
};
13-
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, hookArgs.config.projectData, $logger, hookArgs);
14+
15+
const projectData = hookArgs.config.projectData;
16+
setProcessInitDirectory(projectData.projectDir);
17+
18+
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, projectData, $logger, hookArgs);
1419
return result;
1520
}

Diff for: lib/before-shouldPrepare.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const { join } = require("path");
22
const { readFileSync, existsSync, writeFileSync } = require("fs");
3+
const { setProcessInitDirectory } = require("./utils");
34
const envOptionsCacheFileLocation = join(__dirname, "env.cache.json");
45

56
module.exports = function (hookArgs) {
67
const platformInfo = hookArgs.shouldPrepareInfo && hookArgs.shouldPrepareInfo.platformInfo;
78
if (platformInfo && platformInfo.appFilesUpdaterOptions && platformInfo.appFilesUpdaterOptions.bundle) {
9+
setProcessInitDirectory(platformInfo.projectData.projectDir);
10+
811
return (args, originalMethod) => {
912
return originalMethod(...args).then(originalShouldPrepare => {
1013
const currentEnvString = JSON.stringify(platformInfo.env || {});

Diff for: lib/before-watch.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { runWebpackCompiler } = require("./compiler");
2+
const { setProcessInitDirectory } = require("./utils");
23

34
module.exports = function ($logger, hookArgs) {
45
if (hookArgs.config) {
@@ -15,7 +16,9 @@ module.exports = function ($logger, hookArgs) {
1516
watch: true
1617
};
1718

18-
return runWebpackCompiler(config, hookArgs.projectData, $logger, hookArgs);
19+
const projectData = hookArgs.projectData;
20+
setProcessInitDirectory(projectData.projectDir);
21+
return runWebpackCompiler(config, projectData, $logger, hookArgs);
1922
}));
2023
}
2124
}

0 commit comments

Comments
 (0)