fix(release): type package export manifests
This commit is contained in:
parent
008dd44eac
commit
a7e5abd4ab
|
|
@ -66,16 +66,20 @@ interface PackageExports {
|
|||
[key: string]: PackageExports | string | undefined
|
||||
}
|
||||
|
||||
interface PublishPackageJSON extends Record<string, unknown> {
|
||||
interface PublishPackageJSON extends PackageJSON {
|
||||
exports?: PackageExports
|
||||
imports?: PackageExports
|
||||
}
|
||||
|
||||
function isPackageExports(value: unknown): value is PackageExports {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
}
|
||||
|
||||
function removeUnpublishedConditions(value: PackageExports | undefined): void {
|
||||
if (!value) return
|
||||
delete value.bun
|
||||
for (const child of Object.values(value)) {
|
||||
if (typeof child === 'object' && child) removeUnpublishedConditions(child)
|
||||
if (isPackageExports(child)) removeUnpublishedConditions(child)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,14 @@ import { promisify } from 'node:util'
|
|||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
type PackageExports = {
|
||||
[key: string]: PackageExports | string | null | undefined
|
||||
}
|
||||
|
||||
type PackageJSON = {
|
||||
bin?: Record<string, string> | string
|
||||
exports?: PackageExports
|
||||
imports?: PackageExports
|
||||
name: string
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +28,7 @@ function packageExportTargets(value: unknown): string[] {
|
|||
return Object.values(value).flatMap(packageExportTargets)
|
||||
}
|
||||
|
||||
export function packageExportTargetPaths(packageJSON: { exports?: unknown }): string[] {
|
||||
export function packageExportTargetPaths(packageJSON: Pick<PackageJSON, 'exports'>): string[] {
|
||||
return packageExportTargets(packageJSON.exports)
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +58,7 @@ export async function validateTarballBinTargets(tarballPath: string): Promise<vo
|
|||
|
||||
export async function validateTarballExportTargets(tarballPath: string): Promise<void> {
|
||||
const entries = await tarballEntries(tarballPath)
|
||||
const packageJSON = (await tarballPackageJSON(tarballPath)) as PackageJSON & { exports?: unknown }
|
||||
const packageJSON = await tarballPackageJSON(tarballPath)
|
||||
|
||||
for (const target of packageExportTargetPaths(packageJSON)) {
|
||||
if (!target.startsWith('./')) continue
|
||||
|
|
|
|||
Loading…
Reference in a new issue