Skip to content

fix(deploy): prevent extra directories when using relative deploy path - #11006

Merged
zkochan merged 1 commit into
pnpm:mainfrom
zubeyralmaho:fix/deploy-extra-directories-10981
Sep 25, 2026
Merged

zkochan merged 1 commit into
pnpm:mainfrom
zubeyralmaho:fix/deploy-extra-directories-10981

Conversation

@zubeyralmaho

@zubeyralmaho zubeyralmaho commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10981

pnpm deploy with a relative path (e.g., pnpm --filter=my-pkg deploy ./foo) creates extraneous nested directories inside the deploy target (foo/foo/...) and corrupts workspace projects' node_modules. This happens in the legacy deploy path (used when shared lockfile is unavailable or node-linker=hoisted without pre-existing lockfile).

Root Cause

In the legacy deploy path (deploy.ts), only the deployed project's modulesDir was updated to point to the deploy directory's node_modules (line 135):

deployedProject.modulesDir = path.relative(selectedProject.rootDir, path.join(deployDir, 'node_modules'))

The modulesDir option passed to install.handler (line 193) was a relative path from workspaceDir:

modulesDir: path.relative(opts.workspaceDir, path.join(deployDir, 'node_modules'))
// e.g., 'foo/node_modules' when deploying to ./foo

In read-projects-context, this relative modulesDir is used as a fallback for all workspace projects that don't have an explicit modulesDir:

// read-projects-context/src/index.ts:61
const modulesDir = path.join(project.rootDir, project.modulesDir ?? relativeModulesDir)

For non-deployed projects, this produced wrong paths like project-2/foo/node_modules instead of foo/node_modules, creating extra directories inside workspace projects and inside the deploy target.

Fix

Set modulesDir for all workspace projects in allProjects to point to the deploy directory's node_modules, not just the deployed project:

const deployNodeModules = path.join(deployDir, 'node_modules')
if (opts.allProjects) {
  for (const project of opts.allProjects) {
    project.modulesDir = path.relative(project.rootDir, deployNodeModules)
  }
}

This ensures that no matter which code path is taken downstream, all modulesDir references resolve to the deploy directory.

Test plan

  • All 11 deploy tests pass (including new regression test)
  • All 9 shared lockfile deploy tests pass
  • Added regression test: deploy with node-linker=hoisted to a nested relative path (some/nested/path) verifies no extra directories are created inside deploy target or workspace projects
  • Compile and lint pass

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pnpm deploy with a relative destination path creating unexpected extra directories in the deploy destination and workspace projects.
    • Ensured deployed projects and their production dependencies are available in the deploy destination when using the hoisted linker.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a pnpm deploy regression where deploying to a relative (nested) target path could cause extra directories to be created inside the deploy target and/or inside other workspace projects, particularly with node-linker=hoisted.

Changes:

  • Add a regression test ensuring pnpm deploy doesn’t create unintended nested directories when deploying to a nested relative path.
  • Update deploy implementation to align workspace projects’ modulesDir resolution with the deploy target’s node_modules.
  • Add a changeset to publish the fix as a patch.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
releasing/commands/test/deploy/deploy.test.ts Adds regression coverage for unintended directory creation during deploy with hoisted linker.
releasing/commands/src/deploy/deploy.ts Adjusts workspace project modulesDir handling to avoid incorrect path joining that creates extraneous directories.
.changeset/fix-deploy-extra-directories.md Declares patch releases for the deploy fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread releasing/commands/src/deploy/deploy.ts Resolved

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: Fixes pnpm deploy creating extra directories (e.g. project-2/foo/node_modules) when using a relative deploy path in workspaces.

Done well: Root cause is clear: only deployedProject had modulesDir set; non-deployed projects fell back to incorrect relative path. Fix correctly sets modulesDir for ALL workspace projects to path.relative(project.rootDir, deployNodeModules). The inline comment explains why this is needed. Regression test with multi-project workspace (project-1 depends on project-2) and deploy to some/nested/path verifies no extra dirs in deploy target or other projects.

Minor: The test asserts fs.existsSync(project-1/some) and project-2/some are falsy. Good coverage. Consider also asserting root/some is falsy if root is in allProjects, though the current test may already cover that implicitly.

In the legacy deploy path, only the deployed project's modulesDir was
set to point to the deploy directory's node_modules. Other workspace
projects fell back to the relative modulesDir from opts, which was
incorrectly joined with each project's rootDir in read-projects-context,
creating extraneous directories (e.g., project-2/foo/node_modules when
deploying to ./foo) and corrupting the project's own node_modules.

Now all workspace projects in allProjects get their modulesDir set to
point to the deploy directory's node_modules, preventing any stray
directory creation.

