Skip to content

Commit

Permalink
feat: api.hasPresets (umijs#60)
Browse files Browse the repository at this point in the history
* feat: api.hasPresets

* fix: presetId
  • Loading branch information
信鑫-King committed Feb 19, 2020
1 parent 463d26c commit 3a053ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ umi-next:
- api.addMiddleware() @done
- route 支持 Routes 配置 @done
改名为 route.wrappers
- api.hasPlugins(pluginIds: string[]) @done
- api.hasPlugins(pluginIds: string[]) @done
- api.hasPresets(presetIds: string[]) @done
- 未实现的接口,优先级低
api.rebuildTmpFiles()
api.modifyHTMLChunks()
Expand Down
17 changes: 17 additions & 0 deletions docs/plugin/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ e.g.
api.hasPlugins(['@umijs/plugin-dva']);
```

### hasPresets(presetIds: string[])

判断是否有注册某个插件集。

插件集的 id 规则,

e.g.

```js
// 判断是否有注册 @umijs/preset-ui
api.hasPresets(['@umijs/preset-ui']);
```

注:

- 如果在注册阶段使用,只能判断**在他之前**是否有注册某个插件集

## 扩展方法

通过 `api.registerMethod()` 扩展的方法。
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/Service/PluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,13 @@ export default class PluginAPI {
return pluginId in this.service.plugins;
});
}

hasPresets(presetIds: string[]) {
return presetIds.every(presetId => {
return (
presetId in this.service.plugins &&
this.service.plugins[presetId]?.isPreset
);
});
}
}

0 comments on commit 3a053ee

Please sign in to comment.