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

publish-to-git

v1.1.9

Published

Publish private npm packages to Git repositories with npm publish semantics

Downloads

2,113

Readme

publish-to-git

Publish private npm packages to Git repositories with npm publish semantics (uses same files as npm publish)

Default behavior takes the version from package.json, runs npm pack and then pushes the contents to an orphan tag v<VERSION> (for example v1.0.0). It's similar to how gh-pages works.

Such tags can be easily referenced to in package.json. It provides proper versioning to private Git npm packages along with an easy publish path that's compatible with npm.

Installation

npm install --save-dev publish-to-git

Requirements: node > 8.0.0 and git command being in the PATH.

Consumption of private Git NPM packages

For Github

"some-package": "reponame/repo#v1.0.0",
"some-package-with-semver": "reponame/repo#semver:^v1.0.0",

For Gitlab or BitBucket (use bitbucket:)

"some-package": "gitlab:reponame/repo#v1.0.0",
"some-package-with-semver": "gitlab:reponame/repo#semver:^v1.0.0",

For some other Git repo:

"some-package": "git+ssh://[email protected]:somerepo#v1.0.0",
"some-package-with-semver": "git+ssh://[email protected]:somerepo#semver:^v1.0.0",

Note: Installing from Github/Gitlab/Bitbucket seems to be more efficient due to the way it conditionally turns on shallow clone.

Usage

In package.json

"scripts": {
  "publish": "publish-to-git"
}

or run with npx:

# npx publish-to-git

See also a few options which may assist in your particular use case:

Options:
  --help     Show help [boolean]
  --version  Show version number [boolean]
  --remote   Git remote, may be remote name or full URL to the repo [default: "origin"]
  --tag      Tag name to which src will be published, for example: v1.2.3 - by default uses version from package.json
  --push     Push update to the git remote (pass --no-push to disable) [boolean] [default: "true"]
  --force    Override any existing tag on the remote as well as locally (git tag -f, git push -f) [boolean]

Examples:
  publish-to-git --tag v2.1.3 --no-push     # by default version from package.json is used
  publish-to-git --remote https://USER:[email protected]/USER/REPO
  publish-to-git --force    # useful in CI and when we want to override the same tag which triggered the build

Programmatic usage

const { publish } = require('publish-to-git');

const options = {
  tag: 'v1.0.0', // you can also provide version: '1.0.0' instead of tag
  push: { // set to false to not push
    remote: 'origin', // set to URL or remote name
    force: false, // set to true to force push
  }
};

publish(options).then(() => {
  console.log('Done');
});

Please see https://github.com/Rush/publish-to-git/blob/master/main.js for reference

Usage in Drone CI

This example assumes that the developer pushes a tag that's identical to the version in package json. CI will complete the build and override tag contents. If you find this approach ugly, you could push tags in form of build-v1.0.0 and then have publish-to-git publish using default options.

pipeline:
  # other pipelines here, like build etc.
  publish-to-git:
    commands:
      - git config --global user.email "admin@drone" # git will complain if these are not set
      - git config --global user.name "Drone CI"
      - npx publish-to-git --force # this will override existing tag with npm package contents
    when:
      event: tag

Quick note on semver with https

Older versions of npm prior to 6.0 had a bug with supporting semver git packages. It's no longer a problem since npm 6.0.

For automated publishing to Github ~/.netc and npm/git will automatically pick it up:

machine github.com
login <GITHUB_TOKEN>
password=x-oauth-basic

License

MIT