diff --git a/lib/utils/tar.js b/lib/utils/tar.js index 0a74ce8c44434..c25fe71614a60 100644 --- a/lib/utils/tar.js +++ b/lib/utils/tar.js @@ -120,7 +120,9 @@ const getContents = async (manifest, tarball) => { unpackedSize: totalEntrySize, shasum, integrity: ssri.parse(integrity.sha512[0]), - filename: `${manifest.name}-${manifest.version}.tgz`, + // @scope/packagename.tgz => scope-packagename.tgz + // we can safely use these global replace rules due to npm package naming rules + filename: `${manifest.name.replace('@', '').replace('/', '-')}-${manifest.version}.tgz`, files: uppers.concat(others), entryCount: totalEntries, bundled: Array.from(bundled), diff --git a/tap-snapshots/test/lib/commands/pack.js.test.cjs b/tap-snapshots/test/lib/commands/pack.js.test.cjs index e3219b45ed54f..fdb64f990e9b8 100644 --- a/tap-snapshots/test/lib/commands/pack.js.test.cjs +++ b/tap-snapshots/test/lib/commands/pack.js.test.cjs @@ -56,6 +56,36 @@ Array [ ] ` +exports[`test/lib/commands/pack.js TAP should log scoped package output as valid json > logs pack contents 1`] = ` +Array [] +` + +exports[`test/lib/commands/pack.js TAP should log scoped package output as valid json > outputs as json 1`] = ` +Array [ + Array [ + Object { + "bundled": Array [], + "entryCount": 1, + "filename": "myscope-test-package-1.0.0.tgz", + "files": Array [ + Object { + "mode": 420, + "path": "package.json", + "size": 50, + }, + ], + "id": "@myscope/test-package@1.0.0", + "integrity": "sha512-bUu8iTm2E5DZMrwKeyx963K6ViEmaFocXh75EujgI+FHSaJeqvObcdk1KFwdx8CbOgsfNHEvWNQw/bONAJsoNw==", + "name": "@myscope/test-package", + "shasum": "7e6eb2e1ca46bed6b8fa8e144e0fcd1b22fe2d98", + "size": 145, + "unpackedSize": 50, + "version": "1.0.0", + }, + ], +] +` + exports[`test/lib/commands/pack.js TAP should pack current directory with no arguments > logs pack contents 1`] = ` Array [ undefined, diff --git a/tap-snapshots/test/lib/commands/publish.js.test.cjs b/tap-snapshots/test/lib/commands/publish.js.test.cjs index 28211f7794cba..fd9fd74624070 100644 --- a/tap-snapshots/test/lib/commands/publish.js.test.cjs +++ b/tap-snapshots/test/lib/commands/publish.js.test.cjs @@ -136,7 +136,7 @@ Array [ String( name: @npm/test-package version: 1.0.0 - filename: @npm/test-package-1.0.0.tgz + filename: npm-test-package-1.0.0.tgz package size: 147 B unpacked size: 55 B shasum:{sha} @@ -191,7 +191,7 @@ Array [ String( name: @npm/test-package version: 1.0.0 - filename: @npm/test-package-1.0.0.tgz + filename: npm-test-package-1.0.0.tgz package size: 147 B unpacked size: 55 B shasum:{sha} diff --git a/tap-snapshots/test/lib/utils/tar.js.test.cjs b/tap-snapshots/test/lib/utils/tar.js.test.cjs index e4af36aeae0b6..e2b004f176319 100644 --- a/tap-snapshots/test/lib/utils/tar.js.test.cjs +++ b/tap-snapshots/test/lib/utils/tar.js.test.cjs @@ -33,4 +33,34 @@ own files: 5 total files: 5 +` + +exports[`test/lib/utils/tar.js TAP should log tarball contents of a scoped package > must match snapshot 1`] = ` + + +package: @myscope/my-cool-pkg@1.0.0 +=== Tarball Contents === + +4B cat +4B chai +4B dog +123B package.json +=== Bundled Dependencies === + +bundle-dep +=== Tarball Details === + +name: @myscope/my-cool-pkg +version: 1.0.0 +filename: myscope-my-cool-pkg-1.0.0.tgz +package size: 280 B +unpacked size: 135 B +shasum: a4f63307f2211e8fde72cd39bc1176b4fe997b71 +integrity: sha512-b+RavF8JiErJt[...]YpwkJc8ycaabA== +bundled deps: 1 +bundled files: 0 +own files: 5 +total files: 5 + + ` diff --git a/test/lib/commands/pack.js b/test/lib/commands/pack.js index f287d93dc7536..199afc640f035 100644 --- a/test/lib/commands/pack.js +++ b/test/lib/commands/pack.js @@ -77,6 +77,24 @@ t.test('should log output as valid json', async t => { t.ok(fs.statSync(path.resolve(npm.prefix, filename))) }) +t.test('should log scoped package output as valid json', async t => { + const { npm, outputs, logs } = await loadMockNpm(t, { + prefixDir: { + 'package.json': JSON.stringify({ + name: '@myscope/test-package', + version: '1.0.0', + }), + }, + }) + process.chdir(npm.prefix) + npm.config.set('json', true) + await npm.exec('pack', []) + const filename = 'myscope-test-package-1.0.0.tgz' + t.matchSnapshot(outputs.map(JSON.parse), 'outputs as json') + t.matchSnapshot(logs.notice.map(([, m]) => m), 'logs pack contents') + t.ok(fs.statSync(path.resolve(npm.prefix, filename))) +}) + t.test('dry run', async t => { const { npm, outputs, logs } = await loadMockNpm(t, { prefixDir: { diff --git a/test/lib/utils/tar.js b/test/lib/utils/tar.js index 23f40703b5cf4..f72b1432c89d6 100644 --- a/test/lib/utils/tar.js +++ b/test/lib/utils/tar.js @@ -51,6 +51,38 @@ t.test('should log tarball contents', async (t) => { t.matchSnapshot(printLogs(tarballContents)) }) +t.test('should log tarball contents of a scoped package', async (t) => { + const testDir = t.testdir({ + 'package.json': JSON.stringify({ + name: '@myscope/my-cool-pkg', + version: '1.0.0', + bundleDependencies: [ + 'bundle-dep', + ], + dependencies: { + 'bundle-dep': '1.0.0', + }, + }), + cat: 'meow', + chai: 'blub', + dog: 'woof', + node_modules: { + 'bundle-dep': { + 'package.json': '', + }, + }, + }) + + const tarball = await pack(testDir) + const tarballContents = await getContents({ + _id: '1', + name: '@myscope/my-cool-pkg', + version: '1.0.0', + }, tarball) + + t.matchSnapshot(printLogs(tarballContents)) +}) + t.test('should log tarball contents with unicode', async (t) => { const { logTar } = mockTar({ notice: (str) => {