Skip to content

Commit 0808328

Browse files
committed
pack: set correct filename for scoped packages
This should probably be done in libnpmpack. Can be removed from here when it is.
1 parent 2c305e8 commit 0808328

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/pack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const pack = async (args) => {
2727

2828
for (const tar of tarballs) {
2929
logTar(tar, { log, unicode })
30-
output(tar.filename)
30+
output(tar.filename.replace(/^@/, '').replace(/\//, '-'))
3131
}
3232
}
3333

@@ -36,6 +36,7 @@ const pack_ = async (arg, opts) => {
3636
const { dryRun } = opts
3737
const manifest = await pacote.manifest(spec, opts)
3838
const filename = `${manifest.name}-${manifest.version}.tgz`
39+
.replace(/^@/, '').replace(/\//, '-')
3940
const tarballData = await libpack(arg, opts)
4041
const pkgContents = await getContents(manifest, tarballData)
4142

test/lib/pack.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,40 @@ t.test('should pack given directory', (t) => {
7878
})
7979
})
8080

81+
t.test('should pack given directory for scoped package', (t) => {
82+
const testDir = t.testdir({
83+
'package.json': JSON.stringify({
84+
name: '@cool/my-pkg',
85+
version: '1.0.0'
86+
}, null, 2)
87+
})
88+
89+
const pack = requireInject('../../lib/pack.js', {
90+
'../../lib/utils/output.js': output,
91+
'../../lib/npm.js': {
92+
flatOptions: {
93+
unicode: true,
94+
json: true,
95+
dryRun: true
96+
}
97+
},
98+
libnpmpack,
99+
npmlog: {
100+
notice: () => {},
101+
'showProgress': () => {},
102+
'clearProgress': () => {}
103+
}
104+
})
105+
106+
return pack([testDir], er => {
107+
if (er) {
108+
throw er
109+
}
110+
const filename = 'cool-my-pkg-1.0.0.tgz'
111+
t.strictSame(OUTPUT, [[filename]])
112+
})
113+
})
114+
81115
t.test('should log pack contents', (t) => {
82116
const pack = requireInject('../../lib/pack.js', {
83117
'../../lib/utils/output.js': output,

0 commit comments

Comments
 (0)