Skip to content

fix: pass rootDirectory in projectSettings for monorepo deployments - #348

Open
Fetten wants to merge 11 commits into
amondnet:masterfrom
Fetten:fix/monorepo-project-settings
Open

fix: pass rootDirectory in projectSettings for monorepo deployments#348
Fetten wants to merge 11 commits into
amondnet:masterfrom
Fetten:fix/monorepo-project-settings

Conversation

@Fetten

@Fetten Fetten commented Apr 22, 2026

Copy link
Copy Markdown

Summary

When deploying monorepos via the API, the root-directory input is only passed
to @vercel/client's clientOptions (local file hashing) but never included
in the POST /v13/deployments body as projectSettings.rootDirectory.

Without this, Vercel's build server falls back to the repo root, fails to detect
the correct package manager (e.g. pnpm), and uses npm — which breaks on
workspace:* protocol with EUNSUPPORTEDPROTOCOL.

Changes

  • Pass projectSettings.rootDirectory in the deployment options when
    root-directory is set
  • Add new source-files-outside-root-directory input (default: true) to
    support monorepos where dependencies live outside the root directory
  • Add unit tests for the new behavior

Test plan

  • Existing unit tests pass (196/196)
  • Action builds successfully
  • Tested with a real monorepo deployment (pnpm + turborepo)

Summary by cubic

Fixes monorepo deployments by sending projectSettings.rootDirectory and optionally sourceFilesOutsideRootDirectory, and adds a node-version input to control Vercel’s Node.js version.

  • Bug Fixes

    • Include projectSettings.rootDirectory in POST /v13/deployments to avoid falling back to the repo root and mis-detecting the package manager.
    • Always apply action inputs even when vercel.json exists; include rootDirectory and/or sourceFilesOutsideRootDirectory only when set, and treat them independently.
  • New Features

    • Added node-version input to set projectSettings.nodeVersion; the input takes precedence, and when unset falls back to package.json engines.node.
    • Added source-files-outside-root-directory input (default false) for monorepos with shared packages outside the root.

Written for commit 7fa3d7a. Summary will update on new commits. Review in cubic

The root-directory input was only passed to @vercel/client's
clientOptions but never included in the POST /v13/deployments body
as projectSettings. Without this, Vercel's build might fail to
detect the correct package manager and break e.g. with pnpm when
using the `workspace:*` protocol.

This adds `projectSettings.rootDirectory` and
`sourceFilesOutsideRootDirectory` to the deployment options
when `root-directory` is set.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces the source-files-outside-root-directory configuration option to better support monorepo deployments by including projectSettings in the Vercel API request. The changes span the action metadata, configuration parsing, type definitions, and the API client logic. A review comment identifies an inconsistency in a test helper where the default value for the new setting does not match the production default, which should be corrected to ensure tests accurately reflect the action's behavior.

Comment thread src/__tests__/vercel-api.test.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 9 files

Requires human review: This PR modifies the core deployment request shape sent to the Vercel API by adding projectSettings. Changes to API request payloads in critical paths require human verification.

Architecture diagram
sequenceDiagram
    participant Runner as GitHub Runner (Action)
    participant Config as getActionConfig()
    participant Client as VercelApiClient
    participant SDK as @vercel/client
    participant VercelAPI as Vercel API (POST /v13/deployments)
    participant Builder as Vercel Build Server

    Note over Runner,Builder: Monorepo Deployment Flow

    Runner->>Config: Load Action Inputs
    Config-->>Runner: rootDirectory, sourceFilesOutsideRootDirectory (NEW)

    Runner->>Client: deploy(config)
    
    Client->>Client: buildDeploymentOptions()
    alt rootDirectory is set
        Note over Client: NEW: Include projectSettings in API payload
        Client->>Client: projectSettings.rootDirectory = config.rootDirectory
        Client->>Client: projectSettings.sourceFilesOutsideRootDirectory = ...
    end

    Client->>SDK: createDeployment(path, options)
    SDK->>VercelAPI: POST /v13/deployments
    Note right of VercelAPI: CHANGED: Body now contains projectSettings

    VercelAPI-->>SDK: 200 OK (Deployment Created)
    SDK-->>Client: Deployment Events
    
    Note over Builder: Build Lifecycle Starts
    VercelAPI->>Builder: Trigger Build
    
    alt projectSettings.rootDirectory provided
        Builder->>Builder: Navigate to rootDirectory (e.g., apps/web)
        Builder->>Builder: Detect Package Manager (e.g., pnpm)
        Builder->>Builder: Run build (Correct workspace context)
    else projectSettings.rootDirectory missing (Old Behavior)
        Builder->>Builder: Fallback to repository root
        Builder->>Builder: Default to npm (May fail pnpm workspaces)
    end

    Builder-->>VercelAPI: Build Status update
    VercelAPI-->>Runner: Deployment Ready
Loading

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Auto-approved: Fixes monorepo deployments by passing projectSettings to the Vercel API. The change is isolated, includes unit tests, and maintains backward compatibility for non-monorepo projects.

@Fetten
Fetten marked this pull request as draft April 22, 2026 10:43
@Fetten
Fetten marked this pull request as ready for review April 22, 2026 11:08

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/vercel-api.ts">

