Skip to content

feat: skip postinstall steps in case CLI is not installed globally #4317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2019

Conversation

rosen-vladimirov
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov commented Jan 28, 2019

In case the CLI package is not installed globally, probably it is installed as a dependency of a project or as a dependency of other dependency.
In this case the postinstall actions have no meaning for the user, as probably CLI will be used as a library.
Skip all of the postinstall actions in such case. Remove the execution code of the old post-install command and move it to post-install-cli command.
Add unit tests. Remove a property from staticConfig - it has no meaning to be there, just place it in the postinstall command directly.
Handle case when CLI is installed globally with npm or yarn - in both cases the npm_config_argv will be populated with the original command. For example:

  • npm i -g nativescript - the npm_config_argv will be: ["i", "-g", "nativescript"]
  • yarn global add nativescript - the npm_config_argv will be: ["global", "add", "nativescript"]

PR Checklist

What is the current behavior?

When executing npm i nativescript, you are prompted to enable autocompletion and all other post install tasks.

What is the new behavior?

CLI will ask you to enable autocompletion (and other questions asked on post-install) only when npm i -g nativescript or yarn global add nativescript is used.

Implements issue #4323

In case the CLI package is not installed globally, probably it is installed as a dependency of a project or as a dependency of other dependency.
In this case the postinstall actions have no meaning for the user, as probably CLI will be used as a library.
Skip all of the postinstall actions in such case. Remove the execution code of the old `post-install` command and move it to `post-install-cli` command.
Add unit tests. Remove a property from staticConfig - it has no meaning to be there, just place it in the postinstall command directly.
Currently the postinstall.js requires helpers and tries to execute some methods of it. However, CLI is not bootstraped and the global variable `_` is not set, so the action fails. Fix the code by adding require to `lodash` in the current file.
The other option of fix is to remove the `helpers` require from postinstall script to `post-install-cli` command. However, the current check is if we should execute the postinstall actions - if we move the check to the command, the commands service will still execute the check and prompt the user to allow tracking, which is not a desired behavior.
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/skip-postinstall-lib branch from da404fd to 3d13b99 Compare January 29, 2019 16:30
@rosen-vladimirov rosen-vladimirov merged commit d70fe8b into master Jan 29, 2019
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/skip-postinstall-lib branch January 29, 2019 17:44
dtopuzov added a commit to NativeScript/nativescript-tooling-qa that referenced this pull request Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants