Skip to content

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Jan 31, 2026

The script that runs the api server in dev used on only restart the server when any of the files in the api workspace changes. I've now extended this logic to also watch and restart when workspace packages the api side uses changes

@netlify
Copy link

netlify bot commented Jan 31, 2026

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 651be9d
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/697fc3effe8eca0008d97f4d

@github-actions github-actions bot added this to the next-release milestone Jan 31, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 31, 2026

Greptile Overview

Greptile Summary

This PR extends the API dev watcher to also watch the source trees of workspace packages that the API depends on (via workspace:* deps), enabling rebuild/restart when those packages change. It introduces workspacePackages() to discover relevant package src/** globs and updates startWatch() to include them and broaden ignored paths.

Key integration points:

  • packages/api-server/src/workspacePackages.ts computes watch patterns from root workspaces + API package.json workspace deps.
  • packages/api-server/src/watch.ts adds those patterns to chokidar and keeps the existing build/restart + SDL validation flow intact.

Confidence Score: 3/5

  • This PR is generally safe to merge, but workspace watching may not work correctly on Windows or with common workspaces configurations.
  • Core behavior is additive and limited to dev watch paths/ignores, but there are two concrete correctness gaps: (1) generated glob patterns can be Windows-incompatible due to backslashes, and (2) workspaces detection only supports the array form, potentially disabling the feature in common monorepo setups.
  • packages/api-server/src/workspacePackages.ts; packages/api-server/src/watch.ts

Important Files Changed

Filename Overview
packages/api-server/src/watch.ts Adds workspace package globs to chokidar watch list and expands ignored paths; potential Windows glob normalization issue when mixing ensurePosixPath with ** patterns.
packages/api-server/src/workspacePackages.ts New helper to find API’s workspace:* dependencies and return glob watch patterns; workspace detection only supports array workspaces and path globs may be Windows-incompatible.

Sequence Diagram

sequenceDiagram
  participant Dev as Developer
  participant Watch as api-server/startWatch
  participant WP as workspacePackages()
  participant Ch as chokidar
  participant BM as BuildManager
  participant SM as serverManager
  participant SDL as loadAndValidateSdls

  Dev->>Watch: startWatch()
  Watch->>WP: compute workspace globs
  WP-->>Watch: [api/src, pkg/src/**]
  Watch->>Ch: chokidar.watch(paths, ignored)
  Ch-->>Watch: ready
  Watch->>BM: run(clean=true)
  BM->>SM: restartApiServer()
  Watch->>SDL: validate SDLs

  Ch-->>Watch: all(event, file)
  alt file includes .sdl
    Watch->>SDL: validate SDLs
    alt invalid
      Watch->>SM: killApiServer()
      Watch-->>Dev: log schema error
      Watch-->>Ch: return (skip rebuild)
    end
  end
  Watch->>BM: cancelScheduledBuild()
  alt event is add/unlink
    Watch->>BM: run(rebuild=false)
  else other events (change, etc.)
    Watch->>BM: run(rebuild=true)
  end
  BM->>SM: restartApiServer()
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 125 to 127
const watcher = chokidar.watch(
watchPaths.map((p) => ensurePosixPath(p)),
{
Copy link
Contributor

Choose a reason for hiding this comment

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

[P0] workspacePackages() can generate invalid chokidar globs on Windows due to path.join() backslashes.

workspacePackages() returns patterns like ...\\src\\**\\* on Windows, and startWatch() only normalizes watch roots with ensurePosixPath (which likely doesn’t treat ** globs specially). This can result in chokidar not matching any workspace package files on Windows.

Consider normalizing the returned patterns from workspacePackages() to POSIX (or returning absolute dirs and letting chokidar handle recursion) instead of mixing path.join + globs.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/api-server/src/watch.ts
Line: 125:127

Comment:
[P0] `workspacePackages()` can generate invalid chokidar globs on Windows due to `path.join()` backslashes.

`workspacePackages()` returns patterns like `...\\src\\**\\*` on Windows, and `startWatch()` only normalizes watch roots with `ensurePosixPath` (which likely doesn’t treat `**` globs specially). This can result in chokidar not matching any workspace package files on Windows.

Consider normalizing the returned patterns from `workspacePackages()` to POSIX (or returning absolute dirs and letting chokidar handle recursion) instead of mixing `path.join` + globs.

How can I resolve this? If you propose a fix, please make it concise.

@nx-cloud
Copy link

nx-cloud bot commented Jan 31, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 651be9d

Command Status Duration Result
nx run-many -t build ✅ Succeeded 3m 24s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-01 21:57:12 UTC

@Tobbe Tobbe merged commit a5b15d9 into main Feb 1, 2026
65 of 68 checks passed
@Tobbe Tobbe deleted the tobbe-feat-watch-packages-api branch February 1, 2026 22:06
@dosubot
Copy link

dosubot bot commented Feb 1, 2026

Related Documentation

No published documentation to review for changes on this repository.

Write your first living document

How did I do? Any feedback?  Join Discord

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

The changes in this PR are now available in 3.0.0-canary.13322+8fb222b6a

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