Skip to content

feat: add appkit codemod on-plugins-ready CLI#291

Merged
MarioCadenas merged 9 commits intomainfrom
feat/codemod-on-plugins-ready
Apr 27, 2026
Merged

feat: add appkit codemod on-plugins-ready CLI#291
MarioCadenas merged 9 commits intomainfrom
feat/codemod-on-plugins-ready

Conversation

@MarioCadenas
Copy link
Copy Markdown
Collaborator

@MarioCadenas MarioCadenas commented Apr 21, 2026

Summary

Adds appkit codemod on-plugins-ready CLI command to auto-migrate apps from the old autoStart/extend/start pattern to the new onPluginsReady callback.

Depends on #280.

Usage

npx appkit codemod on-plugins-ready              # dry-run, auto-detect
npx appkit codemod on-plugins-ready --write      # apply changes
npx appkit codemod on-plugins-ready --path file  # specific file

What it does

  • Pattern A (.then chain): Extracts callback body, removes .start(), injects as onPluginsReady property, preserves .catch() handlers (including arrow functions with parens)
  • Pattern B (await + imperative): Gathers extend/start calls, injects into onPluginsReady, removes standalone statements. Bails with warning for complex cases (non-server usage of appkit handle, multiple extend calls)
  • autoStart stripping: Removes autoStart: true/false from all server() configs, preserves other properties
  • File discovery: Auto-detects files importing createApp from @databricks/appkit
  • Idempotent: No-ops with friendly message if already migrated
  • Dry-run by default: --write flag to apply changes

Test plan

  • 9 tests covering both patterns, bail-outs, idempotency, autoStart stripping, arrow function catch handlers, multi-extend bail
  • Full suite passes (1595/1595)
  • Typecheck passes
  • Build passes

Demo

codemod-demo.mp4

@MarioCadenas MarioCadenas marked this pull request as ready for review April 21, 2026 15:58
Replace the post-await extend/start ceremony with a declarative
`customize` callback on createApp config. The callback runs after
plugin setup but before the server starts, giving access to the
full appkit handle for registering custom routes or async setup.

- Add `customize` option to createApp config
- Server start is now orchestrated by createApp (lookup by name)
- Remove `autoStart` from public API, ServerConfig, and manifest
- Remove `start()` from server plugin exports
- Remove autoStart guards from extend() and getServer()
- Remove ServerError.autoStartConflict()
- Migrate dev-playground, template, and all tests

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
… detection

Rename the lifecycle hook from `customize` to `onPluginsReady` to
clearly communicate when it fires (after plugins are ready, before
server starts).

Add `appkit codemod customize-callback` CLI command that auto-migrates
old autoStart/extend/start patterns to the new onPluginsReady callback.
Supports both .then() chain (Pattern A) and await + imperative
(Pattern B, with bail-out for complex cases).

Add runtime detection that throws helpful errors when users pass
autoStart to server() or call server.start() after upgrading,
directing them to run the codemod.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
The test fixture .ts files import @databricks/appkit which doesn't
exist in the shared package, causing tsc to fail in CI. Exclude
the fixtures directory from the shared tsconfig.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Remove the codemod CLI from this PR to keep the review focused
on the core lifecycle change. The codemod will land as a follow-up
with bug fixes from review.

Runtime detection (constructor autoStart throw + exports().start()
trap) stays since it's part of the migration story.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Log when the onPluginsReady hook starts and completes to aid
debugging in development mode.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Update runtime detection error messages to point users to
`npx appkit codemod on-plugins-ready` to match the hook name.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas MarioCadenas force-pushed the feat/customize-callback branch from 0e8847c to c03f8d0 Compare April 27, 2026 08:57
Add `appkit codemod on-plugins-ready` command that auto-migrates
old autoStart/extend/start patterns to the new onPluginsReady callback.

Handles Pattern A (.then chain) and Pattern B (await + imperative).
Bails with a warning for complex cases (non-server usage of appkit
handle, multiple extend calls).

Includes fixes from review:
- Use raw slice offset for brace matching (not trimmed)
- Use brace-aware parsing for .catch() handlers with arrow functions
- Bail out when multiple .extend() calls detected in Pattern B

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
- Remove entire `await appkit.server.start();` statements instead of
  just stripping `.start()` (which left dangling `await appkit.server;`)
- Detect async callbacks in .then() and emit `async onPluginsReady`
  so await expressions inside the body remain valid

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas MarioCadenas force-pushed the feat/codemod-on-plugins-ready branch from 31e6174 to 3d50cfa Compare April 27, 2026 09:02
Base automatically changed from feat/customize-callback to main April 27, 2026 12:49
@MarioCadenas MarioCadenas enabled auto-merge (squash) April 27, 2026 12:50
@MarioCadenas MarioCadenas merged commit f2f0504 into main Apr 27, 2026
7 checks passed
@MarioCadenas MarioCadenas deleted the feat/codemod-on-plugins-ready branch April 27, 2026 12:56
MarioCadenas added a commit that referenced this pull request Apr 27, 2026
`server({ autoStart: false }).then(appkit => appkit.server.extend(...).start())`
is gone — `createApp` now orchestrates server start itself, with the
post-setup hook surfaced as the `onPluginsReady` config callback.

Drop `autoStart: false`, hoist the `extend` block from the trailing
`.then` chain into `onPluginsReady`, and replace the dangling promise
with `.catch(console.error)` so unhandled rejections still surface.

Tracks #280 / #291 (autoStart removal + on-plugins-ready codemod).
MarioCadenas added a commit that referenced this pull request Apr 29, 2026
`server({ autoStart: false }).then(appkit => appkit.server.extend(...).start())`
is gone — `createApp` now orchestrates server start itself, with the
post-setup hook surfaced as the `onPluginsReady` config callback.

Drop `autoStart: false`, hoist the `extend` block from the trailing
`.then` chain into `onPluginsReady`, and replace the dangling promise
with `.catch(console.error)` so unhandled rejections still surface.

Tracks #280 / #291 (autoStart removal + on-plugins-ready codemod).
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