mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(exportable-manifest, types): add typesVersions field to PUBLISH_CONFIG_WHITELIST (#4637)
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/yellow-wolves-swim.md
Normal file
6
.changeset/yellow-wolves-swim.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/exportable-manifest": patch
|
||||
"@pnpm/types": patch
|
||||
---
|
||||
|
||||
Add typesVersions to PUBLISH_CONFIG_WHITELIST
|
||||
@@ -3,30 +3,8 @@ import PnpmError from '@pnpm/error'
|
||||
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import { Dependencies, ProjectManifest } from '@pnpm/types'
|
||||
import fromPairs from 'ramda/src/fromPairs'
|
||||
import isEmpty from 'ramda/src/isEmpty'
|
||||
import omit from 'ramda/src/omit'
|
||||
|
||||
// property keys that are copied from publishConfig into the manifest
|
||||
const PUBLISH_CONFIG_WHITELIST = new Set([
|
||||
// manifest fields that may make sense to overwrite
|
||||
'bin',
|
||||
'type',
|
||||
'imports',
|
||||
// https://github.com/stereobooster/package.json#package-bundlers
|
||||
'main',
|
||||
'module',
|
||||
'typings',
|
||||
'types',
|
||||
'exports',
|
||||
'browser',
|
||||
'esnext',
|
||||
'es2015',
|
||||
'unpkg',
|
||||
'umd:main',
|
||||
// These are useful to hide in order to avoid warnings during local development
|
||||
'os',
|
||||
'cpu',
|
||||
])
|
||||
import { overridePublishConfig } from './overridePublishConfig'
|
||||
|
||||
const PREPUBLISH_SCRIPTS = [
|
||||
'prepublishOnly',
|
||||
@@ -49,19 +27,7 @@ export default async function makePublishManifest (dir: string, originalManifest
|
||||
}
|
||||
}
|
||||
|
||||
const { publishConfig } = publishManifest
|
||||
if (publishConfig != null) {
|
||||
Object.keys(publishConfig)
|
||||
.filter(key => PUBLISH_CONFIG_WHITELIST.has(key))
|
||||
.forEach(key => {
|
||||
publishManifest[key] = publishConfig[key]
|
||||
delete publishConfig[key]
|
||||
})
|
||||
|
||||
if (isEmpty(publishConfig)) {
|
||||
delete publishManifest.publishConfig
|
||||
}
|
||||
}
|
||||
overridePublishConfig(publishManifest)
|
||||
|
||||
if (opts?.readmeFile) {
|
||||
publishManifest.readme ??= opts.readmeFile
|
||||
|
||||
42
packages/exportable-manifest/src/overridePublishConfig.ts
Normal file
42
packages/exportable-manifest/src/overridePublishConfig.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { ProjectManifest } from '@pnpm/types'
|
||||
import isEmpty from 'ramda/src/isEmpty'
|
||||
|
||||
// property keys that are copied from publishConfig into the manifest
|
||||
const PUBLISH_CONFIG_WHITELIST = new Set([
|
||||
// manifest fields that may make sense to overwrite
|
||||
'bin',
|
||||
'type',
|
||||
'imports',
|
||||
// https://github.com/stereobooster/package.json#package-bundlers
|
||||
'main',
|
||||
'module',
|
||||
'typings',
|
||||
'types',
|
||||
'exports',
|
||||
'browser',
|
||||
'esnext',
|
||||
'es2015',
|
||||
'unpkg',
|
||||
'umd:main',
|
||||
// These are useful to hide in order to avoid warnings during local development
|
||||
'os',
|
||||
'cpu',
|
||||
// https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions
|
||||
'typesVersions',
|
||||
])
|
||||
|
||||
export function overridePublishConfig (publishManifest: ProjectManifest): void {
|
||||
const { publishConfig } = publishManifest
|
||||
if (!publishConfig) return
|
||||
|
||||
Object.entries(publishConfig)
|
||||
.filter(([key]) => PUBLISH_CONFIG_WHITELIST.has(key))
|
||||
.forEach(([key, value]) => {
|
||||
publishManifest[key] = value
|
||||
delete publishConfig[key]
|
||||
})
|
||||
|
||||
if (isEmpty(publishConfig)) {
|
||||
delete publishManifest.publishConfig
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { PackageManifest, PublishConfig } from '@pnpm/types'
|
||||
import { overridePublishConfig } from '../lib/overridePublishConfig'
|
||||
|
||||
test('publish config to be overridden', async () => {
|
||||
const publishConfig: PublishConfig = {
|
||||
main: 'overridden',
|
||||
types: 'overridden',
|
||||
typesVersions: {
|
||||
'*': {
|
||||
'*': ['overridden'],
|
||||
},
|
||||
},
|
||||
}
|
||||
const publishManifest: PackageManifest = {
|
||||
name: 'foo',
|
||||
version: '1.0.0',
|
||||
main: 'origin',
|
||||
types: 'origin',
|
||||
typesVersions: {
|
||||
'*': {
|
||||
'*': ['origin'],
|
||||
},
|
||||
},
|
||||
publishConfig,
|
||||
}
|
||||
overridePublishConfig(publishManifest)
|
||||
|
||||
Object.keys(publishConfig).forEach((publishConfigKey) => {
|
||||
expect(publishManifest[publishConfigKey]).toEqual(publishConfig[publishConfigKey])
|
||||
})
|
||||
})
|
||||
@@ -58,6 +58,14 @@ export interface PublishConfig extends Record<string, unknown> {
|
||||
executableFiles?: string[]
|
||||
}
|
||||
|
||||
type Version = string
|
||||
type Pattern = string
|
||||
export interface TypesVersions {
|
||||
[version: Version]: {
|
||||
[pattern: Pattern]: string[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface BaseManifest {
|
||||
name?: string
|
||||
version?: string
|
||||
@@ -90,6 +98,7 @@ export interface BaseManifest {
|
||||
typings?: string
|
||||
types?: string
|
||||
publishConfig?: PublishConfig
|
||||
typesVersions?: TypesVersions
|
||||
readme?: string
|
||||
keywords?: string[]
|
||||
author?: string
|
||||
|
||||
Reference in New Issue
Block a user