Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(publish): remove meaningless key in publishConfig #4334

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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