Skip to content

Commit

Permalink
Add plugin implemenation type (#2355)
Browse files Browse the repository at this point in the history
* types: add plugin implementation type for plugin authors

* build: properly lint ts sources and tests

* uncomment tests
  • Loading branch information
Hotell authored and lukastaegert committed Aug 1, 2018
1 parent 55d90d8 commit da97ea5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -117,10 +117,15 @@
"README.md"
],
"lint-staged": {
"*.ts": [
"{src,bin,browser,typings}/**/*.ts": [
"tslint --project . --fix",
"prettier --write",
"git add"
],
"test/**/*.ts": [
"tslint --project test/typescript --fix",
"prettier --write",
"git add"
]
}
}
12 changes: 12 additions & 0 deletions src/rollup/types.d.ts
Expand Up @@ -148,6 +148,18 @@ export type ResolveDynamicImportHook = (

export type AddonHook = string | ((this: PluginContext) => string | Promise<string>);

/**
* use this type for plugin annotation
* @example
* ```ts
* interface Options {
* ...
* }
* const myPlugin: PluginImpl<Options> = (options = {}) => { ... }
* ```
*/
export type PluginImpl<O extends object = object> = (options?: O) => Plugin;

export interface Plugin {
name: string;
options?: (options: InputOptions) => InputOptions | void | null;
Expand Down
13 changes: 13 additions & 0 deletions test/typescript/index.ts
@@ -1 +1,14 @@
import * as rollup from './dist/rollup';

// Plugin API
interface Options {
extensions?: string | string[];
}
const plugin: rollup.PluginImpl<Options> = (options = {}) => {
// tslint:disable-next-line:no-unused-variable
const extensions = options.extensions || ['.js'];
return { name: 'my-plugin' };
};

plugin();
plugin({ extensions: ['.js', 'json'] });

0 comments on commit da97ea5

Please sign in to comment.