Skip to content

Commit

Permalink
refactor(publish): remove meaningless key in publishConfig (#4334)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHole1 committed Feb 13, 2022
1 parent 21cd0f2 commit e1b4590
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-donuts-argue.md
@@ -0,0 +1,6 @@
---
"@pnpm/exportable-manifest": minor
"@pnpm/plugin-commands-publishing": minor
---

remove meaningless key in publishConfig when use `pack` or `pulish` commands [#4311](https://github.com/pnpm/pnpm/issues/4311)
8 changes: 7 additions & 1 deletion packages/exportable-manifest/src/index.ts
Expand Up @@ -3,6 +3,7 @@ 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
Expand Down Expand Up @@ -48,13 +49,18 @@ export default async function makePublishManifest (dir: string, originalManifest
}
}

const { publishConfig } = 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
}
}

if (opts?.readmeFile) {
Expand Down
30 changes: 30 additions & 0 deletions packages/plugin-commands-publishing/test/pack.ts
Expand Up @@ -165,3 +165,33 @@ test('pack: should not embed readme', async () => {

expect(pkg.readme).toBeFalsy()
})

test('pack: remove publishConfig', async () => {
prepare({
name: 'remove-publish-config',
version: '0.0.0',
main: 'index.d.js',
publishConfig: {
types: 'index.d.ts',
main: 'index.js',
},
})

await pack.handler({
...DEFAULT_OPTS,
argv: { original: [] },
dir: process.cwd(),
extraBinPaths: [],
packDestination: process.cwd(),
embedReadme: false,
})

await tar.x({ file: 'remove-publish-config-0.0.0.tgz' })

expect((await import(path.resolve('package/package.json'))).default).toStrictEqual({
name: 'remove-publish-config',
version: '0.0.0',
main: 'index.js',
types: 'index.d.ts',
})
})
14 changes: 0 additions & 14 deletions packages/plugin-commands-publishing/test/publish.ts
Expand Up @@ -268,20 +268,6 @@ test('publish: package with all possible fields in publishConfig', async () => {
types: './published-types.d.ts',
typings: './published-typings.d.ts',

publishConfig: {
bin: './published-bin.js',
browser: './published-browser.js',
es2015: './published-es2015.js',
esnext: './published-esnext.js',
exports: './published-exports.js',
main: './published.js',
module: './published.mjs',
types: './published-types.d.ts',
typings: './published-typings.d.ts',
'umd:main': './published-umd.js',
unpkg: './published-unpkg.js',
},

browser: './published-browser.js',
es2015: './published-es2015.js',
esnext: './published-esnext.js',
Expand Down

0 comments on commit e1b4590

Please sign in to comment.