<violation number="1" location="src/vercel-api.ts:121">
P2: `sourceFilesOutsideRootDirectory` is hardcoded to `true`, so the `source-files-outside-root-directory` input/config value is ignored whenever `rootDirectory` is set.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Runner as GitHub Action Runner
    participant Client as @vercel/client (Local)
    participant API as Vercel Deployment API
    participant Builder as Vercel Build Server

    Note over Runner,Client: Initialization & Config
    Runner->>Runner: getActionConfig()
    Note right of Runner: NEW: Read source-files-outside-root-directory

    Runner->>Client: createDeployment(clientOptions)
    Note right of Client: Uses root-directory for<br/>local file hashing/upload

    Note over Runner,API: Deployment Creation Flow

    Runner->>Runner: CHANGED: buildDeploymentOptions()
    
    alt root-directory is provided
        Runner->>Runner: NEW: Construct projectSettings object
        Note right of Runner: Set rootDirectory & <br/>sourceFilesOutsideRootDirectory
    else root-directory is empty
        Runner->>Runner: Omit projectSettings
    end

    Runner->>API: POST /v13/deployments
    Note right of API: Payload includes CHANGED:<br/>projectSettings.rootDirectory

    API->>Builder: Trigger Remote Build
    
    Note over Builder: Remote Execution Environment
    
    alt projectSettings.rootDirectory present
        Builder->>Builder: CHANGED: Switch context to rootDirectory
        Builder->>Builder: Detect package manager (e.g., pnpm)
        Builder->>Builder: Resolve workspace:* dependencies
    else No projectSettings
        Builder->>Builder: Fallback to repository root
        Builder->>Builder: Default package manager (npm)
        Note over Builder: May fail on monorepo structures
    end

    Builder-->>API: Build Status
    API-->>Runner: Deployment Events (ready/error)
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/vercel-api.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 8 files (changes from recent commits).

Auto-approved: Fixes monorepo deployments by correctly passing rootDirectory to the Vercel API. The change is well-isolated, includes unit tests, and follows Vercel's API requirements.

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 4 files (changes from recent commits).

Auto-approved: Fixes monorepo deployments by correctly passing rootDirectory and sourceFilesOutsideRootDirectory to the Vercel API. Includes unit tests and documentation updates.

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Auto-approved: This PR fixes monorepo deployments by correctly passing projectSettings to the Vercel API. It is well-tested, documented, and the logic changes are isolated and safe.

@amondnet

Copy link
Copy Markdown
Owner

/gemini review

@amondnet amondnet self-assigned this Apr 23, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for monorepos by adding a new source-files-outside-root-directory input, which allows Vercel to resolve dependencies located outside the project's root directory. The changes include updates to the README, action configuration, and the Vercel API client to pass these settings. Additionally, the PR refactors test helpers to reduce code duplication across the test suite. Review feedback suggests making the projectSettings object in the API client conditional to avoid sending empty objects for standard deployments, which would also require updating the corresponding test expectations.

Comment thread src/vercel-api.ts Outdated
},
gitMetadata: buildGitMetadata(deployContext),
autoAssignCustomDomains: config.autoAssignCustomDomains,
projectSettings: {},

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.

medium

Initializing projectSettings as an empty object means it will be sent in every deployment request, even for non-monorepo projects. It is safer to only include this optional field when monorepo settings are actually provided to avoid potential side effects with the Vercel API's handling of project-level overrides.

Comment thread src/vercel-api.ts Outdated
Comment on lines +115 to +120
if (config.rootDirectory) {
options.projectSettings!.rootDirectory = config.rootDirectory
}
if (config.sourceFilesOutsideRootDirectory) {
options.projectSettings!.sourceFilesOutsideRootDirectory = true
}

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.

medium

To avoid sending an empty projectSettings object for standard deployments, consider initializing it conditionally only when rootDirectory or sourceFilesOutsideRootDirectory are present.

  if (config.rootDirectory || config.sourceFilesOutsideRootDirectory) {
    options.projectSettings = {}
    if (config.rootDirectory) {
      options.projectSettings.rootDirectory = config.rootDirectory
    }
    if (config.sourceFilesOutsideRootDirectory) {
      options.projectSettings.sourceFilesOutsideRootDirectory = true
    }
  }

Comment thread src/__tests__/vercel-api.test.ts Outdated
{
name: 'empty when neither is set',
overrides: { rootDirectory: '', sourceFilesOutsideRootDirectory: false },
expected: {},

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.

medium

If projectSettings is made conditional in the API client, this test expectation should be updated to undefined to reflect that the field is omitted when no monorepo settings are provided.

Suggested change
expected: {},
expected: undefined,

@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Deploy preview for file ready!

Project:file
Status: ✅  Deploy successful!
Preview URL:https://team-scope-test-a5rylxfkd-dietfriends.vercel.app
Latest Commit:f58f5c5
Inspect:View deployment

Deployed with vercel-action

@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Deploy preview for express-basic-auth ready!

Project:express-basic-auth
Status: ✅  Deploy successful!
Preview URL:https://express-basic-auth-l8o1bef1z-minsu-lees-projects-b1e388b7.vercel.app
Latest Commit:f58f5c5
Inspect:View deployment

Deployed with vercel-action

@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Deploy preview for static ready!

Project:static
Status: ✅  Deploy successful!
Preview URL:https://zeit-now-deployment-action-example-angular-kjijhdrhh.vercel.app
Latest Commit:f58f5c5
Alias:https://staging.static.vercel-action.amond.dev
Alias:https://pr-348.static.vercel-action.amond.dev
Inspect:View deployment

Deployed with vercel-action

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 4 files (changes from recent commits).

Auto-approved: Safe fix for monorepo deployments; it correctly passes existing and new configuration fields to the Vercel API. Includes updated documentation and comprehensive unit tests.

Fetten added 3 commits April 23, 2026 21:02
…ect-settings

# Conflicts:
#	dist/index.js
#	dist/index.js.map
#	src/__tests__/vercel-api.test.ts
#	src/__tests__/vercel.test.ts
#	src/vercel-api.ts
@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 12 files (changes from recent commits).

Auto-approved: Fixes a bug in monorepo deployments by correctly passing project settings (rootDirectory, nodeVersion) to the Vercel API. Includes thorough unit tests and documentation updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants