lib/finalize-manifest.js
function tarballedProps (pkg, spec, opts) {
  const needsShrinkwrap = (!pkg || (
    pkg._hasShrinkwrap !== false &&
    !pkg._shrinkwrap
  ))
  const needsBin = !!(!pkg || (
    !pkg.bin &&
    pkg.directories &&
    pkg.directories.bin
  ))
  const needsIntegrity = !pkg || (!pkg._integrity && pkg._integrity !== false)
  const needsShasum = !pkg || (!pkg._shasum && pkg._shasum !== false)
  const needsHash = needsIntegrity || needsShasum
  const needsManifest = !pkg || !pkg.name
  const needsExtract = needsShrinkwrap || needsBin || needsManifest
  if (!needsShrinkwrap && !needsBin && !needsHash && !needsManifest) {
    return BB.resolve({})
  } else {
    opts = optCheck(opts)
    const tarStream = fetchFromManifest(pkg, spec, opts)
    const extracted = needsExtract && new tar.Parse()
    return BB.join(
      needsShrinkwrap && jsonFromStream('npm-shrinkwrap.json', extracted),
      needsManifest && jsonFromStream('package.json', extracted),
      needsBin && getPaths(extracted),
      needsHash && ssri.fromStream(tarStream, { algorithms: ['sha1', 'sha512'] }),
      needsExtract && pipe(tarStream, extracted),
      (sr, mani, paths, hash) => {
        if (needsManifest && !mani) {
          const err = new Error(`Non-registry package missing package.json: ${spec}.`)
          err.code = 'ENOPACKAGEJSON'
          throw err
        }
        const extraProps = mani || {}
        delete extraProps._resolved
        // drain out the rest of the tarball
        tarStream.resume()
        // if we have directories.bin, we need to collect any matching files
        // to add to bin
        if (paths && paths.length) {
          const dirBin = mani
            ? (mani && mani.directories && mani.directories.bin)
            : (pkg && pkg.directories && pkg.directories.bin)
          if (dirBin) {
            extraProps.bin = {}
            paths.forEach(filePath => {
              if (minimatch(filePath, dirBin + '/**')) {
                const relative = path.relative(dirBin, filePath)
                if (relative && relative[0] !== '.') {
                  extraProps.bin[path.basename(relative)] = path.join(dirBin, relative)
                }
              }
            })
          }
        }
        return Object.assign(extraProps, {
          _shrinkwrap: sr,
          _resolved: (mani && mani._resolved) ||
          (pkg && pkg._resolved) ||
          spec.fetchSpec,
          _integrity: needsIntegrity && hash && hash.sha512 && hash.sha512[0].toString(),
          _shasum: needsShasum && hash && hash.sha1 && hash.sha1[0].hexDigest()
        })
      }
    )
  }
}
function tarballedProps (pkg, spec, opts) {
  const needsShrinkwrap = (!pkg || (
    pkg._hasShrinkwrap !== false &&
    !pkg._shrinkwrap
  ))
  const needsBin = !!(!pkg || (
    !pkg.bin &&
    pkg.directories &&
    pkg.directories.bin
  ))
  const needsIntegrity = !pkg || (!pkg._integrity && pkg._integrity !== false)
  const needsShasum = !pkg || (!pkg._shasum && pkg._shasum !== false)
  const needsHash = needsIntegrity || needsShasum
  const needsManifest = !pkg || !pkg.name
  const needsExtract = needsShrinkwrap || needsBin || needsManifest
  if (!needsShrinkwrap && !needsBin && !needsHash && !needsManifest) {
    return BB.resolve({})
  } else {
    opts = optCheck(opts)
    const tarStream = fetchFromManifest(pkg, spec, opts)
    const extracted = needsExtract && new tar.Parse()
    return BB.join(
      needsShrinkwrap && jsonFromStream('npm-shrinkwrap.json', extracted),
      needsManifest && jsonFromStream('package.json', extracted),
      needsBin && getPaths(extracted),
      needsHash && ssri.fromStream(tarStream, { algorithms: ['sha1', 'sha512'] }),
      needsExtract && pipe(tarStream, extracted),
      (sr, mani, paths, hash) => {
        if (needsManifest && !mani) {
          const err = new Error(`Non-registry package missing package.json: ${spec}.`)
          err.code = 'ENOPACKAGEJSON'
          throw err
        }
        const extraProps = mani || {}
        delete extraProps._resolved
        // drain out the rest of the tarball
        tarStream.resume()
        // if we have directories.bin, we need to collect any matching files
        // to add to bin
        if (paths && paths.length) {
          const dirBin = mani
            ? (mani && mani.directories && mani.directories.bin)
            : (pkg && pkg.directories && pkg.directories.bin)
          if (dirBin) {
            extraProps.bin = {}
            paths.forEach(filePath => {
              if (minimatch(filePath, dirBin + '/**')) {
                const relative = path.relative(dirBin, filePath)
                if (relative && relative[0] !== '.') {
                  extraProps.bin[path.basename(relative)] = path.join(dirBin, relative)
                }
              }
            })
          }
        }
        return Object.assign(extraProps, {
          _shrinkwrap: sr,
          _resolved: (mani && mani._resolved) ||
          (pkg && pkg._resolved) ||
          spec.fetchSpec,
          _integrity: needsIntegrity && hash && hash.sha512 && hash.sha512[0].toString(),
          _shasum: needsShasum && hash && hash.sha1 && hash.sha1[0].hexDigest()
        })
      }
    )
  }
}
function tarballedProps ( pkg , spec , opts ) { const needsShrinkwrap = ( ! pkg || ( pkg . _hasShrinkwrap !== false && ! pkg . _shrinkwrap ) ) const needsBin = ! ! ( ! pkg || ( ! pkg . bin && pkg . directories && pkg . directories . bin ) ) const needsIntegrity = ! pkg || ( ! pkg . _integrity && pkg . _integrity !== false ) const needsShasum = ! pkg || ( ! pkg . _shasum && pkg . _shasum !== false ) const needsHash = needsIntegrity || needsShasum const needsManifest = ! pkg || ! pkg . name const needsExtract = needsShrinkwrap || needsBin || needsManifest if ( ! needsShrinkwrap && ! needsBin && ! needsHash && ! needsManifest ) { return BB . resolve ( { } ) } else { opts = optCheck ( opts ) const tarStream = fetchFromManifest ( pkg , spec , opts ) const extracted = needsExtract && new tar . Parse ( ) return BB . join ( needsShrinkwrap && jsonFromStream ( 'npm-shrinkwrap.json' , extracted ) , needsManifest && jsonFromStream ( 'package.json' , extracted ) , needsBin && getPaths ( extracted ) , needsHash && ssri . fromStream ( tarStream , { algorithms : [ 'sha1' , 'sha512' ] } ) , needsExtract && pipe ( tarStream , extracted ) , ( sr , mani , paths , hash ) => { if ( needsManifest && ! mani ) { const err = new Error ( ` ${ spec } ` ) err . code = 'ENOPACKAGEJSON' throw err } const extraProps = mani || { } delete extraProps . _resolved // drain out the rest of the tarball tarStream . resume ( ) // if we have directories.bin, we need to collect any matching files // to add to bin if ( paths && paths . length ) { const dirBin = mani ? ( mani && mani . directories && mani . directories . bin ) : ( pkg && pkg . directories && pkg . directories . bin ) if ( dirBin ) { extraProps . bin = { } paths . forEach ( filePath => { if ( minimatch ( filePath , dirBin + '/**' ) ) { const relative = path . relative ( dirBin , filePath ) if ( relative && relative [ 0 ] !== '.' ) { extraProps . bin [ path . basename ( relative ) ] = path . join ( dirBin , relative ) } } } ) } } return Object . assign ( extraProps , { _shrinkwrap : sr , _resolved : ( mani && mani . _resolved ) || ( pkg && pkg . _resolved ) || spec . fetchSpec , _integrity : needsIntegrity && hash && hash . sha512 && hash . sha512 [ 0 ] . toString ( ) , _shasum : needsShasum && hash && hash . sha1 && hash . sha1 [ 0 ] . hexDigest ( ) } ) } ) } }
Some things aren't filled in by standard manifest fetching. If this function needs to do its work, it will grab the package tarball, extract it, and take whatever it needs from the stream.
Some things aren t filled in by standard manifest fetching . If this function needs to do its work it will grab the package tarball extract it and take whatever it needs from the stream .