FlandreDaisuki / rollup-plugin-userscript-metablock

Transform json file to userscript metablock and append on.
https://www.npmjs.com/package/rollup-plugin-userscript-metablock
MIT License
35 stars 7 forks source link

Include TypeScript types #17

Closed jsejcksn closed 3 years ago

jsejcksn commented 3 years ago

Hello. I looked for types for this module, but did not find any. In order to satisfy the TS compiler, I started making a declaration of my own, but it is incomplete. I will include it in this post. Feel free to use it to jumpstart any work toward including types.

rollup-plugin-userscript-metablock.d.ts:

declare module 'rollup-plugin-userscript-metablock' {
  export type MetaValues = {
    name?: string | (Record<string, string> & {default: string});
    description?: string;
    namespace?: string;

    /**
     * Match pattern:
     * https://developer.chrome.com/docs/extensions/mv3/match_patterns/
     */
    match?: string | string[];
    include?: string | string[];
    exclude?: string | string[];
    icon?: string;
    require?: string;

    /** Default `"document-end"` */
    'run-at'?:
      | 'document-end'
      | 'document-start'
      | 'document-idle'
      | 'document-body' /** Only Tampermonkey */
      | 'context-menu'; /** Only Tampermonkey, only Chrome */

    /** Values are URIs */
    resource?: Record<string, string>;

    /** SemVer: https://semver.org/ */
    version?: string;
    noframes?: true;
    grant?: string | string[];
  };

  export type Options = {
    /** Default `"./metablock.json"` */
    file?: string;

    /** Default `"compatible"` */
    manager?:
      | 'compatible'
      | 'greasemonkey3'
      | 'greasemonkey4'
      | 'tampermonkey'
      | 'violentmonkey'
      | '';

    order?: string[];

    /** Default `null` */
    override?: MetaValues;
    validator?: 'off' | 'warn' | 'error';
  };

  function metablock (options?: Options): any;

  export default metablock;
}
FlandreDaisuki commented 3 years ago

Thanks for the example.

It works fine and I don't update this for a long time. I'll review every script manager API recently and add the type when I have time. PR welcome as well.