☁️ Publish your npm package to a GitHub repository branch

Overview

git-publish

Publish your npm package to a Git branch.

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

Why?

For testing published packages without publishing to npm.

Making a prerelease to npm using npm publish has the following drawbacks:

  • Needs a unique version for every release.

  • Hard to remove due to npm's strict unpublish policy.

  • Cumbersome to verify the contents of the published package.

  • Production environment—risky if you make a mistake (eg. accidentally publish as stable).

Using npm link has the drawback of not running npm life cycle scripts and including non-publishable assets.

In contrast, git-publish has the following benefits:

  • Unversioned Instead of versions, branch names are used. Branches can be updated to reflect latest change.

  • Deletable Simply delete the branch when you're done with it.

  • Browsable Use GitHub to verify the contents of the branch. You can even share a link for others to see.

  • Dev environment Low risk of mistakes.

  • Simulates npm publish Runs npm life cycle scripts and only includes publishable assets.

Usage

Publish your npm package to a branch on the Git repository:

npx git-publish

⚠️ Warning: This command will force-push to the remote branch npm/<current branch>. Make sure there are no unsaved changes there.

Global install

Keep the command handy by installing it globally:

npm install -g git-publish

When globally installed, you can use it without npx:

git-publish

Flags

Flag Description
-b, --branch <branch name> The branch to publish the package to. Defaults to prefixing "npm/" to the current branch or tag name.
-r, --remote <remote> The remote to push to. (default: origin)
-d, --dry Dry run mode. Will not commit or push to the remote.
-h, --help Show help
--version Show version

FAQ

What are some use-cases where this is useful?

  • When you want to test a new package that isn't ready to be published on npm.

  • When you're contributing to an open source project so you don't have publish access, but want to test the changes in a production-like environment.

  • When you want to test in a remote environment so you can't use npm link.

  • When you want to avoid using npm link because of symlink complexities.

How can I include a build step?

Call the build command it in the prepack script.

What does this script do?

  1. Run npm hooks prepare & prepack
  2. Create a temporary branch by prefixing the current branch with the npm/ namespace
  3. Detect and commit the npm publish files
  4. Force push the branch to remote
  5. Delete local branch from Step 2
  6. Print the installation command for the branch

How is this different from simply committing the files to a branch?

  • There can be missing distribution files (eg. files outside of dist). git-publish uses npm-packlist —the same library npm publish uses—to detect publish files declared via package.json#files and .npmignore.

  • Irrelevant files are committed (eg. source files). This can slow down installation or even interfere with the library behavior. For example, if your project has development configuration files, they can accidentally be read by the dependent tooling.

  • npm hooks are not executed. git-publish simulates package packing and runs hooks prepare and prepack.

Can I publish to and install from a private repository?

Yes, if using a Git client authorized to access the private repository.

If it must be publicly accessible, you can set the --remote <remote> flag to push the publish assets to a public repository. It's recommended to compile and minify the code if doing this with private code.

User story

You want to test a branch on a private repository Repo A, but GitHub Actions on the consuming project Repo B doesn't have access to the private repository so npm install fails.

To work around this, you can publish the branch to Repo B to install it from there:

$ npx git-publish --remote [email protected]:repo-b.git --branch test-pkg

✔ Successfully published branch! Install with command:
  → npm i 'repo-b#test-pkg'
You might also like...

Publish your Obsidian note to a Telegraph page.

Publish your Obsidian note to a Telegraph page.

Obsidian Telegraph Publish Publish your Obsidian note to a Telegraph page. Features: Publish the active file to a new Telegraph page (create). Publish

Dec 12, 2022

Free Obisidian Publish alternative, for publishing your digital garden.

Free Obisidian Publish alternative, for publishing your digital garden.

What is MindStone? MindStone is a free open-source alternative solution to Obsidian Publish Here how it look like once published, checkout demo versio

Dec 30, 2022

Detect npm packages by author name in your package-lock.json or yarn.lock.

detect-package-by-author Detect npm packages by author name in your package-lock.json or yarn.lock. Install Install with npm: # Not Yet Publish # npm

Jan 11, 2022

🛫 TypeScript Starter template to simplify creating your next npm package.

TypeScript Starter Kit This is an opinionated TypeScript Starter kit to help kick-start development of your next npm package. 💡 Get Started Luckily,

Sep 27, 2022

A CLI tool to make Taobao's npm mirror sync your package immediately.

npm-mirror-sync A CLI tool to make Taobao's npm mirror sync your package immediately. 让淘宝的 NPM 镜像立即收录你的包的新版本。 背景 相信国内小伙伴都在用淘宝的 NPM 镜像(npmmirror.com)作为

Jun 9, 2022

🛫 TypeScript Starter template to simplify creating your next npm package.

TypeScript Starter Kit This is an opinionated TypeScript Starter kit to help kick-start development of your next npm package. 💡 Get Started Luckily,

May 19, 2022

Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported.

noist (Short for No Hoist) Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported. Why? As of npm@7 NPM suppo

Oct 27, 2022

Show npm package authors and maintainers of your dependencies and devDependencies.

your-deps-authors Show npm package authors and maintainers of your dependencies and devDependencies. Usage $ npx your-deps-authors ╔══════════════════

Sep 29, 2022

Semantic Release plugin to create and publish NuGet packages.

semantic-release-nuget semantic-release plugin to create and publish a NuGet package. Step Description verifyConditions Verify the presence of the NUG

Jan 2, 2023
Releases(v1.0.1)
Owner
hiroki osame
I'm on a mission to open source my solutions 🚀
hiroki osame
Micro.publish is an Obsidian plugin to publish notes directly to Micro.blog, written in TypeScript

Micro.publish Micro.publish is a community maintained plugin for Obsidian to publish notes to a Micro.blog blog. Installing This plugin will be availa

Otavio Cordeiro 14 Dec 9, 2022
ScrapedDuck routinely scrapes LeekDuck.com and pushes the found data to a branch on this repository, for use by other external applications.

ScrapedDuck ScrapedDuck routinely scrapes LeekDuck.com (with permission) and pushes the found data to a branch on this repository, for use by other ex

Anthony 19 Dec 19, 2022
🚀 A GitHub action to publish a new release of the repository

Create a JavaScript Action using TypeScript Use this template to bootstrap the creation of a TypeScript action. ?? This template includes compilation

Clicampo 3 Nov 1, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project Those days of manually updating portfolio website after every new project made are gone ⚡ Yesss . . . you read that right. ?? portfo

Gaurav Gulati 15 Aug 3, 2021
This branch is created to make receive and send data to api using async and await methods

Microverse-Leader-Board Project from module 2 week 4 This branch is created to make receive and send data to api using async and await methods Screens

Akshitha Reddy 6 Apr 22, 2022
Ansible template that shows how to create dynamic staging servers with ..com

Vagrant + Ansible + Docker Swarm + Trafeik + NGINX template Template repo that creates virtual machines with Docker, Docker Swarm, Traefik, NGINX. It

Mateusz Bagiński 4 Oct 15, 2022
Automatically sync your leetcode solutions to your github account - top 5 trending GitHub repository

LeetHub - Automatically sync your code to GitHub. Top 5 Trending JavaScript Repositories Available on: What is LeetHub? A chrome extension that automa

Qasim Wani 2.8k Dec 31, 2022
Upload or Upload & Publish your bundle (apk or aab) to Huawei AppGallery with ConnectApi

appgallery-publisher Upload/Publish your bundle (apk or aab) to AppGallery automatically with appgallery-publisher Usage Single Javascript File Bash F

Mustafa Yiğit 17 Sep 19, 2022