Files
twenty/packages/twenty-apps/examples/hello-world
Charles BochetandGitHub 0bb3660844 chore(twenty-sdk): shrink logic-function bundles via stubbing (#20033)
## Summary

Logic-function bundles produced by the SDK CLI were ~1.2 MB each (source
maps ~3.1 MB) because esbuild was inlining `twenty-sdk/define` and its
transitive dependencies (zod + locales, twenty-shared, etc.). Those
`define*` factories are pure build-time metadata used only by the
manifest extractor — the Lambda runtime only ever invokes
`default.config.handler`, so the factories are dead weight at runtime.

This PR shrinks the bundles to ~9.5 KB each (~99% reduction) without
changing runtime behaviour.

## What changes

- **Stub `twenty-sdk/define` at user-app build time.** New esbuild
plugin
(`packages/twenty-sdk/src/cli/utilities/build/common/plugins/stub-twenty-sdk-define.plugin.ts`)
intercepts every import of `twenty-sdk/define` during user-app builds
and replaces it with a tiny virtual module:
- Factory functions (`defineLogicFunction`,
`definePostInstallLogicFunction`, …) become `(config) => ({ success:
true, config, errors: [] })`.
  - Enums and helpers become `Proxy`-based no-ops.
- Wired into both the one-shot build (`build-application.ts`) and the
watcher (`esbuild-watcher.ts`), for logic functions and front
components.
- **New runtime barrel `twenty-sdk/logic-function`.** Re-exports only
the types logic-function authors need (`InstallPayload`, `RoutePayload`,
`CronPayload`, `DatabaseEventPayload`, `LogicFunctionConfig`,
`InputJsonSchema`, …). Compiled `.mjs` is 36 bytes. Wired into Vite,
Rollup `.d.ts` bundling, `package.json#exports`, and `typesVersions`.
- **Lint enforcement.** Added an oxlint `no-restricted-imports` rule
that forbids `twenty-shared` / `twenty-shared/*` imports from
`**/*.logic-function.ts` and `**/logic-functions/**/*.ts`, with a help
message pointing at the new barrel. Applied to the `create-twenty-app`
template and to `github-connector`, `hello-world`, `postcard`.
- **Migrated existing sources.** All logic-function files across
`community/{github-connector, apollo-enrich}`, `examples/{hello-world,
postcard}`, and `internal/{twenty-for-twenty, self-hosting, exa}` now
import types from `twenty-sdk/logic-function` instead of
`twenty-sdk/define` or `twenty-shared/*`. Renamed leftover
`InstallLogicFunctionPayload` references to `InstallPayload`.

## Why this is safe

- `define*` exports from `twenty-sdk/define` are metadata factories
whose call expressions are statically inspected by the manifest
extractor (`manifest-extract-config.ts`). They're never evaluated at
runtime — the Lambda executor only walks `default.config.handler`
(`logic-function-drivers/constants/executor/index.mjs`).
- The stub keeps the same call shape (`{ success, config, errors }`), so
any logic-function module that re-exports
`defineX(config).config.handler` still resolves to the user's handler at
runtime.
- Front-component bundles are unaffected by the stub because the
pre-existing JSX transform plugin
(`jsx-transform-to-remote-dom-worker-format-plugin.ts`) unwraps
`defineFrontComponent(...)` earlier in the pipeline. That's intentional
— front-component bloat is React/Preact, not in scope here.

## Measurements (github-connector)

| Asset | Before | After |
|---|---|---|
| `*.logic-function.mjs` | ~1.2 MB | ~9.5 KB |
| `*.logic-function.mjs.map` | ~3.1 MB | ~22 KB |
2026-04-24 17:51:35 +02:00
..
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00
2026-04-03 12:44:03 +00:00

This is a Twenty application project bootstrapped with create-twenty-app.

Getting Started

First, authenticate to your workspace:

yarn twenty remote add --api-url http://localhost:2020 --as local

Then, start development mode to sync your app and watch for changes:

yarn twenty dev

Open your Twenty instance and go to /settings/applications section to see the result.

Available Commands

Run yarn twenty help to list all available commands. Common commands:

# Remotes & Authentication
yarn twenty remote add --api-url http://localhost:2020 --as local     # Authenticate with Twenty
yarn twenty remote status         # Check auth status
yarn twenty remote switch         # Switch default remote
yarn twenty remote list           # List all configured remotes
yarn twenty remote remove <name>  # Remove a remote

# Application
yarn twenty dev        # Start dev mode (watch, build, sync, and auto-generate typed client)
yarn twenty add     # Add a new entity (object, field, function, front-component, role, view, navigation-menu-item)
yarn twenty logs  # Stream function logs
yarn twenty exec  # Execute a function with JSON payload
yarn twenty uninstall  # Uninstall app from workspace

Integration Tests

If your project includes the example integration test (src/__tests__/app-install.integration-test.ts), you can run it with:

# Make sure a Twenty server is running at http://localhost:3000
yarn test

The test builds and installs the app, then verifies it appears in the applications list. Test configuration (API URL and API key) is defined in vitest.config.ts.

LLMs instructions

Main docs and pitfalls are available in LLMS.md file.

Learn More

To learn more about Twenty applications, take a look at the following resources:

You can check out the Twenty GitHub repository - your feedback and contributions are welcome!