Skip to content
This repository was 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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
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.

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