Skip to content

Commit

Permalink
Detect unpublished packages (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub authored and sholladay committed Jul 22, 2019
1 parent 50dfb78 commit 142c229
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const fetchMeta = require('package-json');
const getPackage = require('./lib/get-package');
const recentPublish = require('./lib/recent-publish');
const significantDownloads = require('./lib/significant-downloads');
const unpublished = require('./lib/unpublished');
const hasReadme = require('./lib/has-readme');
const hasBinaryOrDependent = require('./lib/has-binary-or-dependent');
const hasProdVersion = require('./lib/has-prod-version');
Expand Down Expand Up @@ -39,6 +40,11 @@ const squatter = async (name, version = 'latest') => {
allVersions : true,
fullMetadata : true
});

if (unpublished(meta)) {
return false;
}

const pkg = getPackage(meta, version);

const isExempt = await pOne(exemptions, (test) => {
Expand Down
7 changes: 7 additions & 0 deletions lib/unpublished.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const unpublished = (meta) => {
return Boolean(!meta['dist-tags'] && meta.time && meta.time.unpublished);
};

module.exports = unpublished;
15 changes: 14 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import recentPublish from './lib/recent-publish';
import significantDownloads from './lib/significant-downloads';
import unpublished from './lib/unpublished';
import hasReadme from './lib/has-readme';
import hasBinaryOrDependent from './lib/has-binary-or-dependent';
import hasProdVersion from './lib/has-prod-version';
Expand Down Expand Up @@ -29,7 +30,8 @@ test('squatter() correctly identifies non-squatters', async (t) => {
'delivr',
'semver',
'got',
'ava'
'ava',
'leopard'
];
await Promise.all(nonSquatters.map(async (pkgName) => {
t.false(await squatter(pkgName), `${pkgName} must not be a squatter`);
Expand Down Expand Up @@ -190,3 +192,14 @@ test('hasExtraMaintainer() looks for multiple maintainers', (t) => {
]
}));
});

test('unpublished() looks for missing dist-tags and an unpublished time', (t) => {
t.false(unpublished({}));
t.false(unpublished({ time : { created : '2018' } }));
t.false(unpublished({
'dist-tags' : {},
time : { unpublished : '2011' }
}));

t.true(unpublished({ time : { unpublished : '2011' } }));
});

0 comments on commit 142c229

Please sign in to comment.