Skip to content

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

Open
MarioCadenas wants to merge 2 commits intofeat/customize-callbackfrom
feat/codemod-on-plugins-ready
Open

feat: add appkit codemod on-plugins-ready CLI#291
MarioCadenas wants to merge 2 commits intofeat/customize-callbackfrom
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

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 marked this pull request as ready for review April 21, 2026 15:58
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