Given that a project's lib/
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 lib/
dir will not exist, so if the package's package.json
's main
field points to (for example) lib/index.js
, the package cannot be compiled when imported because these files do not exist within the repository and therefore within the package installed into node_modules
. This means the package needs to built (just as it would be before release), only this time locally so that the lib
directory (or whatever other files are generated during the build process) are added to the module's directory.
Assuming there is a build
script within the package.json
file's scripts
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?
There are now prepublish
, prepublishOnly
and prepare
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 babel
which is critical to the build).
I am aware of one strategy to deal with this problem:
lib/
dir from .gitignore
and check it in.lib/
dir to .gitignore
and remove dir from git.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.
There is a closed issue on NPM's Github with no resolution - just lots of people who want a solution. From this issue it is clear that using prepare
is not the answer.
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.
Note: I also reached out to NPM's support regarding this issue and I'll add their response if I receive one.