aboutsummaryrefslogtreecommitdiff
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.js33
1 files changed, 15 insertions, 18 deletions
diff --git a/deps/npm/lib/pack.js b/deps/npm/lib/pack.js
index 93c21ad559..3b3f5b7bbc 100644
--- a/deps/npm/lib/pack.js
+++ b/deps/npm/lib/pack.js
@@ -32,7 +32,7 @@ const tar = require('tar')
const packlist = require('npm-packlist')
const ssri = require('ssri')
-pack.usage = 'npm pack [[<@scope>/]<pkg>...]'
+pack.usage = 'npm pack [[<@scope>/]<pkg>...] [--dry-run]'
// if it can be installed, it can be packed.
pack.completion = install.completion
@@ -68,22 +68,13 @@ function pack_ (pkg, dir) {
: mani.name
const target = `${name}-${mani.version}.tgz`
return pinflight(target, () => {
+ const dryRun = npm.config.get('dry-run')
if (mani._requested.type === 'directory') {
- return cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'packing'}, (tmp) => {
- const tmpTarget = path.join(tmp, path.basename(target))
- return prepareDirectory(mani._resolved)
- .then(() => {
- return packDirectory(mani, mani._resolved, tmpTarget, target, true)
- })
- .tap(() => {
- if (npm.config.get('dry-run')) {
- log.verbose('pack', '--dry-run mode enabled. Skipping write.')
- } else {
- return move(tmpTarget, target, {Promise: BB, fs})
- }
- })
- })
- } else if (npm.config.get('dry-run')) {
+ return prepareDirectory(mani._resolved)
+ .then(() => {
+ return packDirectory(mani, mani._resolved, target, target, true, dryRun)
+ })
+ } else if (dryRun) {
log.verbose('pack', '--dry-run mode enabled. Skipping write.')
return cacache.tmp.withTmp(npm.tmp, {tmpPrefix: 'packing'}, (tmp) => {
const tmpTarget = path.join(tmp, path.basename(target))
@@ -137,7 +128,7 @@ function prepareDirectory (dir) {
}
module.exports.packDirectory = packDirectory
-function packDirectory (mani, dir, target, filename, logIt) {
+function packDirectory (mani, dir, target, filename, logIt, dryRun) {
deprCheck(mani)
return readJson(path.join(dir, 'package.json')).then((pkg) => {
return lifecycle(pkg, 'prepack', dir)
@@ -165,7 +156,13 @@ function packDirectory (mani, dir, target, filename, logIt) {
.then((files) => tar.create(tarOpt, files.map((f) => `./${f}`)))
.then(() => getContents(pkg, tmpTarget, filename, logIt))
// thread the content info through
- .tap(() => move(tmpTarget, target, {Promise: BB, fs}))
+ .tap(() => {
+ if (dryRun) {
+ log.verbose('pack', '--dry-run mode enabled. Skipping write.')
+ } else {
+ return move(tmpTarget, target, {Promise: BB, fs})
+ }
+ })
.tap(() => lifecycle(pkg, 'postpack', dir))
})
})