fix(plugin-commands-publishing): add readme file to published package.json (#4117)

close #4091
This commit is contained in:
FolknR
2021-12-15 16:07:55 +02:00
committed by GitHub
parent ca4749adeb
commit 6493e0c932
5 changed files with 27 additions and 2 deletions

View 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

View 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
}

View File

@@ -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',
})
})

View File

@@ -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
}

View File

@@ -90,6 +90,7 @@ export interface BaseManifest {
typings?: string
types?: string
publishConfig?: PublishConfig
readme?: string
}
export type DependencyManifest = BaseManifest & Required<Pick<BaseManifest, 'name' | 'version'>>