How to use the pacote.packument function in pacote

To help you get started, we’ve selected a few pacote examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npm / arborist / test / fixtures / registry-mocks / fetch-lock-contents.js View on Github external
const main = async lock => {
  for (const [loc, meta] of Object.entries(lock.packages)) {
    if (!loc || meta.link || !nm.test(loc))
      continue

    const name = meta.name || loc.replace(nm, '$1')

    console.error('FETCHING', name)

    const paku = await pacote.packument(name)
    const saveTo = resolve(dir, name.replace(/^@/, '') + '.json')
    mkdirp.sync(dirname(saveTo))
    writeFileSync(saveTo, JSON.stringify(paku, 0, 2))
    // bundled deps sometimes don't have a resolved value
    if (!meta.resolved)
      continue
    const path = url.parse(meta.resolved).pathname.replace(/^\/@?/, '')
    const tgzFile = resolve(dir, path)
    await pacote.tarball.file(meta.resolved, tgzFile)
  }
  console.log('OK!')
}
github electrode-io / fyn / lib / pkg-src-manager.js View on Github external
const pacoteRequest = () => {
      return pacote
        .packument(
          pkgName,
          this.getPacoteOpts({
            "full-metadata": true,
            "fetch-retries": 3,
            "cache-policy": "ignore",
            "cache-key": qItem.cacheKey,
            memoize: false
          })
        )
        .tap(x => {
          this._metaStat.inTx--;
          if (x.readme) delete x.readme; // don't need this
          updateItem(x._cached ? "cached" : "200");
        })
        .catch(err => {
github sk770 / npm-offline-packager / lib / fetch-packages.js View on Github external
pacote.manifest(`${packageName}@${packageVersion}`, pacoteOptions)
            .catch((error) => {
                if (error.code === 'ETARGET') {
                    const { latest } = error.distTags;
                    return pacote.manifest(`${packageName}@${latest}`, pacoteOptions);
                }

                if (error.code === 'E404') {
                    console.error(`\nError: "${packageName}@${packageVersion}" not found`);
                    return packageVersion !== 'latest' ? pacote.manifest(packageName, pacoteOptions)
                        : Promise.reject(new Error(`${packageName}@${packageVersion} not found`));
                }

                return Promise.reject(error);
            }),
        packageVersion !== 'latest' ? pacote.packument(packageName, pacoteOptions) : Promise.resolve(),
    ])
        .then(([manifest, packument]) => {
            if (packument) {
                manifest.isLatest = packument['dist-tags'].latest === manifest.version;
            } else {
                manifest.isLatest = true;
            }

            return manifest;
        });
}
github meetalva / alva / packages / analyzer / src / get-package.ts View on Github external
async function getVersion(name: npa.Result): Promise {
	if (name.type === 'version') {
		return name.fetchSpec!;
	}

	const packument = await pacote.packument(name.name);

	if (name.type === 'tag') {
		const version = packument['dist-tags'][name.fetchSpec!];

		if (typeof version !== 'string') {
			throw new Error(`Could not determine version of ${name.name} for tag ${name.fetchSpec}`);
		}

		return version;
	}

	if (name.type === 'range') {
		const versions = Object.keys(packument.versions).sort(semver.compare);
		const spec = typeof name.fetchSpec === 'string' ? name.fetchSpec : 'latest';
		const version = semver.maxSatisfying(versions, spec);
github ES-Community / nsecure / src / depWalker.js View on Github external
async function getExpectedSemVer(range) {
    try {
        const { versions, "dist-tags": { latest } } = await pacote.packument(depName, {
            registry: REGISTRY_DEFAULT_ADDR,
            ...token
        });
        const currVersion = semver.maxSatisfying(Object.keys(versions), range);

        return currVersion === null ? latest : currVersion;
    }
    catch (err) {
        return cleanRange(range);
    }
}
github tjunnone / npm-check-updates / lib / package-managers / npm.js View on Github external
function viewMany(packageName, fields, currentVersion) {
    if (currentVersion && (!semver.validRange(currentVersion) || versionUtil.isWildCard(currentVersion))) {
        return Promise.resolve({});
    }

    npmConfig.fullMetadata = _.includes(fields, 'time');

    return pacote.packument(packageName, npmConfig).then(result =>
        fields.reduce((accum, field) => Object.assign(
            accum,
            {
                [field]: field.startsWith('dist-tags.') ?
                    result.versions[_.get(result, field)] :
                    result[field]
            }
        ), {})
    );
}
github entropic-dev / entropic / registry / lib / cache.js View on Github external
async function packument(spec) {
  return pacote.packument(spec, OPTS);
}
github entropic-dev / entropic / tools / vcpm-sync / main.js View on Github external
async function syncPackage(token, pkg, progress) {
  progress(`${pkg} start`);
  const json = await pacote.packument(pkg);

  const createPackage = await fetch(
    `${REG}/packages/package/legacy@${HOST}/${enc(pkg)}`,
    {
      method: 'PUT',
      body: '{}',
      headers: {
        'content-type': 'application/json',
        authorization: `Bearer ${token}`
      }
    }
  );

  if (createPackage.status > 399) {
    progress(
      `${pkg} saw ${createPackage.status}: ${await createPackage.text()}`

pacote

JavaScript package downloader

ISC
Latest version published 3 months ago

Package Health Score

95 / 100
Full package analysis