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

Typed plugins in new platform #12857

Merged
merged 16 commits into from
Jul 19, 2017
Merged

Conversation

kimjoar
Copy link
Contributor

@kimjoar kimjoar commented Jul 14, 2017

I think this is the simplest way to build external plugins with types. Added a kbn-types package that contains a file that exports whatever we want to export from core, then use TS to build declaration files. See the readme in the kbn-types package for more info.

I'll create issues for some follow-ups. One is having CI build the package and make sure the error code is 0, as we otherwise have broken external types. Not really sure how to otherwise test this, e.g. making sure the right things are available etc. Another follow-up is exploring if we should commit the types, e.g. to make "breaking changes" to the types more obvious.

I've got a feeling it should be possible to further minimise the exposed types, but if this works, I think this is probably a good enough start, then we can learn as we start trying to make core plugins truly "independent" (separate package.json etc).

@kimjoar kimjoar added Feature:New Platform WIP Work in progress labels Jul 14, 2017
@kimjoar kimjoar force-pushed the plugin-types branch 3 times, most recently from 598f3e7 to 4783b64 Compare July 19, 2017 09:55
@kimjoar kimjoar changed the title [WIP] Typed plugins in new platform Typed plugins in new platform Jul 19, 2017
@kimjoar kimjoar removed the WIP Work in progress label Jul 19, 2017
Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just few nits/questions.


Now external code can use this package, e.g. something like this:

```js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: maybe typescript instead of js? Webstorm supports it (and also complains if we try to highlight typescript with js hint), but not sure if it's standard and your IDE supports it as well, so up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1 @@
types/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what is the difference between packages/@elastic/...package-name... and packages/...package-name...? Should we put kbn-types package under @elastic or is there any reason why we shouldn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to @elastic. We'll likely never push anything that's not under @elastic, so don't really see the point of that folder, but it's something we can solve later

});

const router = http.createAndRegisterRouter('/api/foo', {});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ;

question:: also wondering if we should include TS in packages/... while running npm run prettier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done


If you want to play around with an example, see the `./example` folder.

## Exposing types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this doc 👍

@kimjoar kimjoar merged commit 7559909 into elastic:new-platform Jul 19, 2017
@kimjoar kimjoar deleted the plugin-types branch July 19, 2017 19:53
@kimjoar kimjoar mentioned this pull request Jul 19, 2017
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants