[APPS] Support uploading backend functions to app definitions#284
Draft
sdkennedy2 wants to merge 6 commits intomasterfrom
Draft
[APPS] Support uploading backend functions to app definitions#284sdkennedy2 wants to merge 6 commits intomasterfrom
sdkennedy2 wants to merge 6 commits intomasterfrom
Conversation
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
…l, restore dev-time package exports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
High code apps need the ability to define backend functions that get bundled and published to the app definition after upload. This enables server-side logic to be co-located with the app's frontend code and automatically deployed as part of the build process.
See RFC: Backend Functions for the full design.
Changes
Added a complete backend functions pipeline that runs during the build:
Discovery — scans a configurable
backendDir(default:backend/) for function modules. Supports both single-file (backend/myFunc.ts) and directory (backend/myFunc/index.ts) patterns.Bundling — each discovered function is bundled with esbuild into a single self-contained file. Everything is inlined with no externals, since the execution environment does not support
requireorimportat runtime. If@datadog/action-catalogis installed, itssetExecuteActionImplementationexport is forced into the bundle.Transformation — bundled code is wrapped in the Action Platform script format with a
main($)entry point that registers the$.Actions-basedexecuteActionimplementation and invokes the function with template-resolved args.Archive inclusion — transformed functions are written to temp files and included in the upload zip archive alongside frontend assets. Frontend assets are namespaced under a configurable
frontendDir(default:frontend/) and backend functions underbackend/within the archive. The archive is uploaded via the existingPOST .../uploadendpoint — no separate API call is needed.Shared constants (
ACTION_CATALOG_EXPORT_LINE,SET_EXECUTE_ACTION_SNIPPET) are extracted intobackend-shared.tsfor reuse by the upcoming dev server middleware.New configuration options:
Design Decisions
Why esbuild as a direct dependency instead of reusing the user's bundler?
We considered reusing the user's bundler (webpack/rollup/vite/rspack/esbuild) to avoid introducing a new dependency. We decided against it because:
name,version,outDir) to plugins, not the bundler instance. Threading the instance through would require factory-level changes.asyncTrueEnd, after the user's bundler has finished.esbuild is lightweight, has a simple programmatic API, and is already a transitive dependency for most users (vite ships it). The backend function bundling is a distinct concern from the frontend build — a dedicated tool is simpler and more maintainable.
No externals — The execution environment does not support
importorrequireat runtime, so everything must be inlined into a single bundle per function.QA Instructions
backend/directory containing one or more function modulesAPPS_UPLOAD_ASSETS=1and valid API/app keysfrontend/andbackend/directories with the expected filesBlast Radius
backend/directory — no impact on existing apps without backend functionsfrontendDirprefixing changes the archive structure for all apps (assets now live underfrontend/instead of the root)Documentation