summaryrefslogtreecommitdiff
path: root/deps/npm/lib/pack.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/pack.js')
-rw-r--r--deps/npm/lib/pack.js63
1 files changed, 35 insertions, 28 deletions
diff --git a/deps/npm/lib/pack.js b/deps/npm/lib/pack.js
index ff906cc2bd..cf1e77f48e 100644
--- a/deps/npm/lib/pack.js
+++ b/deps/npm/lib/pack.js
@@ -4,46 +4,53 @@ const pacote = require('pacote')
const libpack = require('libnpmpack')
const npa = require('npm-package-arg')
-const npm = require('./npm.js')
const { getContents, logTar } = require('./utils/tar.js')
const writeFile = util.promisify(require('fs').writeFile)
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
-const usage = usageUtil('pack', 'npm pack [[<@scope>/]<pkg>...] [--dry-run]')
-const cmd = (args, cb) => pack(args).then(() => cb()).catch(cb)
+class Pack {
+ constructor (npm) {
+ this.npm = npm
+ }
-const pack = async (args) => {
- if (args.length === 0)
- args = ['.']
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ get usage () {
+ return usageUtil('pack', 'npm pack [[<@scope>/]<pkg>...] [--dry-run]')
+ }
- const { unicode } = npm.flatOptions
+ exec (args, cb) {
+ this.pack(args).then(() => cb()).catch(cb)
+ }
- // clone the opts because pacote mutates it with resolved/integrity
- const tarballs = await Promise.all(args.map((arg) =>
- pack_(arg, { ...npm.flatOptions })))
+ async pack (args) {
+ if (args.length === 0)
+ args = ['.']
- for (const tar of tarballs) {
- logTar(tar, { log, unicode })
- output(tar.filename.replace(/^@/, '').replace(/\//, '-'))
- }
-}
+ const { unicode } = this.npm.flatOptions
-const pack_ = async (arg, opts) => {
- const spec = npa(arg)
- const { dryRun } = opts
- const manifest = await pacote.manifest(spec, opts)
- const filename = `${manifest.name}-${manifest.version}.tgz`
- .replace(/^@/, '').replace(/\//, '-')
- const tarballData = await libpack(arg, opts)
- const pkgContents = await getContents(manifest, tarballData)
+ // clone the opts because pacote mutates it with resolved/integrity
+ const tarballs = await Promise.all(args.map(async (arg) => {
+ const spec = npa(arg)
+ const { dryRun } = this.npm.flatOptions
+ const manifest = await pacote.manifest(spec, this.npm.flatOptions)
+ const filename = `${manifest.name}-${manifest.version}.tgz`
+ .replace(/^@/, '').replace(/\//, '-')
+ const tarballData = await libpack(arg, this.npm.flatOptions)
+ const pkgContents = await getContents(manifest, tarballData)
- if (!dryRun)
- await writeFile(filename, tarballData)
+ if (!dryRun)
+ await writeFile(filename, tarballData)
- return pkgContents
-}
+ return pkgContents
+ }))
-module.exports = Object.assign(cmd, { usage })
+ for (const tar of tarballs) {
+ logTar(tar, { log, unicode })
+ output(tar.filename.replace(/^@/, '').replace(/\//, '-'))
+ }
+ }
+}
+module.exports = Pack