From b5e9284c38cfb8e38fe3ebc897b85dd0aea9399e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20S=C3=A1ez?= Date: Wed, 2 Jun 2021 18:48:33 -0400 Subject: [PATCH] fix: publishConfig.directory script (#3497) Co-authored-by: Zoltan Kochan --- .changeset/tricky-yaks-fly.md | 5 +++++ packages/plugin-commands-publishing/src/publish.ts | 10 +++++++--- .../plugin-commands-publishing/src/recursivePublish.ts | 2 +- .../test/recursivePublish.ts | 6 ++++-- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/tricky-yaks-fly.md diff --git a/.changeset/tricky-yaks-fly.md b/.changeset/tricky-yaks-fly.md new file mode 100644 index 0000000000..57bcc37a3e --- /dev/null +++ b/.changeset/tricky-yaks-fly.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": patch +--- + +fix publishConfig.directory script diff --git a/packages/plugin-commands-publishing/src/publish.ts b/packages/plugin-commands-publishing/src/publish.ts index 914495897e..c6a2d2ada3 100644 --- a/packages/plugin-commands-publishing/src/publish.ts +++ b/packages/plugin-commands-publishing/src/publish.ts @@ -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, diff --git a/packages/plugin-commands-publishing/src/recursivePublish.ts b/packages/plugin-commands-publishing/src/recursivePublish.ts index 3dbcefc49a..842ddfb963 100644 --- a/packages/plugin-commands-publishing/src/recursivePublish.ts +++ b/packages/plugin-commands-publishing/src/recursivePublish.ts @@ -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', diff --git a/packages/plugin-commands-publishing/test/recursivePublish.ts b/packages/plugin-commands-publishing/test/recursivePublish.ts index 94bf8efa78..80356277db 100644 --- a/packages/plugin-commands-publishing/test/recursivePublish.ts +++ b/packages/plugin-commands-publishing/test/recursivePublish.ts @@ -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({