PHP 8.2.30
Preview: pack.js Size: 2.69 KB
/proc/self/root/proc/self/root/opt/alt/alt-nodejs24/root/usr/lib/node_modules/npm/lib/commands/pack.js

const pacote = require('pacote')
const libpack = require('libnpmpack')
const npa = require('npm-package-arg')
const { log, output } = require('proc-log')
const { getContents, logTar } = require('../utils/tar.js')
const BaseCommand = require('../base-cmd.js')

class Pack extends BaseCommand {
  static description = 'Create a tarball from a package'
  static name = 'pack'
  static params = [
    'dry-run',
    'json',
    'pack-destination',
    'workspace',
    'workspaces',
    'include-workspace-root',
    'ignore-scripts',
  ]

  static usage = ['<package-spec>']
  static workspaces = true
  static ignoreImplicitWorkspace = false

  async exec (args) {
    if (args.length === 0) {
      args = ['.']
    }

    const unicode = this.npm.config.get('unicode')
    const json = this.npm.config.get('json')

    const Arborist = require('@npmcli/arborist')
    // Get the manifests and filenames first so we can bail early on manifest
    // errors before making any tarballs
    const manifests = []
    for (const arg of args) {
      const spec = npa(arg)
      const manifest = await pacote.manifest(spec, { ...this.npm.flatOptions, Arborist })
      if (!manifest._id) {
        throw new Error('Invalid package, must have name and version')
      }
      manifests.push({ arg, manifest })
    }

    // Load tarball names up for printing afterward to isolate from the
    // noise generated during packing
    const tarballs = []
    for (const { arg, manifest } of manifests) {
      const tarballData = await libpack(arg, {
        ...this.npm.flatOptions,
        foregroundScripts: this.npm.config.isDefault('foreground-scripts')
          ? true
          : this.npm.config.get('foreground-scripts'),
        prefix: this.npm.localPrefix,
        workspaces: this.workspacePaths,
      })
      tarballs.push(await getContents(manifest, tarballData))
    }

    for (const [index, tar] of Object.entries(tarballs)) {
      // XXX(BREAKING_CHANGE): publish outputs a json object with package
      // names as keys. Pack should do the same here instead of an array
      logTar(tar, { unicode, json, key: index })
      if (!json) {
        output.standard(tar.filename.replace(/^@/, '').replace(/\//, '-'))
      }
    }
  }

  async execWorkspaces (args) {
    // If they either ask for nothing, or explicitly include '.' in the args,
    // we effectively translate that into each workspace requested

    const useWorkspaces = args.length === 0 || args.includes('.')

    if (!useWorkspaces) {
      log.warn('Ignoring workspaces for specified package(s)')
      return this.exec(args)
    }

    await this.setWorkspaces()
    return this.exec([...this.workspacePaths, ...args.filter(a => a !== '.')])
  }
}

module.exports = Pack

Directory Contents

Dirs: 0 × Files: 67

Name Size Perms Modified Actions
6.17 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.29 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.14 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
847 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
11.48 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
4.22 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
8.90 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
10.99 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.41 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
2.43 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
7.98 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.52 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
449 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
10.06 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.76 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.42 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.57 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
2.16 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
634 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
6.46 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
577 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.53 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.67 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
7.07 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
373 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
370 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.10 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.25 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
234 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.29 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.42 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
16.80 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.98 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
7.95 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.85 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
2.69 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
873 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.60 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
309 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
10.45 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
799 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
9.50 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.51 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
2.19 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.24 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
303 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
295 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
6.27 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
4.42 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.83 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
671 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
2.65 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.88 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.03 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
293 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
288 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
4.36 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
288 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.92 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
302 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.52 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
5.38 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
183 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download
1.74 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
3.50 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
13.54 KB lrw-r--r-- 2026-02-23 07:38:41
Edit Download
527 B lrw-r--r-- 2026-02-23 07:38:41
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).