mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(plugin-commands-publishing): add readme file to published package.json (#4117)
close #4091
This commit is contained in:
7
.changeset/flat-dogs-admire.md
Normal file
7
.changeset/flat-dogs-admire.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/exportable-manifest": patch
|
||||
"@pnpm/plugin-commands-publishing": patch
|
||||
"@pnpm/types": patch
|
||||
---
|
||||
|
||||
add readme file to published package.json file
|
||||
@@ -36,7 +36,7 @@ const PREPUBLISH_SCRIPTS = [
|
||||
'postpublish',
|
||||
]
|
||||
|
||||
export default async function makePublishManifest (dir: string, originalManifest: ProjectManifest) {
|
||||
export default async function makePublishManifest (dir: string, originalManifest: ProjectManifest, opts?: { readmeFile?: string }) {
|
||||
const publishManifest: ProjectManifest = omit(['pnpm', 'scripts'], originalManifest)
|
||||
if (originalManifest.scripts != null) {
|
||||
publishManifest.scripts = omit(PREPUBLISH_SCRIPTS, originalManifest.scripts)
|
||||
@@ -57,6 +57,10 @@ export default async function makePublishManifest (dir: string, originalManifest
|
||||
})
|
||||
}
|
||||
|
||||
if (opts?.readmeFile) {
|
||||
publishManifest.readme ??= opts.readmeFile
|
||||
}
|
||||
|
||||
return publishManifest
|
||||
}
|
||||
|
||||
|
||||
@@ -45,3 +45,14 @@ test('publish lifecycle scripts are removed', async () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('readme added to published manifest', async () => {
|
||||
expect(await exportableManifest(process.cwd(), {
|
||||
name: 'foo',
|
||||
version: '1.0.0',
|
||||
}, { readmeFile: 'readme content' })).toStrictEqual({
|
||||
name: 'foo',
|
||||
version: '1.0.0',
|
||||
readme: 'readme content',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -124,7 +124,9 @@ async function packPkg (destFile: string, filesMap: Record<string, string>, proj
|
||||
}
|
||||
const mode = isExecutable ? 0o755 : 0o644
|
||||
if (/^package\/package\.(json|json5|yaml)/.test(name)) {
|
||||
const publishManifest = await exportableManifest(projectDir, manifest)
|
||||
const readmePath = Object.keys(filesMap).find(name => /^package\/readme.md$/i.test(name))
|
||||
const readmeFile = readmePath ? await fs.promises.readFile(filesMap[readmePath], 'utf8') : undefined
|
||||
const publishManifest = await exportableManifest(projectDir, manifest, { readmeFile })
|
||||
pack.entry({ mode, mtime, name: 'package/package.json' }, JSON.stringify(publishManifest, null, 2))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ export interface BaseManifest {
|
||||
typings?: string
|
||||
types?: string
|
||||
publishConfig?: PublishConfig
|
||||
readme?: string
|
||||
}
|
||||
|
||||
export type DependencyManifest = BaseManifest & Required<Pick<BaseManifest, 'name' | 'version'>>
|
||||
|
||||
Reference in New Issue
Block a user