mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-24 01:51:41 -04:00
fix(publish): copy .npmrc from the root of repository (#3511)
close #3508
This commit is contained in:
5
.changeset/rare-pianos-buy.md
Normal file
5
.changeset/rare-pianos-buy.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-publishing": patch
|
||||
---
|
||||
|
||||
Copy the `.npmrc` from the root of the repository.
|
||||
@@ -1,4 +1,4 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import { promises as fs, existsSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { docsUrl, readProjectManifest } from '@pnpm/cli-utils'
|
||||
import { Config, types as allTypes } from '@pnpm/config'
|
||||
@@ -193,10 +193,18 @@ Do you want to continue?`,
|
||||
}
|
||||
|
||||
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : dir
|
||||
const localNpmrc = path.join(cwd, '.npmrc')
|
||||
const copyNpmrc = !existsSync(localNpmrc) && opts.workspaceDir && existsSync(path.join(opts.workspaceDir, '.npmrc'))
|
||||
if (copyNpmrc && opts.workspaceDir) {
|
||||
await fs.copyFile(path.join(opts.workspaceDir, '.npmrc'), localNpmrc)
|
||||
}
|
||||
|
||||
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args], {
|
||||
cwd,
|
||||
})
|
||||
if (copyNpmrc) {
|
||||
await rimraf(localNpmrc)
|
||||
}
|
||||
|
||||
_status = status!
|
||||
}
|
||||
|
||||
@@ -67,8 +67,7 @@ test('recursive publish', async () => {
|
||||
},
|
||||
])
|
||||
|
||||
await fs.writeFile(path.join(pkg1.name, '.npmrc'), CREDENTIALS, 'utf8')
|
||||
await fs.writeFile(path.join(pkg2.name, '.npmrc'), CREDENTIALS, 'utf8')
|
||||
await fs.writeFile('.npmrc', CREDENTIALS, 'utf8')
|
||||
|
||||
await publish.handler({
|
||||
...DEFAULT_OPTS,
|
||||
@@ -250,8 +249,7 @@ test('recursive publish writes publish summary', async () => {
|
||||
},
|
||||
])
|
||||
|
||||
await fs.writeFile('@pnpmtest/test-recursive-publish-project-3/.npmrc', CREDENTIALS, 'utf8')
|
||||
await fs.writeFile('@pnpmtest/test-recursive-publish-project-4/.npmrc', CREDENTIALS, 'utf8')
|
||||
await fs.writeFile('.npmrc', CREDENTIALS, 'utf8')
|
||||
|
||||
process.env.npm_config_userconfig = path.join('.npmrc')
|
||||
await publish.handler({
|
||||
|
||||
Reference in New Issue
Block a user