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

Commit

Permalink
fix: Set INIT_CWD env in all before-* hooks (#480)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rosen-vladimirov authored and manoldonev committed Apr 2, 2018
1 parent 87dd53d commit b7ef84f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/before-cleanApp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const { cleanSnapshotArtefacts } = require("../snapshot/android/project-snapshot-generator");
const { isAndroid } = require("../projectHelpers");
const { setProcessInitDirectory } = require("./utils");

module.exports = function (hookArgs) {
if (isAndroid(hookArgs.platformInfo.platform)) {
cleanSnapshotArtefacts(hookArgs.platformInfo.projectData.projectDir);
const projectDir = hookArgs.platformInfo.projectData.projectDir;
setProcessInitDirectory(projectDir);
cleanSnapshotArtefacts(projectDir);
}
}
7 changes: 6 additions & 1 deletion lib/before-prepareJS.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { runWebpackCompiler } = require("./compiler");
const { setProcessInitDirectory } = require("./utils");

module.exports = function ($logger, hookArgs) {
const env = hookArgs.config.env || {};
Expand All @@ -10,6 +11,10 @@ module.exports = function ($logger, hookArgs) {
bundle: appFilesUpdaterOptions.bundle,
release: appFilesUpdaterOptions.release,
};
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, hookArgs.config.projectData, $logger, hookArgs);

const projectData = hookArgs.config.projectData;
setProcessInitDirectory(projectData.projectDir);

const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, projectData, $logger, hookArgs);
return result;
}
3 changes: 3 additions & 0 deletions lib/before-shouldPrepare.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { join } = require("path");
const { readFileSync, existsSync, writeFileSync } = require("fs");
const { setProcessInitDirectory } = require("./utils");
const envOptionsCacheFileLocation = join(__dirname, "env.cache.json");

module.exports = function (hookArgs) {
const platformInfo = hookArgs.shouldPrepareInfo && hookArgs.shouldPrepareInfo.platformInfo;
if (platformInfo && platformInfo.appFilesUpdaterOptions && platformInfo.appFilesUpdaterOptions.bundle) {
setProcessInitDirectory(platformInfo.projectData.projectDir);

return (args, originalMethod) => {
return originalMethod(...args).then(originalShouldPrepare => {
const currentEnvString = JSON.stringify(platformInfo.env || {});
Expand Down
5 changes: 4 additions & 1 deletion lib/before-watch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { runWebpackCompiler } = require("./compiler");
const { setProcessInitDirectory } = require("./utils");

module.exports = function ($logger, hookArgs) {
if (hookArgs.config) {
Expand All @@ -15,7 +16,9 @@ module.exports = function ($logger, hookArgs) {
watch: true
};

return runWebpackCompiler(config, hookArgs.projectData, $logger, hookArgs);
const projectData = hookArgs.projectData;
setProcessInitDirectory(projectData.projectDir);
return runWebpackCompiler(config, projectData, $logger, hookArgs);
}));
}
}
Expand Down

0 comments on commit b7ef84f

Please sign in to comment.