Skip to content

Commit

Permalink
pack: set correct filename for scoped packages
Browse files Browse the repository at this point in the history
This should probably be done in libnpmpack.  Can be removed
from here when it is.
  • Loading branch information
isaacs committed Aug 5, 2020
1 parent 2c305e8 commit 0808328
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const pack = async (args) => {

for (const tar of tarballs) {
logTar(tar, { log, unicode })
output(tar.filename)
output(tar.filename.replace(/^@/, '').replace(/\//, '-'))
}
}

Expand All @@ -36,6 +36,7 @@ const pack_ = async (arg, opts) => {
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)

Expand Down
34 changes: 34 additions & 0 deletions test/lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,40 @@ t.test('should pack given directory', (t) => {
})
})

t.test('should pack given directory for scoped package', (t) => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: '@cool/my-pkg',
version: '1.0.0'
}, null, 2)
})

const pack = requireInject('../../lib/pack.js', {
'../../lib/utils/output.js': output,
'../../lib/npm.js': {
flatOptions: {
unicode: true,
json: true,
dryRun: true
}
},
libnpmpack,
npmlog: {
notice: () => {},
'showProgress': () => {},
'clearProgress': () => {}
}
})

return pack([testDir], er => {
if (er) {
throw er
}
const filename = 'cool-my-pkg-1.0.0.tgz'
t.strictSame(OUTPUT, [[filename]])
})
})

t.test('should log pack contents', (t) => {
const pack = requireInject('../../lib/pack.js', {
'../../lib/utils/output.js': output,
Expand Down

0 comments on commit 0808328

Please sign in to comment.