Skip to content

Commit 71d5e0a

Browse files
committed
fix(refactor): use output.buffer for pack
1 parent e420d75 commit 71d5e0a

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

lib/commands/pack.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ class Pack extends BaseCommand {
5353
prefix: this.npm.localPrefix,
5454
workspaces: this.workspacePaths,
5555
})
56-
const pkgContents = await getContents(manifest, tarballData)
57-
tarballs.push(pkgContents)
56+
tarballs.push(await getContents(manifest, tarballData))
5857
}
5958

60-
// XXX(BREAKING_CHANGE): publish outputs a json object with package
61-
// names as keys. Pack should do the same here instead of an array
62-
if (json) {
63-
output.standard(JSON.stringify(tarballs, null, 2))
64-
return
65-
}
66-
67-
for (const tar of tarballs) {
68-
logTar(tar, { unicode })
69-
output.standard(tar.filename.replace(/^@/, '').replace(/\//, '-'))
59+
for (const [index, tar] of Object.entries(tarballs)) {
60+
// XXX(BREAKING_CHANGE): publish outputs a json object with package
61+
// names as keys. Pack should do the same here instead of an array
62+
logTar(tar, { unicode, json, key: index })
63+
if (!json) {
64+
output.standard(tar.filename.replace(/^@/, '').replace(/\//, '-'))
65+
}
7066
}
7167
}
7268

@@ -82,7 +78,7 @@ class Pack extends BaseCommand {
8278
}
8379

8480
await this.setWorkspaces()
85-
return this.exec([...this.workspacePaths, ...args.filter(a => a !== '.')])
81+
return this.exec([...this.workspacePaths, ...args])
8682
}
8783
}
8884

lib/commands/publish.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,13 @@ class Publish extends BaseCommand {
104104
workspaces: this.workspacePaths,
105105
})
106106
const pkgContents = await getContents(manifest, tarballData)
107+
logTar(pkgContents, { unicode, json, key: workspace })
107108

108109
// The purpose of re-reading the manifest is in case it changed,
109110
// so that we send the latest and greatest thing to the registry
110111
// note that publishConfig might have changed as well!
111112
manifest = await this.#getManifest(spec, opts, true)
112113

113-
if (json) {
114-
output.buffer(workspace ? { [workspace]: pkgContents } : pkgContents)
115-
} else {
116-
logTar(pkgContents, { unicode })
117-
}
118-
119114
const resolved = npa.resolve(manifest.name, manifest.version)
120115

121116
// make sure tag is valid, this will throw if invalid

lib/utils/tar.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
const tar = require('tar')
22
const ssri = require('ssri')
3-
const { log } = require('proc-log')
3+
const { log, output } = require('proc-log')
44
const formatBytes = require('./format-bytes.js')
55
const localeCompare = require('@isaacs/string-locale-compare')('en', {
66
sensitivity: 'case',
77
numeric: true,
88
})
99

10-
const logTar = (tarball, opts = {}) => {
11-
const { unicode = false } = opts
10+
const logTar = (tarball, { unicode = false, json, key } = {}) => {
11+
if (json) {
12+
output.buffer(key == null ? tarball : { [key]: tarball })
13+
return
14+
}
1215
log.notice('')
1316
log.notice('', `${unicode ? '📦 ' : 'package:'} ${tarball.name}@${tarball.version}`)
1417
log.notice('Tarball Contents')

0 commit comments

Comments
 (0)