Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fetch-package.js « registry-mocks « fixtures « test « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 41ac5e9e9c167834f9e61ea019416d8135ae0bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// fetch a single package's packument, corgi, and specific tarball
const { resolve } = require('path')
const { writeFileSync } = require('fs')
const pacote = require('pacote')
const npa = require('npm-package-arg')

const dir = resolve(__dirname, 'content')

const main = async (raw) => {
  const spec = npa(raw)

  const packument = await pacote.packument(spec.name, { fullMetadata: true })
  const packumentFile = resolve(dir, spec.name.replace(/^@/, '') + '.json') 
  writeFileSync(packumentFile, JSON.stringify(packument, 0, 2))

  const corgi = await pacote.packument(spec.name, {})
  const corgiFile = resolve(dir, spec.name.replace(/^@/, '') + '.min.json')
  writeFileSync(corgiFile, JSON.stringify(corgi, 0, 2))

  if (spec.type === 'version') {
    const tarballUrl = packument.versions[spec.fetchSpec].dist.tarball
    const path = new URL(tarballUrl).pathname.replace(/^\/@?/, '')
    const tarballFile = resolve(dir, path)
    await pacote.tarball.file(tarballUrl, tarballFile)
  }
}

main(process.argv[2])