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

Commit cb009d7

Browse files
fix: Hooks are not executed correctly when CLI is used as a library
When CLI is used as a library, the `$projectData` is not populated. Instead of using this injected dependency in the hooks, the projectData should be taken from the hookArgs or from the `projectDataService`. Fix all hooks, so the correct projectData is used.
1 parent 61a6f21 commit cb009d7

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Diff for: lib/after-prepare.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { installSnapshotArtefacts } = require("../snapshot/android/project-snapshot-generator");
22
const { shouldSnapshot } = require("./utils");
33

4-
module.exports = function ($projectData, hookArgs) {
4+
module.exports = function (hookArgs) {
55
const env = hookArgs.env || {};
66
const shouldSnapshotOptions = {
77
platform: hookArgs.platform,
@@ -10,6 +10,6 @@ module.exports = function ($projectData, hookArgs) {
1010
};
1111

1212
if (env.snapshot && shouldSnapshot(shouldSnapshotOptions)) {
13-
installSnapshotArtefacts($projectData.projectDir);
13+
installSnapshotArtefacts(hookArgs.projectData.projectDir);
1414
}
1515
}

Diff for: lib/before-prepareJS.js

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

3-
module.exports = function ($projectData, $logger, hookArgs) {
3+
module.exports = function ($logger, hookArgs) {
44
const env = hookArgs.config.env || {};
55
const platform = hookArgs.config.platform;
66
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
@@ -10,6 +10,6 @@ module.exports = function ($projectData, $logger, hookArgs) {
1010
bundle: appFilesUpdaterOptions.bundle,
1111
release: appFilesUpdaterOptions.release,
1212
};
13-
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $projectData, $logger, hookArgs);
13+
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, hookArgs.config.projectData, $logger, hookArgs);
1414
return result;
1515
}

Diff for: lib/before-watch.js

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

3-
module.exports = function ($projectData, $logger, hookArgs) {
3+
module.exports = function ($logger, hookArgs) {
44
if (hookArgs.config) {
55
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
66
if (appFilesUpdaterOptions.bundle) {
@@ -15,7 +15,7 @@ module.exports = function ($projectData, $logger, hookArgs) {
1515
watch: true
1616
};
1717

18-
return runWebpackCompiler(config, $projectData, $logger, hookArgs);
18+
return runWebpackCompiler(config, hookArgs.projectData, $logger, hookArgs);
1919
}));
2020
}
2121
}

Diff for: lib/before-watchPatterns.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const {
55
setProcessInitDirectory,
66
} = require("./utils");
77

8-
module.exports = function ($projectData, hookArgs) {
8+
module.exports = function (hookArgs) {
99
const { liveSyncData } = hookArgs;
1010
if (!liveSyncData || !liveSyncData.bundle) {
1111
return;
1212
}
1313

14-
setProcessInitDirectory($projectData.projectDir);
14+
setProcessInitDirectory(hookArgs.projectData.projectDir);
1515
const { platforms } = hookArgs;
1616
const { env } = liveSyncData;
1717
return (args, originalMethod) => {
@@ -21,7 +21,7 @@ module.exports = function ($projectData, hookArgs) {
2121
}
2222

2323
const compilationContexts = platforms.map(platform =>
24-
getContext($projectData, platform, env));
24+
getContext(hookArgs.sprojectData, platform, env));
2525

2626
const ignorePatterns = compilationContexts.map(
2727
context => `!${context}`
@@ -32,7 +32,7 @@ module.exports = function ($projectData, hookArgs) {
3232
};
3333
}
3434

35-
function getContext($projectData, platform, env) {
36-
const fullEnvData = buildEnvData($projectData, platform, env);
37-
return getCompilationContext($projectData.projectDir, fullEnvData);
35+
function getContext(projectData, platform, env) {
36+
const fullEnvData = buildEnvData(projectData, platform, env);
37+
return getCompilationContext(projectData.projectDir, fullEnvData);
3838
}

0 commit comments

Comments
 (0)