diff --git a/README.md b/README.md index 29e29456..9b235a11 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,24 @@ jobs: await printStuff() ``` +### Use scripts with jsDoc support + +If you want type support for your scripts, you could use the command below to install the +`github-script` type declaration. +```sh +$ npm i -D @types/github-script@github:actions/github-script +``` + +And then add the `jsDoc` declaration to your script like this: +```js +// @ts-check +/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */ +export default async ({ core, context }) => { + core.debug("Running something at the moment"); + return context.actor; +}; +``` + ### Use env as input You can set env vars to use them in your script: diff --git a/package.json b/package.json index 6cc8dfa0..1ce8de22 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "author": "GitHub", "license": "MIT", "main": "dist/index.js", + "types": "types/async-function.d.ts", "private": true, "scripts": { - "build": "ncc build src/main.ts", + "build": "npm run build:types && ncc build src/main.ts", + "build:types": "tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types", "format:check": "prettier --check src __test__", "format:write": "prettier --write src __test__", "lint": "eslint src __test__", diff --git a/src/async-function.ts b/src/async-function.ts index 8acd0d5c..8b38e641 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -8,7 +8,7 @@ import fetch from 'node-fetch' const AsyncFunction = Object.getPrototypeOf(async () => null).constructor -type AsyncFunctionArguments = { +export declare type AsyncFunctionArguments = { context: Context core: typeof core github: InstanceType diff --git a/types/async-function.d.ts b/types/async-function.d.ts new file mode 100644 index 00000000..b4d6a8e8 --- /dev/null +++ b/types/async-function.d.ts @@ -0,0 +1,20 @@ +/// +import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import { Context } from '@actions/github/lib/context'; +import { GitHub } from '@actions/github/lib/utils'; +import * as glob from '@actions/glob'; +import * as io from '@actions/io'; +import fetch from 'node-fetch'; +export declare type AsyncFunctionArguments = { + context: Context; + core: typeof core; + github: InstanceType; + exec: typeof exec; + glob: typeof glob; + io: typeof io; + fetch: typeof fetch; + require: NodeRequire; + __original_require__: NodeRequire; +}; +export declare function callAsyncFunction(args: AsyncFunctionArguments, source: string): Promise;