NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.21k stars 241 forks source link

hooks/before-prepare will NOT be executed because it has invalid arguments - platformsData. #1959

Closed gvsakhil closed 5 years ago

gvsakhil commented 5 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug When I run tns run android Its giving a warning /Users/akki/Documents/Workspace/UTU/UTU.MobileApp/hooks/before-prepare/nativescript-custom-entitlements.js will NOT be executed because it has invalid arguments - platformsData. and this is happening from the day I migrated my nativescript version to tns6.

Fatme commented 5 years ago

@gvsakhil,

NativeScript 6.0 release has breaking changes that affects the way the hooks are executed. More info can be found here. As platformsData is renamed to platformsDataService in CLI 6.0, you need to change $platformsData to $platformsDataService:

module.exports = function($platformsDataService) {

If you want to make it backwards compatible, you could use the following:

module.exports = function($injector, hookArgs) {
    const platformsData = getPlatformsData($injector);
}

function getPlatformsData($injector) {
    try {
        return $injector.resolve("platformsData");
    } catch (err) {
        return $injector.resolve("platformsDataService");
    }
}
Fatme commented 5 years ago

I'm closing this issue as it is expected after migrating to NativeScript 6.0.

gvsakhil commented 5 years ago

In which file should I make that change module.exports = function($platformsDataService) { @Fatme

Fatme commented 5 years ago

@gvsakhil, The change should be made in /Users/akki/Documents/Workspace/UTU/UTU.MobileApp/hooks/before-prepare/nativescript-custom-entitlements.js.

gvsakhil commented 5 years ago

Sometimes we delete hooks folder and again build. So we should change the code every time we delete hooks folder?