Skip to content

predeploy hooks for every codebase run when --only lists multiple functions in the same codebase #11475

Open

Description

@samuel-pp

[REQUIRED] Environment info

firebase-tools: 15.17.0

Platform:

macOS (logic is in the CLI and is not platform-specific). Reproduced from current master: src/deploy/lifecycleHooks.ts, getReleventConfigs.

[REQUIRED] Test case

firebase.json with two function codebases:

{
  "functions": [
    {
      "source": "b",
      "codebase": "b",
      "predeploy": ["echo predeploy b"]
    },
    {
      "source": "a",
      "codebase": "a",
      "predeploy": ["echo predeploy a"]
    }
  ]
}

[REQUIRED] Steps to reproduce

Deploy two functions that belong to the same codebase in one command:

firebase deploy --only "functions:a:a-test1,functions:a:a-test2" --project <project-id> --force

These commands only run the a predeploy hook:

firebase deploy --only "functions:a:a-test1" --project <project-id> --force
firebase deploy --only "functions:a" --project <project-id> --force

[REQUIRED] Expected behavior

--only names one codebase, so only that codebase's predeploy runs:

predeploy a

[REQUIRED] Actual behavior

Every codebase predeploy runs:

predeploy b
predeploy a

In a project where the other codebases use npm --prefix "$RESOURCE_DIR" ci, those installs run even though the deploy filter is only functions:a:....

Cause

getReleventConfigs splits --only into one entry per function, then marks a match with Array.find:

const found = onlyTargets.find(
  (individualOnly) => config.codebase === individualOnly.split(":")[0],
);
if (found) {
  onlyConfigs.push(config);
  matched[found] = true;
}

a is visited once, so only the first filter (a:a-test1) is set to true. a:a-test2 stays false.

The fallback then treats any unmatched filter as a function deployed without a codebase, and runs lifecycle hooks for every codebase:

if (!Object.values(matched).every((matched) => matched)) {
  onlyConfigs = targetConfigs;
}

Two functions in different codebases do not hit this, because each codebase marks its own first filter. Two or more functions in the same codebase do.

Suggested fix

When a codebase matches, mark every --only filter with that codebase prefix, not only the first find result. If every filter's codebase is known, keep onlyConfigs limited to those codebases.

Activity

  1. aalej commented on Nov 10, 2026

    @aalej
    Contributor

    Thanks for the detailed report and for taking the time to look through the source code, @samuel-pp! I think your observations are correct, because we use Array.find() in getReleventConfigs, it stops at the first match. The subsequent targets are left as false, triggering the fallback that runs all hooks.

    I am able to reproduce the issue, deploying a single function in a codebase or a single codebase works as expected. However, as you mentioned, deploying multiple functions on the same codebase triggers this issue

    Running a command with multiple filters like firebase deploy --dry-run --only "functions:codebase-a:helloWorldA_1" --project PROJECT_ID, will trigger the predeploy script of another codebase

    $ firebase deploy --dry-run --only "functions:codebase-a:helloWorldA_1,functions:codebase-a:helloWorldA_2" --project PROJECT_ID
    
    === Deploying to 'PROJECT_ID'...
    
    i  deploying functions
    Running command: echo "hello from codebase-a"
    hello from codebase-a
    ✔  functions: Finished running predeploy script.
    Running command: echo "hello from codebase-b"
    hello from codebase-b
    

    However a single codebase or function does not trigger this behavior

    $ firebase deploy --dry-run --only "functions:codebase-a:helloWorldA_1" --project PROJECT_ID
    
    === Deploying to 'PROEJCT_ID'...
    
    i  deploying functions
    Running command: echo "hello from codebase-a"
    hello from codebase-a
    ✔  functions: Finished running predeploy script.
    

    I'll check this with our engineering team and mark this as reproducible. Since it looks like you've identified the cause, if you're interested, feel free to submit a PR for this! Otherwise someone from our engineering team should be able to take a look shortly

    sharing mcve here - https://github.com/aalej/issues-11475

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions