Visitar URL original
fix: key stage download --json output by package name (#9380) · npm/cli@2a13550 · GitHub
Skip to content

Commit 2a13550

Browse files
reggiCopilot
andauthored
fix: key stage download --json output by package name (#9380)
`npm stage download <id> --json` currently emits the package contents under a literal `"undefined"` key because `logTar` is called without a `key` option. ### Before ```json { "undefined": { "name": "polo-meow-meow-meow", "version": "1.0.3", ... } } ``` ### After ```json { "polo-meow-meow-meow": { "name": "polo-meow-meow-meow", "version": "1.0.3", ... } } ``` This matches the JSON shape of `npm publish --json` and `npm pack --json`. ### Background The `key == null` fallback in `lib/utils/tar.js` (that would have rendered a bare object when no key was passed) was removed from `latest` in #9247 ("fix: sync json output of pack and publish") as a `BREAKING CHANGE`. Per that PR: > BREAKING CHANGE: the --json output of `npm pack` and `npm publish` have changed. They are now always consistent, and in the same format. > > Previously, `npm pack` would output an array of entries and `npm publish` an object. The `npm publish` object also changed forms depending on if workspaces were being published. > > Now, the output is always an object with the package name as the top level index. When #9201 (npm stage) landed, it added a new `logTar` caller in `lib/commands/stage/download.js` that did not pass a `key`, silently violating the v12 contract established in #9247 and producing the `"undefined"` wrapper. This PR brings the new caller into compliance. ### Repro ``` npm stage download <stage-id> --json ``` A follow-up backports this to `release/v11` for consistent output across branches: #9381. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 254809e commit 2a13550

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎lib/commands/stage/download.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class StageDownload extends BaseCommand {
3131

3232
const manifest = await this.#readManifestFromTarball(data)
3333
const pkgContents = await getContents(manifest, data)
34-
logTar(pkgContents, { unicode, json })
34+
logTar(pkgContents, { unicode, json, key: pkgContents.name })
3535

3636
const safeName = pkgContents.name.replace('@', '').replace('/', '-')
3737
const filename = `${safeName}-${pkgContents.version}-${stageId}.tgz`

0 commit comments

Comments
 (0)