Skip to content

Commit

Permalink
refactor: api.modifyDepInfo -> api.addDepInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Aug 14, 2020
1 parent c4ed446 commit b4f0dfd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
28 changes: 14 additions & 14 deletions docs/plugins/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ api.addBeforeMiddewares(() => {
});
```

### addDepInfo

添加依赖信息,包括 semver range 和别名信息。

```js
api.addDepInfo((memo) => {
return {
name: 'foo',
range: pkg.dependencies.foo,
alias: [pathToFooPackage],
};
});
```

### addEntryCode

在入口文件最后添加代码。
Expand Down Expand Up @@ -642,20 +656,6 @@ api.modifyDefaultConfig((memo) => {
});
```

### modifyDepInfo

添加依赖信息,包括 semver range 和别名信息。

```js
api.modifyDepInfo((memo) => {
memo['foo'] = {
range: pkg.dependencies.foo,
alias: [pathToFooPackage],
};
return memo;
});
```

### modifyHTML

修改 HTML,基于 [cheerio](https://github.com/cheeriojs/cheerio) 的 ast。
Expand Down
28 changes: 14 additions & 14 deletions docs/plugins/api.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ api.addBeforeMiddewares(() => {
});
```

### addDepInfo

添加依赖信息,包括 semver range 和别名信息。

```js
api.addDepInfo((memo) => {
return {
name: 'foo',
range: pkg.dependencies.foo,
alias: [pathToFooPackage],
};
});
```

### addEntryCode

在入口文件最后添加代码。
Expand Down Expand Up @@ -643,20 +657,6 @@ api.modifyDefaultConfig((memo) => {
});
```

### modifyDepInfo

添加依赖信息,包括 semver range 和别名信息。

```js
api.modifyDepInfo((memo) => {
memo['foo'] = {
range: pkg.dependencies.foo,
alias: [pathToFooPackage],
};
return memo;
});
```

### modifyHTML

修改 HTML,基于 [cheerio](https://github.com/cheeriojs/cheerio) 的 ast。
Expand Down
23 changes: 13 additions & 10 deletions packages/preset-built-in/src/plugins/generateFiles/umi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ export default function (api: IApi) {
utils: { Mustache },
} = api;

api.modifyDepInfo((memo) => {
memo['@umijs/runtime'] = {
range: '3',
alias: [runtimePath],
};
memo['@umijs/renderer-react'] = {
range: '3',
alias: [renderReactPath],
};
return memo;
api.addDepInfo(() => {
return [
{
name: '@umijs/runtime',
range: '3',
alias: [runtimePath],
},
{
name: '@umijs/renderer-react',
range: '3',
alias: [renderReactPath],
},
];
});

api.onGenerateFiles(async (args) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-built-in/src/plugins/registerMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function (api: IApi) {
'onPatchRoutesBefore',
'onDevCompileDone',
'addBeforeMiddewares',
'addDepInfo',
'addDevScripts',
'addMiddewares',
'addRuntimePlugin',
Expand All @@ -42,7 +43,6 @@ export default function (api: IApi) {
'modifyBabelOpts',
'modifyBabelPresetOpts',
'modifyBundleImplementor',
'modifyDepInfo',
'modifyHTMLChunks',
'modifyDevHTMLContent',
'modifyExportRouteMap',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export interface IApi extends PluginAPI {
}
>;
modifyBundleImplementor: IModify<any, {}>;
modifyDepInfo: IModify<any, {}>;
modifyConfig: IModify<IConfig, {}>;
modifyDefaultConfig: IModify<IConfig, {}>;
modifyHTML: IModify<CheerioStatic, { route: IRoute }>;
Expand All @@ -217,6 +216,7 @@ export interface IApi extends PluginAPI {
>;

// ApplyPluginType.add
addDepInfo: IAdd<null, { name: string; range: string; alias?: string[] }>;
addDevScripts: IAdd<null, string>;
addHTMLHeadScripts: IAdd<{ route?: IRoute }, IScriptConfig>;
addHTMLScripts: IAdd<{ route?: IRoute }, IScriptConfig>;
Expand Down

0 comments on commit b4f0dfd

Please sign in to comment.