support ES6/ES2015-style import syntax for plugins #594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...
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.
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:
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.