Installing a Dependency from a Monorepo Easily

Zafir Sk Heerah
2 min readJul 12, 2024

--

When working with JavaScript projects, monorepos are a popular way to manage multiple packages or projects under a single repository.

Encountering a monorepo that has not published a sub-package to a registry like NPM is very common, having a tool like gitpkg is very useful. As gitpkg, allows you to publish sub-packages from a monorepo as temporary git repositories, which can be installed as dependencies in other projects.

URL Structure

https://gitpkg.now.sh/{github-username}/{repo-name}/{package-path}?{commit-hash}

Where:

  • {github-username} is the GitHub username of the repository owner.
  • {repo-name} is the name of the GitHub repository.
  • {package-path} is the path within the repository where the package is located.
  • {commit-hash} is the specific commit hash from which you want to install the package.

Using the URL to Install the Package

Given the URL format, you can install the package directly using npm or yarn by running:

NPM

npm install git+https://gitpkg.now.sh/zfir/monorepo/subpackage?d9f0ca9dfe7385b3f44fb961d1600f0304ae9e42

Yarn

yarn add git+https://gitpkg.now.sh/zfir/monorepo/subpackage?d9f0ca9dfe7385b3f44fb961d1600f0304ae9e42

Of course, while gitpkg is a valuable tool for facilitating the testing and sharing of code changes in development or staging environments, it should not be used in production. For production deployments, it is advisable to use packages published to a stable, official registry such as npm. This practice ensures the reliability and stability of your production systems.

Note

If you're concerned about security or need more control over the package distribution process, gitpkg can be self-hosted. This option allows you to manage the service within your own infrastructure, ensuring that your code remains secure and under your control throughout the development process. For instructions on setting up your own instance of gitpkg, you can refer to the official gitpkg repository on GitHub.

--

--

Zafir Sk Heerah
Zafir Sk Heerah

Written by Zafir Sk Heerah

Software Engineer | Consultant | Android and iOS Development | www.zfir.dev | blog.zfir.dev

No responses yet