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

Commit

Permalink
chore: Do not set INIT_CWD on any hook (#493)
Browse files Browse the repository at this point in the history
Previously the INIT_CWD environment variable was set only in one of the hooks. In a recent PR, we've changed the logic of all `before-*` hooks to set the INIT_CWD environment variable.
After some discussions and investigation, we've found that we do not need the INIT_CWD variable. So remove the setting of the variable from all hooks and delete the method that sets it.
  • Loading branch information
rosen-vladimirov authored and dtopuzov committed Apr 18, 2018
1 parent d2bcb52 commit afe6208
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 23 deletions.
5 changes: 1 addition & 4 deletions lib/before-cleanApp.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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)) {
const projectDir = hookArgs.platformInfo.projectData.projectDir;
setProcessInitDirectory(projectDir);
cleanSnapshotArtefacts(projectDir);
cleanSnapshotArtefacts(hookArgs.platformInfo.projectData.projectDir);
}
}
6 changes: 1 addition & 5 deletions lib/before-prepareJS.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { runWebpackCompiler } = require("./compiler");
const { setProcessInitDirectory } = require("./utils");

module.exports = function ($logger, hookArgs) {
const env = hookArgs.config.env || {};
Expand All @@ -12,9 +11,6 @@ module.exports = function ($logger, hookArgs) {
release: appFilesUpdaterOptions.release,
};

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

const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, projectData, $logger, hookArgs);
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, hookArgs.config.projectData, $logger, hookArgs);
return result;
}
2 changes: 0 additions & 2 deletions lib/before-shouldPrepare.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
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 => {
Expand Down
5 changes: 1 addition & 4 deletions lib/before-watch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { runWebpackCompiler } = require("./compiler");
const { setProcessInitDirectory } = require("./utils");

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

const projectData = hookArgs.projectData;
setProcessInitDirectory(projectData.projectDir);
return runWebpackCompiler(config, projectData, $logger, hookArgs);
return runWebpackCompiler(config, hookArgs.projectData, $logger, hookArgs);
}));
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/before-watchPatterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { basename } = require("path");
const {
buildEnvData,
getCompilationContext,
setProcessInitDirectory,
} = require("./utils");

module.exports = function (hookArgs) {
Expand All @@ -11,7 +10,6 @@ module.exports = function (hookArgs) {
return;
}

setProcessInitDirectory(hookArgs.projectData.projectDir);
const { platforms } = hookArgs;
const { env } = liveSyncData;
return (args, originalMethod) => {
Expand Down
7 changes: 1 addition & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ function shouldSnapshot(config) {
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot;
}

function setProcessInitDirectory(dir) {
process.env.INIT_CWD = dir;
}

module.exports = {
buildEnvData,
getCompilationContext,
shouldSnapshot,
setProcessInitDirectory,
shouldSnapshot
};

0 comments on commit afe6208

Please sign in to comment.