Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pdehaan opened this issue Sep 5, 2016 · 1 comment
Open

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

pdehaan opened this issue Sep 5, 2016 · 1 comment

Comments

@pdehaan
Copy link

pdehaan commented Sep 5, 2016

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: '[email protected]' } ],
  _npmUser: { name: 'testx5', email: '[email protected]' } }

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

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

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

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). 🤷

@zeke
Copy link
Member

zeke commented Sep 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants