Skip to content

Commit

Permalink
fix: publish in workspace
Browse files Browse the repository at this point in the history
close #4348
  • Loading branch information
zkochan committed Apr 26, 2022
1 parent 3345c2c commit 97b4bd8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/nasty-baboons-return.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-publishing": patch
"pnpm": patch
---

`pnpm publish` should work correctly in a workspace, when the latest npm CLI is installed [#4348](https://github.com/pnpm/pnpm/issues/4348).
2 changes: 1 addition & 1 deletion packages/plugin-commands-publishing/package.json
Expand Up @@ -55,7 +55,6 @@
"load-json-file": "^6.2.0",
"path-exists": "^4.0.0",
"tar": "^6.1.4",
"tempy": "^1.0.0",
"write-yaml-file": "^4.2.0"
},
"dependencies": {
Expand All @@ -81,6 +80,7 @@
"realpath-missing": "^1.1.0",
"render-help": "^1.0.1",
"tar-stream": "^2.2.0",
"tempy": "^1.0.0",
"write-json-file": "^4.3.0"
},
"peerDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions packages/plugin-commands-publishing/src/publish.ts
Expand Up @@ -11,6 +11,7 @@ import rimraf from '@zkochan/rimraf'
import pick from 'ramda/src/pick'
import realpathMissing from 'realpath-missing'
import renderHelp from 'render-help'
import tempy from 'tempy'
import * as pack from './pack'
import recursivePublish, { PublishRecursiveOpts } from './recursivePublish'
import { getCurrentBranch, isGitRepo, isRemoteHistoryClean, isWorkingTreeClean } from './gitChecks'
Expand Down Expand Up @@ -186,11 +187,17 @@ Do you want to continue?`,
}
}

// We have to publish the tarball from another location.
// Otherwise, npm would publish the package with the package.json file
// from the current working directory, ignoring the package.json file
// that was generated and packed to the tarball.
const packDestination = tempy.directory()
const tarballName = await pack.handler({
...opts,
dir,
packDestination,
})
const tarballDir = path.dirname(path.join(dir, tarballName))
const tarballDir = path.dirname(path.join(packDestination, tarballName))
const localNpmrc = path.join(tarballDir, '.npmrc')
const copyNpmrc = !existsSync(localNpmrc) && opts.workspaceDir && existsSync(path.join(opts.workspaceDir, '.npmrc'))
if (copyNpmrc && opts.workspaceDir) {
Expand All @@ -199,7 +206,7 @@ Do you want to continue?`,
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', path.basename(tarballName), ...args], {
cwd: tarballDir,
})
await rimraf(path.join(dir, tarballName))
await rimraf(packDestination)
if (copyNpmrc) {
await rimraf(localNpmrc)
}
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97b4bd8

Please sign in to comment.