documentalist
documentalist copied to clipboard
Consider using libnpm instead of spawning npm process
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),
});
});