npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-publish

v2.0.0

Published

Publish your npm package to a GitHub repository branch

Downloads

57

Readme

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?

To test a package without publishing to npm.

Why not use npm publish to make a pre-release?

Because of the following drawbacks:

  • Versioning concerns: even though you're just testing, you still need to version bump
  • Undeleteable: releases are hard to remove due to npm's strict unpublish policy
  • Unverifyable: npm does not offer a great way to browse the contents of a package
  • Risky: Publishing tests to a production environment can be dangerous (eg. accidentally publish as stable)

What about npm link?

So why git-publish?

  • No versions: 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 easily 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

This command will publish to the remote branch npm/<current branch>.

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) | | -o, --fresh | Publish without a commit history. Warning: Force-pushes to remote | | -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?

Like npm publish, you can 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 only the npm publish files
  4. 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'