Skip to content

Instantly share code, notes, and snippets.

@justjake
Created December 9, 2015 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justjake/f1ceeeaf30fee9fe23a4 to your computer and use it in GitHub Desktop.
Save justjake/f1ceeeaf30fee9fe23a4 to your computer and use it in GitHub Desktop.
find bad packages in sinopia

Wat

I noticed a bunch of packages triggering [this npm@3 issue] because our Sinopia instance cached a number of packages. I wrote this script to find the bad packages on our server.

Usage

  1. npm install
  2. change the dataDir variable on line 3 of index.js to point to your Sinopia data directory
  3. run node ./index.js | grep BAD to list the bad packages
  4. rm -r those packages
require('shelljs/global');
var semver = require('semver');
var dataDir = '/srv/sinopia/data';
cd(dataDir);
ls('*').forEach(function(filename) {
var registry = filename + '/' + 'package.json';
echo('inspecting ' + registry);
var data = JSON.parse(cat(registry));
var versions = Object.keys(data.versions);
echo('there are ' + versions.length + ' versions');
var good = true;
versions.forEach(function(version) {
try {
good = good && semver.valid(version);
} catch (err) {
good = false;
}
});
if (!good) {
echo('BAD ' + filename);
}
});
{
"name": "find-bad-sinopia-package-caches",
"version": "1.0.0",
"description": "find bad sinopia package caches",
"main": "index.js",
"dependencies": {
"semver": "^5.1.0",
"shelljs": "^0.5.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment