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

fix: Hooks are not executed correctly when CLI is used as a library #479

Merged
merged 1 commit into from
Mar 30, 2018

Conversation

rosen-vladimirov
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov commented Mar 30, 2018

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.

PR Checklist

What is the current behavior?

Trying to use webpack builds from CLI, when CLI is used as a library, leads to different errors as the projectData is not correct.

What is the new behavior?

The hooks take the correct data from hookArgs or projectDataService and the build with webpack works when CLI is used as a library

@rosen-vladimirov rosen-vladimirov self-assigned this Mar 30, 2018
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.
@SvetoslavTsenov
Copy link
Contributor

test

@@ -10,6 +10,6 @@ module.exports = function ($projectData, $logger, hookArgs) {
bundle: appFilesUpdaterOptions.bundle,
release: appFilesUpdaterOptions.release,
};
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $projectData, $logger, hookArgs);
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, hookArgs.config.projectData, $logger, hookArgs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this (hookArgs.config...) is intentionally different from the rest but I couldn't sort it out why by looking briefly through the cli source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hookArgs object contains the arguments passed to the decorated method. The current hook is executed when the preparePlatform method in CLI is called: https://github.com/NativeScript/nativescript-cli/blob/97d72e9f414b1911982af715b36ae21f599cf32c/lib/services/prepare-platform-js-service.ts#L36
As you can see, this method accepts a single argument called config. So the hookArgs object in the current context will have a single property - config and its value will be the value passed to the preparePlatform method. We know this value will be object which has projectData property.

For the other hooks the projectData is often a direct argument of the decorated method, for example: https://github.com/NativeScript/nativescript-cli/blob/master/lib/services/platform-service.ts#L283-L287

@manoldonev
Copy link
Contributor

@manoldonev manoldonev merged commit 87dd53d into master Mar 30, 2018
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-hooks branch April 1, 2018 21:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants