Skip to content

fix(functions/emulator): hidden-path ignore relative to functionsDir#10410

Open
kyungseopk1m wants to merge 1 commit intofirebase:mainfrom
kyungseopk1m:fix/functions-watcher-ignore-relative-path
Open

fix(functions/emulator): hidden-path ignore relative to functionsDir#10410
kyungseopk1m wants to merge 1 commit intofirebase:mainfrom
kyungseopk1m:fix/functions-watcher-ignore-relative-path

Conversation

@kyungseopk1m
Copy link
Copy Markdown

Description

Fixes #10187.

FunctionsEmulator configures chokidar's ignored option with a hidden-segment regex (/(^|[\/\\])\../) that was evaluated against the absolute file path. When the project lives under a dot-prefixed ancestor directory (for example .worktrees/, .cache/, or any other ancestor starting with .), that regex matches the ancestor segment of every path and the watcher silently filters out every change. The result is that saving a source file never triggers a reload.

This change extracts a shouldIgnoreWatchPath(functionsDir, filePath) helper in functionsEmulatorShared.ts that computes path.relative(functionsDir, filePath) and only tests the hidden-segment regex against the relative path. The matcher in functionsEmulator.ts uses that helper in place of the bare regex.

Behavior is preserved for the common case — files like .git/HEAD, .dart_tool/…, or .cache/… inside the watched directory are still ignored, because their relative path starts with a dot. The remaining built-in ignore patterns (.log files, node_modules, venv) and any user-supplied backend.ignore globs are unchanged.

Scenarios Tested

Added unit tests in src/emulator/functionsEmulatorShared.spec.ts covering:

  • Hidden file inside the functions directory (.git/HEAD) is still ignored.
  • Hidden segment nested within the functions directory (src/.cache/module.js) is still ignored.
  • Regular source file under a dot-prefixed ancestor (/home/user/.worktrees/project/functions/src/index.ts) is not ignored — the regression fix.
  • Regular nested source file (lib/handlers/index.js) is not ignored.
  • The functions directory itself is not ignored.
  • No-op regression: a plain functions directory without any dot-prefixed ancestor still ignores .git/HEAD and still watches src/index.ts.

Also verified:

  • npm run lint:quiet passes (eslint + prettier).
  • npm run build passes.
  • npx mocha src/emulator/functionsEmulatorShared.spec.ts — 20 passing (13 existing + 7 new).

Sample Commands

Not applicable — internal emulator behavior, no public CLI surface change.

… functionsDir

chokidar's ignored matcher was evaluating the hidden-segment regex against
the absolute file path.  When the project was located under a dot-prefixed
ancestor directory (e.g. `.worktrees/`, `.cache/`), every file change was
silently filtered out and the emulator never reloaded triggers.

Match against the path relative to `backend.functionsDir` instead so that
the hidden-segment rule only hides dot-prefixed entries inside the watched
directory.  The other built-in ignore patterns and user-supplied
`backend.ignore` globs are unchanged.

Fixes firebase#10187
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 fixes a bug in the Functions emulator where the file watcher would silently ignore changes if the project path contained a dot-prefixed ancestor directory (e.g., .worktrees/). The fix introduces a shouldIgnoreWatchPath utility that evaluates file paths relative to the functions directory before checking for hidden segments, ensuring that hidden ancestors do not trigger the ignore rule. Comprehensive unit tests were added to src/emulator/functionsEmulatorShared.spec.ts to cover various path scenarios. I have no feedback to provide.

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.

Functions emulator file watcher silently ignores changes in git worktrees

2 participants