webiny-v5-to-v6-migration
它能做什么
这个技能向你的 AI 展示如何把代码从 Webiny 较旧的插件方式迁移到当前基于功能的设计。适用于将 v5 项目升级到 v6 的开发者。
适用场景
- ✓将 v5 插件迁移为 v6 功能的时候。
- ✓较旧的上下文插件需要改为注入服务时。
- ✓v5 事件订阅需要改为 v6 事件处理器的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/v5-to-v6-migration/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我把这个提供翻译服务的 v5 上下文插件转换为 v6 注入服务。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能提供 v5 与 v6 的对照写法,例如把上下文插件改为带实现的抽象,以及把事件订阅改为事件处理器。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
v5 → v6 Migration Patterns
Overview
v6 replaces v5's plugin-based architecture with feature-based DI. The key shifts:
| v5 Concept | v6 Equivalent |
|---|---|
ContextPlugin |
createAbstraction + createImplementation (Service) |
| Plugin array | createFeature + container.register() |
context.myService |
DI injection via constructor |
onEntryAfterCreate.subscribe() |
EventHandler feature |
new GraphQLSchemaPlugin() |
GraphQLSchemaFactory.createImplementation() |
Pattern 1: Context Plugin → DI Service
v5
new ContextPlugin(async context => {
context.lingotekService = {
translate: async (docId, locale) => {
/* ... */
},
getStatus: async docId => {
/* ... */
},
deleteProject: async projectId => {
/* ... */
}
};
});
v6
// features/lingotekService/abstractions.ts
import { createAbstraction } from "webiny/api";
export interface ILingotekService {
translate(docId: string, locale: string): Promise<Result<void, Error>>;
getStatus(docId: string): Promise<Result<TranslationStatus, Error>>;
deleteProject(projectId: string): Promise<Result<void, Error>>;
}
export const LingotekService = createAbstraction<ILingotekService>("MyExt/LingotekService");
export namespace LingotekService {
export type Interface = ILingotekService;
}
// features/lingotekService/LingotekService.ts
class LingotekServiceImpl implements LingotekService.Interface {
constructor(private buildParams: BuildParams.Interface) {}
async translate(docId: string, locale: string) {
/* ... */
}
async getStatus(docId: string) {
/* ... */
}
async deleteProject(projectId: string) {
/* ... */
}
}
export default LingotekService.createImplementation({
implementation: LingotekServiceImpl,
dependencies: [BuildParams]
});
// features/lingotekService/feature.ts
export const LingotekServiceFeature = createFeature({
name: "LingotekService",
register(container) {
container.register(LingotekServiceImpl).inSingletonScope();
}
});
Key difference: v5 attaches to context object. v6 uses DI — consumers declare the service as a constructor dependency.
Pattern 2: Event Subscription → EventHandler Feature
v5
context.cms.onEntryAfterCreate.subscribe(async params => {
if (params.model.modelId !== "myModel") return;
await doSomething(params.entry);
});
v6
// features/syncOnCreate/EntryAfterCreateHandler.ts
import { EntryAfterCreateEventHandler } from "webiny/api/cms/entry";
import { LingotekService } from "../lingotekService/abstractions.js";
import { MY_MODEL_ID } from "~/shared/constants.js";
class SyncOnCreateHandler implements EntryAfterCreateEventHandler.Interface {
constructor(private lingotekService: LingotekService.Interface) {}
async handle(event: EntryAfterCreateEventHandler.Event) {
const { entry, model } = event.payload;
if (model.modelId !== MY_MODEL_ID) return;
await this.lingotekService.translate(entry.entryId, "en");
}
}
export default EntryAfterCreateEventHandler.createImplementation({
implementation: SyncOnCreateHandler,
dependencies: [LingotekService]
});
// features/syncOnCreate/feature.ts
export const SyncOnCreateFeature = createFeature({
name: "SyncOnCreate",
register(container) {
container.register(SyncOnCreateHandler);
}
});
Key differences:
- Feature directory is named by business capability (
syncOnCreate), not by event name - Handler is a thin orchestrator — business logic lives in the injected service
- Must filter by
model.modelId— handler fires for ALL models
Pattern 3: Plugin Array → Feature Registration
v5
export default () => [
new GraphQLSchemaPlugin({ ... }),
new ContextPlugin(async ctx => { ... }),
myModelPlugin,
eventSubscriptionPlugin
];
v6
// api/Extension.ts
import { createFeature } from "webiny/api";
export const Extension = createFeature({
name: "MyExtension",
register(container) {
container.register(MyModel);
container.register(MyGraphQLSchema);
SyncOnCreateFeature.register(container);
常见问题
什么替代了上下文插件?
带有实现的抽象,通过依赖注入提供。
什么替代了 GraphQL schema 插件?
根据该技能的表格,是 GraphQL schema 工厂实现。
它只适用于 AI 智能体吗?
该技能是为执行迁移的 AI 智能体编写的,但人也可以遵循同样的模式。
详情
作者的原始描述
Migration patterns for converting v5 Webiny code to v6 architecture. Use this skill when migrating existing v5 plugins to v6 features, converting context plugins to DI services, adapting v5 event subscriptions to v6 EventHandlers, or understanding how v5 patterns translate to v6. Targeted at AI agents performing migrations.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12591
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。