How To Open-Source Parts Of Your Private Project With Bit

Home Dev How To Open-Source Parts Of Your Private Project With Bit


A short intro to how you can open source parts of your private projects without having to refactor them or compromise their privacy.

Perhaps the no.1 barrier to open-sourcing useful code and sharing it with the community is the fact that it’s often written in a larger, private project.

Open-sourcing parts of your project would usually mean having to split and refactor your project just to put parts of it as new projects on GitHub.

This overhead is usually enough to block most of us from sharing useful pieces of code we write every day, which could make excellent open source modules.

Those who do, like Sindre Sorhus, make a huge impact on the community by saving people the need to re-invent the smaller building blocks for every project they build. Imagine a world where everyone could be Sindre.

Sindre’s 1000th NPM package

Lowering the overhead barriers to sharing parts of private projects can help the community share more code, and leverage each other’s work to build new things faster instead of re-inventing the pieces they’re built from.

In this short post I’ll show how using (open source project) Bit you can quickly open-source parts of your existing private GitHub, GitLab or BitBucket projects without having to split the project or compromise its privacy.

How is that possible?

The things about Bit is that it was built to allow the isolation and sharing of small components. These can be common functionalities, small modules or even UI components, all of which are basically just sets of files in your repo.

Using Bit, you can isolate these sets of files (we call code components) from your project and share them with the open source community, while keeping their source project private and intact.

Let’s look at this example project structure which includes a component called hello-world. Let’s say that this project is private, but we think that hello-world would make a great module for the open-source community.

.
├── bit.json
├── package.json
└── src
├── hello-world
│ ├── hello-world.js
│ └── index.js
└── utils
└── noop.js

Before Bit, we would have to create a new GitHub project for this component, remove hello-world from your private project and make all its dependancies (packages as well as other files from the project) available for the new project.

With Bit, you can keep this component as part of your private project and still make it available to the community to discover, use and collaborate on.

This becomes possible thanks to Bit’s ability to isolate sets of files from the project as components. When you use the bit add command to point Bit to sets of files in your repository it will start tracking them as components.

Bit will also read through the files and looks for import or require statements to find dependencies for the code. If it finds any, it will figure out if they are either package dependencies or additional files from the project.

When you use the bit tag command Bit locks the components’ dependency graphs in place, and also locks a version for the components it tracks.

Open source parts of your project to the community

To make sure your components are truly executable outside of the project’s context, Bit will build an isolated component environment and apply all configured extensions to test, compile or perform any other defined task.

By now, your private project remained in tact while Bit identified, isolated and prepared the part of it you want to share with the open source community.

Share with the community

You can share component to Bit’s free hub, to your own servers and also to GitHub, it’s really your choice.

The simplest way would be to share your components to the free Bit Hub. From there they will be made available to the world to discover and use with NPM, Yarn or even Bit itself (to develop them from other projects).

Here is an example React application on GitHub. It’s open source, but could have just as easily been a private repository from an organization.

Using Bit, all its React UI components were shared to the Hub and organized in a Bit Scope. Here is what a UI component looks like after shared with Bit.

https://bitsrc.io/bit/movie-app/components/hero

Note that every component in automatically made available to install using NPM and Yarn, and is presented with docs parsed right from the source code itself + test results to help improve discoverability for the code you share.

You can also use bit import to bring the component’s source code into other projects, develop them and merge changes between different projects.

Auto-parsed docs and examples means discoverabilty

If you’re sharing React UI components, Bit can also render the components and create a live playground to help discover and choose the best ones.

Here is another example shared by the members of the community: a React UI library on GitHub from which components were shared to this Bit Scope. Visit the card or avatar components to play with their live visualization.

React vital-ui-kit

The same process works for Node.js modules, utility functions and almost any useful component you can think of. Here is an example of JS utility functions shared from a utility library created a while ago and shared with Bit.

JS utilities shared with Bit from this library

If you choose, you can also share the code to GitHub. You don’t have to, but it can help other collaborate and open issues for the code you open-source.

For example, we shared the content of Bit’s documentation to GitHub to make it easier for people to suggest improvements to its content. We also use Bit to sync its components with the main (private) docs project we maintain.

Bit docs as components on Bit’s Hub

This flow is also useful for sharing with your team. Having a “Lego-box” of your team’s shared components helps build new features faster while reducing the overhead of finding and maintain shared code.

We use Bit to share and sync over 250 Node and React code component between our projects. You can learn more about how Bit was created here.

Collaborate to build faster

Almost any developer can thing of at least 10 or 20 or 50 great modules they wrote which would make for killer open source projects and NPM packages.

Lowering the barrier for sharing small stuff from your projects and making it open source without compromising the whole project can help everyone share, discover and build with components already written before.

The community can enjoy a greater supply of useful and high-quality building blocks which, given good enough discoverability, can be leveraged to focusing its time on innovating and breaking through new technologies.

Bit itself is open source so you are more than welcome to use it to share some of your own components with the world. We try to do that every single day.

Learn more:

  • How to easily share React components between projects
  • How to publish multiple packages from any repo in 5 minutes
  • 11 React component libraries you should know for 2018

Leave a Reply

Your email address will not be published.