Closes pnpm#10981

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@zkochan
zkochan force-pushed the fix/deploy-extra-directories-10981 branch from 4a2544d to 3704e7e Compare September 25, 2026 18:56
Copilot AI review requested due to automatic review settings September 25, 2026 18:56
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 602c3637-9d22-4486-960f-9e138f5988c3

📥 Commits

Reviewing files that changed from the base of the PR and between 28e3894 and 3704e7e.

📒 Files selected for processing (3)
  • .changeset/fix-deploy-extra-directories.md
  • pnpm11/releasing/commands/src/deploy/deploy.ts
  • pnpm11/releasing/commands/test/deploy/deploy.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The deploy handler now updates module-directory paths for every workspace project. A regression test covers a hoisted-linker deployment to a nested relative path and checks for extra directories. A changeset requests patch releases for @pnpm/releasing.commands and pnpm.

Changes

Deploy target path handling

Layer / File(s) Summary
Update project module paths and verify deploy output
pnpm11/releasing/commands/src/deploy/deploy.ts, pnpm11/releasing/commands/test/deploy/deploy.test.ts, .changeset/fix-deploy-extra-directories.md
The handler sets each workspace project's modulesDir relative to its root. The regression test checks deployed contents and confirms no extra some directories appear in the destination or source projects. The changeset requests patch releases.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
Ensure pnpm deploy creates files only inside the deploy target directory [#10981] ✅

Suggested labels: product: pnpm@11

Merge Risk: ⚪ Minimal · up to 3704e

Workspace projects are directed to the deploy target during relative-path deployment, and the regression test checks for duplicated directories. No actionable merge risk remains.

Architecture Summary

Architecture risk: 🔵 Low · up to 3704e

The change affects 1 system.

Changed systems: pnpm11

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — pnpm11 (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in pnpm11/releasing/commands/src/deploy/deploy.ts: handler now sets modulesDir relative to each project’s rootDir for every project in opts.allProjects. Previously, it searched for the selected project by rootDir and updated only that project; when no match existed, it updated none.
  • observed — Modified behavior in pnpm11/releasing/commands/test/deploy/deploy.test.ts: Added a test that deploys project-1 to some/nested/path with nodeLinker: 'hoisted'. It verifies the destination contains project-2, is-positive, the project entry file, and .modules.yaml, and that no some directory is created inside the destination or either source project.
  • observed — Modified behavior in .changeset/fix-deploy-extra-directories.md: Adds a changeset requesting patch releases for @pnpm/releasing.commands and pnpm, with a description of the relative-path pnpm deploy extra-directory issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

pnpm11/releasing/commands/src/deploy/deploy.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

pnpm11/releasing/commands/test/deploy/deploy.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain.

Review effort: Lite
Findings: None

Resolved since last review (2)

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 25, 2026

@zkochan zkochan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Rebased cleanly onto main, updated paths for pnpm11 monorepo layout, verified test suite passes and review threads are resolved.


Reviewed by Antigravity (gemini-2.5-pro).

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Informational

1. A changeset link breaks colon style 📘 Rule violation ✧ Quality
Description
fix-deploy-extra-directories.md embeds the issue link as an https:// URL, whose colon introduces
neither a list nor an example. A compliance check applying the changeset punctuation convention will
reject this release-note entry when it is validated.
Code

.changeset/fix-deploy-extra-directories.md[6]

+`pnpm deploy` no longer creates extra directories inside the deploy target and workspace projects when using a relative deploy path [pnpm/pnpm#10981](https://github.com/pnpm/pnpm/issues/10981).
Relevance

● Weak

Recent exact precedents reject full https:// links in changesets under this colon-style rule.

PR-#15578
PR-#15580
PR-#15278

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 3058313 requires every colon in a modified changeset to introduce a list or example.
The added release-note sentence contains a colon only as part of its issue URL.

Rule 3058313: Changeset text formatting conventions
.changeset/fix-deploy-extra-directories.md[6-6]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset contains a colon in an `https://` issue URL, but the changeset formatting convention permits colons only when introducing lists or examples.

## Fix Focus Areas
- .changeset/fix-deploy-extra-directories.md[6-6]

## Recommended Fix
Replace the Markdown URL with the plain issue reference `pnpm/pnpm#10981`, preserving traceability without using a disallowed colon.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 53 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This changes deploy/install path resolution across all workspace projects, affecting filesystem layout and node_modules integrity, so it carries meaningful behavioral and regression risk despite the localized diff.

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit 92b3552 into pnpm:main Sep 25, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm deploy creates extra directories and breaks project's node_modules

4 participants