documentalist icon indicating copy to clipboard operation
documentalist copied to clipboard

Consider using libnpm instead of spawning npm process

Open betalb opened this issue 5 years ago • 0 comments

Consider using libnpm instead of spawning npm process in npm plugin

Every piece of information that is currently used by npm plugin can be acquired through libnpm without using npm cli directly.

versions property is sorted by npm cli view command (https://github.com/npm/cli/blob/656bce7dd0f9753a273912e803261ed246593924/lib/view.js#L50)

const packument = require('libnpm/packument');
const semver = require('semver');

packument('libnpm', {
    fullMetadata: true
}).then((data) => {
    const distTags = data["dist-tags"] || {};
    console.log({
        name: data.name,
        description: data.description,
        latestVersion: distTags.latest,
        nextVersion: distTags.next,
        versions: Object.keys(data.versions).sort(semver.compareLoose),
    });
});

betalb avatar Apr 04 '19 09:04 betalb