Skip to content

feat(ud): Phase 2, 3 and 4#1663

Open
Tobbe wants to merge 15 commits intomainfrom
tobbe-feat-ud-support-phase-2
Open

feat(ud): Phase 2, 3 and 4#1663
Tobbe wants to merge 15 commits intomainfrom
tobbe-feat-ud-support-phase-2

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Apr 22, 2026

I keep working towards universal-deploy support. To keep things runnable and verifiable this PR introduces a few temporary constructs that will be removed as we make progress. They're all clearly marked in both the overall plan document and in the code.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for cedarjs ready!

Name Link
🔨 Latest commit a731912
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69ea0f8c5ba7650008a3e72c
😎 Deploy Preview https://deploy-preview-1663--cedarjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR advances the Universal Deploy (UD) integration through phases 2–4: it introduces buildCedarDispatcher (rou3-based routing over Fetch-native handlers), a cedarDevDispatcherPlugin that replaces the old cedarWaitForApiServer middleware so standard Cedar apps no longer spawn a separate API process during dev, a cedarUniversalDeployPlugin for Vite builds, and wires cedar build api / cedar serve api to emit and launch the self-contained srvx entry at api/dist/ud/index.js.

The previously flagged race condition in the dev dispatcher (stale cachedDispatcher overwrite) has been addressed with a generation counter. The ALL_HTTP_METHODS coverage for non-GraphQL routes is correct.

Confidence Score: 5/5

Safe to merge; all remaining findings are P2 doc/style suggestions with no blocking logic errors.

Prior P1 concerns (race condition, ALL_HTTP_METHODS coverage) are resolved in this PR. The two open items are P2: a minor port-exclusion gap in the custom-server dev lane (unlikely in practice), and stale entries in the project overview doc.

docs/implementation-docs/2026-03-26-cedarjs-project-overview.md (DEV/BUILD section), packages/cli/src/commands/dev/devHandler.ts (web port exclusion)

Important Files Changed

Filename Overview
packages/api-server/src/udDispatcher.ts New aggregate dispatcher using rou3 + fast-glob; correctly uses ALL_HTTP_METHODS for non-GraphQL functions and tries/catches errors in the fetch handler
packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts New Vite dev middleware that serves API requests inline; addresses the race condition from a prior review via a generation counter; no blocking issues
packages/cli/src/commands/dev/devHandler.ts Refactored to skip separate API process for standard apps; API port exclusion was dropped from web free-port search in the custom-server lane
packages/cli/src/commands/serve.ts Adds --ud flag (default true) to cedar serve api; forks the pre-built UD entry with PORT/HOST env vars and graceful exit handling
packages/vite/src/buildUDApiServer.ts Self-contained Vite server build that emits api/dist/ud/index.js; dynamic imports keep cold-start cost low
docs/implementation-docs/2026-03-26-cedarjs-project-overview.md api-server and Conventions rows updated correctly, but the DEV/BUILD section (cedar dev flow, build sequence, Vite plugins list) is now factually stale
packages/api-server/src/tests/udFetchable.test.ts Good unit tests covering handler delegation, response passthrough, query params, cookies, and default params

Reviews (12): Last reviewed commit: "review fixes" | Re-trigger Greptile

Comment thread packages/api-server/src/createUDServer.ts Outdated
Comment thread packages/api-server/src/createUDServer.ts
Comment thread packages/api-server/src/createUDServer.ts
Comment thread packages/api-server/src/createUDServer.ts
Comment thread yarn.lock Outdated
Comment thread packages/graphql-server/src/types.ts
@github-actions github-actions Bot added this to the next-release milestone Apr 22, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 22, 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 a731912

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ❌ Failed 3m 27s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded 4m 28s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-23 12:58:28 UTC

@Tobbe Tobbe changed the title feat(ud): Phase 2 feat(ud): Phase 2 and 3 Apr 22, 2026
@Tobbe
Copy link
Copy Markdown
Member Author

Tobbe commented Apr 22, 2026

@greptileai you said "This PR adds Phase 2 of the Universal Deploy integration". What's left to do for Phase 3, to also be able to include that in this PR?

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

According to the implementation plan, Phase 3's exit criteria are:

  1. Cedar can run in production on Node without Fastify — the createUDServer (srvx-based) covers this for the standalone UD server, but the plan specifically calls for @universal-deploy/adapter-node to be the mechanism, not a custom srvx server.

  2. Cedar's server entries registered in the UD store at build time — the Vite plugin does call addEntry(), but the virtual module it returns is a 501 stub:

    // vite-plugin-cedar-universal-deploy.ts
    return new Response(
      'Cedar API virtual entry: not yet implemented (Phase 5)',
      { status: 501 },
    )

    This needs to be replaced with a real Fetchable that dispatches to the discovered Cedar API functions.

  3. yarn cedar serve no longer depends on Fastify — not addressed yet.

So concretely, what's left:

  • Replace the 501 stub in vite-plugin-cedar-universal-deploy.ts's load() with a real Cedar API dispatcher. The route discovery logic already exists in createUDServer.ts — the pieces are there, they just need to be wired into the virtual module's fetch handler.
  • Validate @universal-deploy/adapter-node end-to-end (the plan calls this out explicitly as a Phase 3 deliverable).
  • Wire yarn cedar serve to delegate to the UD node adapter rather than Fastify.

The plan notes that Phase 3's real Fetchable implementation depends on the Phase 2 route manifest — which is partly why the PR punted it to Phase 5. But since Phase 2 route discovery is also in this PR (createUDServer handles it at runtime), you have enough to at least make the virtual module non-stub and do the end-to-end validation.

Comment thread packages/api-server/src/udDispatcher.ts Outdated
@Tobbe Tobbe changed the title feat(ud): Phase 2 and 3 feat(ud): Phase 2, 3 and 4 Apr 23, 2026
Comment thread packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts
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.

1 participant