Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getFeatures() invocation in plugin start() unhandled error #1778

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/develop/plugins/server_plugin_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ These functions are available via the `app` object passed to the plugin when it

#### `app.getFeatures(enabed)`

Returns an object detailing the available APIs and Plugins.
Returns a Promise containing an object detailing the available APIs and Plugins.

The `enabled` parameter is optional and has the following values:
- `undefined` (not provided): list all features
Expand All @@ -27,7 +27,7 @@ The `enabled` parameter is optional and has the following values:

_Example:_
```javascript
let features = app.getFeatures();
const features = await app.getFeatures();

{
"apis": [
Expand Down
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ class Server {

// feature detection
app.getFeatures = async (enabled?: boolean) => {
const checkPMStarted = (): Promise<boolean> => {
return new Promise((resolve) => {
setImmediate(() => {
resolve(typeof app.getPluginsList === 'function')
})
})
}
const maxTries = 10
let tries = 0
let pmStarted = false

while (!pmStarted && tries < maxTries) {
tries++
pmStarted = await checkPMStarted()
}
const plugins = pmStarted ? await app.getPluginsList(enabled) : []
return {
apis: enabled === false ? [] : app.apis,
plugins: await app.getPluginsList(enabled)
plugins: plugins
}
}

Expand Down