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

support ES6/ES2015-style import syntax for plugins #594

Merged

Conversation

shlomiassaf
Copy link
Contributor

@shlomiassaf shlomiassaf commented Sep 19, 2017

Currently, plugins must come in the form of a CommonJS module that exports a function.

In TypeScript this might become an issue, especially if a plugin wants to export some symbols, types etc...

exports = function myPlugin() {};

The example above is fine but it will not allow exporting type information.
You can, of course, export other runtime member by setting properties on the function itself but no types.

Adding runtime members on the function within TS will require declaration merging... a complexity we can avoid...

There are hacky workarounds, using namespaces and/or modules with declaration merging but this is tricky, not trivial and at times create other issues.

This PR add support for plugins that want to implement the ES6/ES2015-style import syntax:

exports function initPlugin() {
};

export class MyPlugin() { ... }

It allows declaring the plugin initialising function under the member initPlugin within the module.

If a function is not found it will fallback to the old method for initialising plugins.

For reference see @RyanCavanaugh post on the subject.

Since this is a pure typescript project it does seem right... Some plugins might form an eco-system which requires sharing symbols.

@shlomiassaf shlomiassaf mentioned this pull request Sep 20, 2017
9 tasks
@blakeembrey
Copy link
Member

@shlomiassaf Is there any documentation we should update with this? Also, any thoughts on a clearer name? initFunction feels a bit more verbose than needed, how about just load or something similar? Looking for input here, you have more experience hacking with TypeDoc than I do 😄

@shlomiassaf
Copy link
Contributor Author

load is fine by me, I'll update after the holiday (New Years)

@shlomiassaf
Copy link
Contributor Author

@blakeembrey done, about the docs, I don't know where they are and if there is a section on plugins...

@blakeembrey blakeembrey merged commit c77b0fc into TypeStrong:master Oct 6, 2017
@shlomiassaf shlomiassaf deleted the support-module-style-plugin branch October 15, 2017 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants