Giter VIP home page Giter VIP logo

nice-package's Introduction

nice-registry [EXPERIMENTAL] ๐Ÿ”ฌ

A stateless proxy server to the npm registry that serves fancied up package metadata.

How it Works

This is what the server does when you fetch a package:

Raw Registry Data

First, the raw package metadata is fetched from registry.npmjs.com. This is the only network request made per package.

Dependents

The dependent-packages module adds dependency info for the package, without making a network request:

  • directDependents
  • directDependentsCount
  • directDevDependents
  • directDevDependentsCount
  • totalDirectDependentsCount

Downloads

The download-counts adds a averageDownloadsPerDay property to the package. This is also added without making a network request/

Owners

The owners and owner-profiles packages are used to create an owners array which includes the following metadata for each npm user, as available:

  • name - full name
  • email - public email address
  • homepage - a URL
  • github - GitHub handle
  • twitter - Twitter handle
  • gravatar - HTTPS gravatar url
  • packageCount - how many packages thes user owns

No network requests are made here either.

Niceties

Lastly, the resulting package object is turned into a [nice package], which has these qualities:

  • uses normalize-package-data as a baseline for cleanup, then:
  • uses the doc['dist-tags'].latest as the baseline for package metadata
  • derives starsCount from the users object
  • derives a versions array from the time object
  • renames _npmUser to lastPublisher, because it's a more intuitive name.
  • renames maintainers to owners, for consistency with the npm's CLI commands.
  • normalizes GitHub repository URLs to https format
  • moves internal bookkeeping properties like _id and _from into an other object that can easily be omitted.

HTTP API

The following routes are supported:

GET /package/:name

Fetches a single package. The following query params are allowed:

Examples:

GET /packages

Fetches multiple packages by name. The following query params are allowed:

  • names (required) - a comma-delimited string of package names to fetch
  • pick - a comma-delimited string of properties to include in the response.
  • omit - a comma-delimited string of properties to omit from the response.

Examples:

Public Server

There's a public instance running on Heroku.

Example URL: http://nice-registry.herokuapp.com/package/cheerio?omit=readme,versions,other,directDependents,

Running Your Own Instance

This server's design follows the 12 Factor development methodology popularized by Heroku. It is stateless: that is, it does not include a database, nor does it write to the filesystem.

Each package request makes just one network call, and that is to fetch the main package data from the npm registry. Supplementary data for download counts, dependents, owner profiles, etc, is provided by offline datasets that are automatically updated and published to npm by bots.

This server can optional cache responses in Redis. If you specify a REDIS_URL in the environment, then it will be used. If you don't, it won't. No configuration required.

Setting up your own instance on Heroku only requires a few commands:

git clone https://github.com/nice-registry/nice-registry
cd nice-registry
heroku create my-nice-registry
heroku addons:add heroku-redis
git push heroku master

Tests

npm install
npm test

License

MIT

nice-package's People

Contributors

abs51295 avatar crookedneighbor avatar easingthemes avatar erulabs avatar feross avatar hemanth avatar pdehaan avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nice-package's Issues

FR: Integrate request.

It be useful to have some like:

const package = require('nice-package')

package(module)
.then(pkg => console.log(JSON.stringify(pkg, null, 2))
.catch(err => console.err(`No such module: ${module}`)

instead of

const got = require('got')
const Package = require('nice-package')

got('https://registry.npmjs.com/express', {json:true})
  .then(function(doc) {
    var pkg = new Package(doc)
    console.log(JSON.stringify(pkg, null, 2))
  })

โ“

If yes, I am happy to do a PR @zeke.

Use `normalize-package-data` instead of `normalize-registry-metadata`

I don't know what's going on, but

nice-package uses normalize-package-data as a starter, then does even more package cleanup:

Is straight up not true. normalize-package-data isn't used anywhere. It's not a dependency of normalize-registry-metadata either.

(and I'm a little miffed atm because nice-package threw the author field into other, when normalize-package-data says it neatly parses the author field into an object with name, email, and url, and I had assumed based on the readme that nice-package was a superset of normalize-package-data)

versions metadata field should always be an array

When a package has an empty string ('') as its description, the } else if (doc.name && doc.description) { check fails, because empty strings are falsey.

} else if (doc.name && doc.description) {

This means that data from the npm registry is returned uncleaned. In particular, the behavior that caused me to notice this is a package where the versions field was returned as an object instead of an array like all the other packages.

nice-package assumes everything is a GitHub repo

... which is a fair assumption, but I'm seeing some cases in my ๐Ÿ’ฉ๐Ÿ”ฅ https://github.com/pdehaan/npm-today repo where recently published modules may be gitlab or bitbucket or other random Git repos (or just random garbage).

Not sure if it's worth fixing, but a bit inconvenient when a user specifies a valid repo URL and after normalizing it through nice-package, it comes back null.

Example:

const fetchNicePackage = require('fetch-nice-package');

fetchNicePackage('conventional-gitlab-releaser')
  .then(({name, version, repository}) => ({name, version, repository}))
  .then(pkg => JSON.stringify(pkg, null, 2))
  .then(output => console.log(output))
  .catch(err => console.error(err));

Output:

{
  "name": "conventional-gitlab-releaser",
  "version": "1.0.14",
  "repository": null
}

Yet, it we look at http://npm.im/conventional-gitlab-releaser we can see npm sees the repository, and the package.json specifies a valid value at https://gitlab.com/hutson/conventional-gitlab-releaser/blob/master/package.json#L37-40

  "name": "conventional-gitlab-releaser",
  "repository": {
    "type": "git",
    "url": "https://gitlab.com/hutson/conventional-gitlab-releaser.git"
  },

Not sure if there is an easy way to have it return the original package.json repository.url (if there was one), if the parser wasn't able to parse the repository -- although that means that you'd potentially be getting back different keys depending on what repository people used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.