Skip to content

Conversation

@PanayotCankov
Copy link
Contributor

Installing from local directory, npm will set process.env.INIT_CWD to the app path, and symlink to the postinstall scripts will be resolved in __dirname

… the app path, and symlink to the postinstall scripts will be resolved in __dirname
@sis0k0
Copy link

sis0k0 commented Oct 18, 2017

Currently, if you are using npm 5 and try to install a nativescript plugin with hooks from local path, the hooks it contains, won't be copied to the project directory. That's because npm install creates a symlink for the installed plugin (again, npm5+). As a result, if you execute a livecycle script, located inside the plugin dir (for ex. - ~/my-plugin/postinstall.js), the value of __dirname will be the original location of the plugin on the drive (~/my-plugin), instead of ~/my-app/node_modules/my-plugin.
INIT_CWD is available in npm since v5.3 and it contains the path where you spawned the process from.
In short, if you run npm install inside ~/my-app, INIT_CWD will be assigned to ~/my-app.
This change fixes the mentioned problem with the hooks.

@Mitko-Kerezov Mitko-Kerezov merged commit 6c84d51 into master Nov 2, 2017
@Mitko-Kerezov Mitko-Kerezov deleted the fix-npm5-local-installations branch November 2, 2017 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants