nice-registry / all-the-packages

:package: All the npm registry metadata as an offline event stream. [DEPRECATED]
https://github.com/nice-registry/all-the-packages/issues/2
24 stars 14 forks source link

A few invalid "test" packages in the registry #1

Open pdehaan opened 8 years ago

pdehaan commented 8 years ago

Not sure if valid bug, or if it's your job to be the package sheriff, but I got a couple errors due to my garbage coding, because it turns out now all packages in the npm registry have a name (go figure).

Steps to reproduce:

const registry = require('all-the-packages');

filterByName(/^eslint-plugin-/i)
  .then((packages) => console.log(packages.length))
  .catch(err => console.error(err));

function filterByName(name) {
  return new Promise((resolve) => {
    const packages = [];
    registry.on('package', (pkg) => {
      if (pkg.name && pkg.name.match(name)) {
        packages.push(pkg);
      }
      if (!pkg.name) {
        console.log("DEBUG:", pkg);
      }
    }).on('end', () => resolve(packages));
  });
}

Output:

$ time node index

DEBUG: { dist: { tarball: 'http://registry.npmjs.org/testx2/-/a' },
  maintainers: [ { name: 'testx5', email: 'abcde@example.com' } ],
  _npmUser: { name: 'testx5', email: 'abcde@example.com' } }

DEBUG: { dist: { tarball: 'http://registry.npmjs.org/zachtestproject2/-/test.tgz' },
  maintainers: [ { name: 'zlrenner', email: 'zlrenner@outlook.com' } ],
  _npmUser: { name: 'zlrenner', email: 'zlrenner@outlook.com' } }

DEBUG: { dist:
   { tarball: 'http://registry.npmjs.org/zachtestproject3/-/test.tgz',
     _from: 'http://zachrenner.com/test.tgz' },
  maintainers: [ { name: 'zlrenner', email: 'zlrenner@outlook.com' } ],
  _npmUser: { name: 'zlrenner', email: 'zlrenner@outlook.com' } }

DEBUG: { dist:
   { tarball: 'http://registry.npmjs.org/zachtestproject4/-/test.tgz',
     _from: 'http://zachrenner.com/test.tgz',
     _shasum: 'asd' },
  maintainers: [ { name: 'zlrenner', email: 'zlrenner@outlook.com' } ],
  _npmUser: { name: 'zlrenner', email: 'zlrenner@outlook.com' } }

346

# node index  51.87s user 1.22s system 100% cpu 52.707 total

Anyways, not sure if you want to emit the package event only if the pkg.value in question passes some basic schema (ie: has a name and version property). :shrug:

zeke commented 8 years ago

nice-package has some validation in place for this:

http://github.com/zeke/nice-package/blob/d5635bc04dce9b28409c7aba77ad614e2453dcc3/index.js#L42-L49

And here's the schema it uses:

properties: {
  name: {
    type: 'string',
    required: true
  },
  description: {
    type: 'string',
    required: true
  }
}

Note that this is different from the official npm notion of a valid package, which I think just requires name and version.

See also package-stream, another thing I made for accessing all the packages in the registry.

I'm open to ideas about when and how to (in)validate packages in all-the-packages, if at all.