Skip to content

Commit

Permalink
docs(migration): add description for plugin breakchange (#1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and dead-horse committed Dec 5, 2017
1 parent a2788a8 commit ae87460
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion docs/source/zh-cn/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ title: Egg@2 升级指南
Egg 的理念之一是`渐进式增强`,故我们为开发者提供`渐进升级`的体验。

- [快速升级](#快速升级)
- [插件变更说明](#插件变更说明)
- [进一步升级](#进一步升级)
- [针对`插件开发者`的升级指南](#插件升级)

Expand All @@ -29,7 +30,59 @@ Egg 的理念之一是`渐进式增强`,故我们为开发者提供`渐进升
- 检查相关插件是否发布新版本(可选)。
- 重新安装依赖,跑单元测试。

**搞定!不需要修改任何一行代码,就已经完成了升级。**
**搞定!几乎不需要修改任何一行代码,就已经完成了升级。**


## 插件变更说明

### egg-multipart

`yield parts` 需修改为 `await parts()``yield parts()`

```js
// old
const parts = ctx.multipart();
while ((part = yield parts) != null) {
// do something
}

// yield parts() also work
while ((part = yield parts()) != null) {
// do something
}

// new
const parts = ctx.multipart();
while ((part = await parts()) != null) {
// do something
}
```

- [egg-multipart#upload-multiple-files](https:/eggjs/egg-multipart#upload-multiple-files)

### egg-userrole

不再兼容 1.x 形式的 role 定义,因为 koa-roles 已经无法兼容了。
请求上下文 `Context` 从 this 传入改成了第一个参数 `ctx` 传入,原有的 `scope` 变成了第二个参数。

```js
// old
app.role.use('user', function() {
return !!this.user;
});

// new
app.role.use((ctx, scope) => {
return !!ctx.user
});

app.role.use('user', ctx => {
return !!ctx.user;
});
```

- [koajs/koa-roles#13](https:/koajs/koa-roles/pull/13)
- [eggjs/egg-userrole#9](https:/eggjs/egg-userrole/pull/9)

## 进一步升级

Expand Down Expand Up @@ -233,8 +286,10 @@ task = app.toAsyncFunction(schedule.task);
- 修改 `engines.node``>=8.0.0`
- 修改 `ci.version``8, 9`, 并重新安装依赖以便生成新的 travis 配置文件。
- 修改 `README.md` 的示例为 async function。
- 编写升级指引。
- 修改 `test/fixtures` 为 async function,可选,建议分开另一个 PR 方便 Review。


一般还会需要继续维护上一个版本,故需要:
- 对上一个版本建立一个 `1.x` 这类的 branch 分支
- 修改上一个版本的 `package.json``publishConfig.tag``release-1.x`
Expand Down

0 comments on commit ae87460

Please sign in to comment.