pnpm Workspaces & Private Flag: Should Workspace Root Privacy Implicitly Apply to Nested Packages?
0 reputation · 03 Oct 2020, 09:53 UTC
0 reputation · 03 Oct 2020, 09:53 UTC
The private field in a package’s package.json is intended to prevent accidental public publishing. In a pnpm workspace, each package can declare its own privacy setting, but the workspace root’s private flag is not automatically propagated to nested packages. This can lead to confusion when a developer expects a single pnpm publish command to publish only the intended package(s).
pnpm currently treats the private flag as a per‑package attribute. There is no documented enforcement that a workspace root marked "private": true will implicitly mark all child packages as private, unlike npm’s default behavior in some contexts. The community has debated whether such propagation should be added, but no consensus or implementation has been finalized as of the latest release.
private flag is set?--access flag during publishing?No. In pnpm, the private field is evaluated on a per‑package basis. A workspace root that declares "private": true does not automatically mark its child packages as private. Each nested package must have its own "private": true (or be excluded via a publish filter) to prevent accidental publishing.
private flag only on the package where it appears.pnpm publish --dry-run on a child without "private": true proceeds without a privacy warning."private": true to the child causes a private package warning during the dry run.packages/root/package.json (or the workspace root) and confirm "private": true is present.
packages/child/package.json and look for the private field. If it is missing or set to false, the child is considered publishable.
pnpm publish --dry-run
If a child lacks private, pnpm will proceed without a warning. If you want to test the warning, add "private": true to that child and run the command again.
pnpm publish --filter "@myorg/public-package" --dry-run
pnpm’s design keeps the privacy declaration explicit to avoid accidental lock‑in of entire workspaces. This matches the npm community’s historical approach where only the package being published is checked for private. Implicit propagation would break projects that intentionally keep some workspaces public while keeping others private.
You can enforce it manually by adding "private": true to every child’s package.json, or by using a publish filter to exclude private packages. There is no configuration flag to enable automatic propagation at this time.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.