Skip to content

feat: add appkit codemod customize-callback CLI#290

Closed
MarioCadenas wants to merge 5 commits intofeat/customize-callbackfrom
feat/codemod-customize-callback
Closed

feat: add appkit codemod customize-callback CLI#290
MarioCadenas wants to merge 5 commits intofeat/customize-callbackfrom
feat/codemod-customize-callback

Conversation

@MarioCadenas
Copy link
Copy Markdown
Collaborator

Summary

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

Depends on #280.

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 in server/, src/, root
  • Idempotent: No-ops with friendly message if already migrated
  • Dry-run by default: --write flag to apply changes

Usage

npx appkit codemod customize-callback              # dry-run, auto-detect
npx appkit codemod customize-callback --write      # apply changes
npx appkit codemod customize-callback --path file  # specific file

Bugs fixed from review

  • H1: Fixed bodyOpenBrace offset calculation after .trim() — was using trimmed string index as offset into original content
  • H2: Fixed .catch() handler parsing — now uses brace-aware findMatchingClose instead of regex, correctly handles .catch((err) => console.error(err))
  • M1: Pattern B now bails with warning when multiple .extend() calls are detected

Test plan

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

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>
Add `appkit codemod customize-callback` 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).

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>
@MarioCadenas MarioCadenas force-pushed the feat/customize-callback branch from 023d7e7 to 25b8c60 Compare April 21, 2026 15:21
@MarioCadenas
Copy link
Copy Markdown
Collaborator Author

Superseded by new PR with renamed codemod (customize-callback -> on-plugins-ready).

@MarioCadenas MarioCadenas deleted the feat/codemod-customize-callback branch April 21, 2026 15:44
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