UNPKG

install-module-linked

Version:
19 lines (18 loc) 893 B
import { getContent } from 'get-file-compat'; import parseInstallString from './parseInstallString.js'; export default function getSpecifier(installString, callback) { const { name, version } = parseInstallString(installString); if (version) return callback(undefined, installString); // URL-encode the package name (handles scoped packages: @scope/pkg -> @scope%2Fpkg) const encodedName = encodeURIComponent(name).replace(/%40/g, '@'); getContent(`https://registry.npmjs.org/${encodedName}/latest`, 'utf8', (err, res)=>{ if (err) return callback(err); try { var _ref; const json = JSON.parse((_ref = res === null || res === void 0 ? void 0 : res.content) !== null && _ref !== void 0 ? _ref : 'null'); callback(undefined, `${name}@${json.version}`); } catch (err) { callback(err); } }); }