Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 473cbc4

Browse files
committed
fix: publish --json (#8789)
close #8788
1 parent 55fb7a6 commit 473cbc4

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pnpm/plugin-commands-publishing": patch
3+
"pnpm": patch
4+
---
5+
6+
`pnpm publish --json` should work [#8788](https://github.com/pnpm/pnpm/issues/8788).

releasing/plugin-commands-publishing/src/pack.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,34 @@ export function help (): string {
6464
})
6565
}
6666

67-
export async function handler (
68-
opts: Pick<UniversalOptions, 'dir'> & Pick<Config, 'catalogs' | 'ignoreScripts' | 'rawConfig' | 'embedReadme' | 'packGzipLevel' | 'nodeLinker'> & Partial<Pick<Config, 'extraBinPaths' | 'extraEnv'>> & {
69-
argv: {
70-
original: string[]
71-
}
72-
engineStrict?: boolean
73-
packDestination?: string
74-
workspaceDir?: string
75-
json?: boolean
67+
export type PackOptions = Pick<UniversalOptions, 'dir'> & Pick<Config, 'catalogs' | 'ignoreScripts' | 'rawConfig' | 'embedReadme' | 'packGzipLevel' | 'nodeLinker'> & Partial<Pick<Config, 'extraBinPaths' | 'extraEnv'>> & {
68+
argv: {
69+
original: string[]
70+
}
71+
engineStrict?: boolean
72+
packDestination?: string
73+
workspaceDir?: string
74+
json?: boolean
75+
}
76+
77+
export async function handler (opts: PackOptions): Promise<string> {
78+
const { publishedManifest, tarballPath, contents } = await api(opts)
79+
if (opts.json) {
80+
return JSON.stringify({
81+
name: publishedManifest.name,
82+
version: publishedManifest.version,
83+
filename: tarballPath,
84+
files: contents.map((path) => ({ path })),
85+
}, null, 2)
7686
}
77-
): Promise<string> {
87+
return `${chalk.blueBright('Tarball Contents')}
88+
${contents.join('\n')}
89+
90+
${chalk.blueBright('Tarball Details')}
91+
${tarballPath}`
92+
}
93+
94+
export async function api (opts: PackOptions): Promise<PackResult> {
7895
const { manifest: entryManifest, fileName: manifestFileName } = await readProjectManifest(opts.dir, opts)
7996
preventBundledDependenciesWithoutHoistedNodeLinker(opts.nodeLinker, entryManifest)
8097
const _runScriptsIfPresent = runScriptsIfPresent.bind(null, {
@@ -152,19 +169,17 @@ export async function handler (
152169
packedTarballPath = path.relative(opts.dir, path.join(dir, tarballName))
153170
}
154171
const packedContents = files.sort((a, b) => a.localeCompare(b, 'en'))
155-
if (opts.json) {
156-
return JSON.stringify({
157-
name: publishManifest.name,
158-
version: publishManifest.version,
159-
filename: packedTarballPath,
160-
files: packedContents.map((path) => ({ path })),
161-
}, null, 2)
172+
return {
173+
publishedManifest: publishManifest,
174+
contents: packedContents,
175+
tarballPath: packedTarballPath,
162176
}
163-
return `${chalk.blueBright('Tarball Contents')}
164-
${packedContents.join('\n')}
177+
}
165178

166-
${chalk.blueBright('Tarball Details')}
167-
${packedTarballPath}`
179+
export interface PackResult {
180+
publishedManifest: ProjectManifest
181+
contents: string[]
182+
tarballPath: string
168183
}
169184

170185
function preventBundledDependenciesWithoutHoistedNodeLinker (nodeLinker: Config['nodeLinker'], manifest: ProjectManifest): void {

releasing/plugin-commands-publishing/src/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ Do you want to continue?`,
237237
// from the current working directory, ignoring the package.json file
238238
// that was generated and packed to the tarball.
239239
const packDestination = tempy.directory()
240-
const tarballName = await pack.handler({
240+
const { tarballPath } = await pack.api({
241241
...opts,
242242
dir,
243243
packDestination,
244244
})
245245
await copyNpmrc({ dir, workspaceDir: opts.workspaceDir, packDestination })
246-
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', path.basename(tarballName), ...args], {
246+
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', path.basename(tarballPath), ...args], {
247247
cwd: packDestination,
248248
env: getEnvWithTokens(opts),
249249
})

0 commit comments

Comments
 (0)