title: Automatically Build NPM Module On Install From Github
body: <p>Given that a project's <code>lib/</code> dir shouldn't be checked into Git because the files it contains are derived files (from the build process). When installing a package from the project's github (during development for example) the <code>lib/</code> dir will not exist, so if the package's <code>package.json</code>'s <code>main</code> field points to (for example) <code>lib/index.js</code>, the package cannot be compiled when imported because these files do not exist within the repository and therefore within the package installed into <code>node_modules</code>. This means the package needs to built (just as it would be before release), only this time locally so that the <code>lib</code> directory (or whatever other files are generated during the build process) are added to the module's directory.</p>
  
  <p><strong>Assuming there is a <code>build</code> script within the <code>package.json</code> file's <code>scripts</code> field, can the package be configured to run this automatically in the situation where it is installed from github only? If not, what is the the best approach to ensuring it is built when installed from github?</strong> </p>
  
  <p>There are now <code>prepublish</code>, <code>prepublishOnly</code> and <code>prepare</code> lifecycle hooks, but none provide an answer to this problem because they don't allow any way to differentiate between the source of the install. In short, yes they allow you to build on install, but they don't allow you to build on install from github only. There is not only no reason to force a build when people install from npm, but more importantly, development dependencies will not be installed (for example <code>babel</code> which is critical to the build).</p>
  
  <p>I am aware of one strategy to deal with this problem:</p>
  
  <ul>
  <li>Fork / branch the repo</li>
  <li>build locally</li>
  <li>remove the <code>lib/</code> dir from <code>.gitignore</code> and check it in.</li>
  <li>install module from your fork/branch</li>
  <li>When you are ready for a PR / rebase add <code>lib/</code> dir to <code>.gitignore</code> and remove dir from git.</li>
  </ul>
  
  <p>But that is far from ideal. I guess this could be automated with a githook though. So every you push to master the project also builds and pushes to a separate branch.</p>
  
  <p>There is a <a href="https://github.com/npm/npm/issues/3055" rel="noreferrer">closed issue</a> on NPM's Github with no resolution - just lots of people who want a solution. From this issue it is clear that using <code>prepare</code> is not the answer. </p>
  
  <p>My usecase is that I am developing a module that is used in a number of other projects. I want to consume the latest version of the module without having to push out a release to NPM whenever I update the codebase - I would rather push out fewer releases when I am ready, but I still need to consume whatever the latest version of the lib is on Github. </p>
  
  <p>Note: I also reached out to NPM's support regarding this issue and I'll add their response if I receive one. </p>