fix: publishConfig.directory script (#3497)

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Pablo Sáez
2021-06-02 18:48:33 -04:00
committed by GitHub
parent 79fd2226b8
commit b5e9284c38
4 changed files with 17 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-publishing": patch
---
fix publishConfig.directory script

View File

@@ -147,7 +147,8 @@ Do you want to continue?`,
runNpm(opts.npmPath, ['publish', ...params])
return
}
const dir = (params.length > 0) && params[0] || process.cwd()
const dirInParams = (params.length > 0) && params[0]
const dir = dirInParams || opts.dir || process.cwd()
const _runScriptsIfPresent = runScriptsIfPresent.bind(null, {
depPath: dir,
@@ -176,7 +177,10 @@ Do you want to continue?`,
workspaceDir: opts.workspaceDir ?? dir,
},
async () => {
const args = opts.argv.original.slice(1)
let args = opts.argv.original.slice(1)
if (dirInParams) {
args = args.filter(arg => arg !== params[0])
}
const index = args.indexOf('--publish-branch')
if (index !== -1) {
// If --publish-branch follows with another cli option, only remove this argument
@@ -188,7 +192,7 @@ Do you want to continue?`,
}
}
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : undefined
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : dir
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args], {
cwd,

View File

@@ -102,10 +102,10 @@ export default async function (
const pkg = opts.selectedProjectsGraph[pkgDir].package
const publishResult = await publish({
...opts,
dir: pkg.dir,
argv: {
original: [
'publish',
pkg.dir,
'--tag',
tag,
'--registry',

View File

@@ -67,7 +67,8 @@ test('recursive publish', async () => {
},
])
await fs.writeFile('.npmrc', CREDENTIALS, 'utf8')
await fs.writeFile(path.join(pkg1.name, '.npmrc'), CREDENTIALS, 'utf8')
await fs.writeFile(path.join(pkg2.name, '.npmrc'), CREDENTIALS, 'utf8')
await publish.handler({
...DEFAULT_OPTS,
@@ -249,7 +250,8 @@ test('recursive publish writes publish summary', async () => {
},
])
await fs.writeFile('.npmrc', CREDENTIALS, 'utf8')
await fs.writeFile('@pnpmtest/test-recursive-publish-project-3/.npmrc', CREDENTIALS, 'utf8')
await fs.writeFile('@pnpmtest/test-recursive-publish-project-4/.npmrc', CREDENTIALS, 'utf8')
process.env.npm_config_userconfig = path.join('.npmrc')
await publish.handler({