From 0808328c93d9cd975837eeb53202ce3844e1cf70 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 4 Aug 2020 17:03:46 -0700 Subject: [PATCH] pack: set correct filename for scoped packages This should probably be done in libnpmpack. Can be removed from here when it is. --- lib/pack.js | 3 ++- test/lib/pack.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/pack.js b/lib/pack.js index 14f63d83c0b7e..20e518484c0dc 100644 --- a/lib/pack.js +++ b/lib/pack.js @@ -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(/\//, '-')) } } @@ -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) diff --git a/test/lib/pack.js b/test/lib/pack.js index 9cb867d670782..097204ea92bea 100644 --- a/test/lib/pack.js +++ b/test/lib/pack.js @@ -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,