diff --git a/eslint.config.mjs b/eslint.config.js similarity index 100% rename from eslint.config.mjs rename to eslint.config.js diff --git a/jest.config.js b/jest.config.js index 7cf1c26f..f6a60fb2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,9 @@ -module.exports = { - preset: 'ts-jest', +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + preset: 'ts-jest/presets/default-esm', clearMocks: true, - testEnvironment: 'node', - testMatch: ['**/*.test.ts'], - verbose: true + // https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/ + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, } diff --git a/package.json b/package.json index 26daa655..1f224951 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "build": "ncc build --source-map --license licenses.txt src/main.ts", "test": "jest" }, + "type": "module", "dependencies": { "@actions/core": "1.10.1", "@actions/github": "6.0.0", @@ -13,6 +14,7 @@ "@octokit/request-error": "5.1.0" }, "devDependencies": { + "@tsconfig/node20": "^20.1.4", "@types/jest": "29.5.12", "@types/node": "20.12.7", "@vercel/ncc": "0.38.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a036abe..b1cdc93a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,6 +21,9 @@ importers: specifier: 5.1.0 version: 5.1.0 devDependencies: + '@tsconfig/node20': + specifier: ^20.1.4 + version: 20.1.4 '@types/jest': specifier: 29.5.12 version: 29.5.12 @@ -455,6 +458,9 @@ packages: '@sinonjs/fake-timers@10.3.0': resolution: {integrity: sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==} + '@tsconfig/node20@20.1.4': + resolution: {integrity: sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==} + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -2296,6 +2302,8 @@ snapshots: dependencies: '@sinonjs/commons': 3.0.1 + '@tsconfig/node20@20.1.4': {} + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.24.0 diff --git a/src/body.ts b/src/body.ts index 540902f2..b749b63b 100644 --- a/src/body.ts +++ b/src/body.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import { Issue, Octokit } from './types' +import { Issue, Octokit } from './types.js' export const appendOrUpdateBody = async (octokit: Octokit, issue: Issue, content: string) => { let fetchedBody = issue.body diff --git a/src/github.ts b/src/github.ts index fd71b3d7..de31c993 100644 --- a/src/github.ts +++ b/src/github.ts @@ -1,7 +1,5 @@ -import { getOctokitOptions, GitHub } from '@actions/github/lib/utils' +import * as github from '@actions/github' import * as pluginRetry from '@octokit/plugin-retry' +import { Octokit } from './types.js' -export const getOctokit = (token: string) => { - const MyOctokit = GitHub.plugin(pluginRetry.retry) - return new MyOctokit(getOctokitOptions(token)) -} +export const getOctokit = (token: string): Octokit => github.getOctokit(token, undefined, pluginRetry.retry) diff --git a/src/main.ts b/src/main.ts index 09a427e4..8bbbdd5e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import { run } from './run' +import { run } from './run.js' const main = async (): Promise => { await run({ diff --git a/src/run.ts b/src/run.ts index 7375ae60..31d715c3 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,9 +1,9 @@ import * as core from '@actions/core' import * as github from '@actions/github' import { RequestError } from '@octokit/request-error' -import { appendOrUpdateBody } from './body' -import { getOctokit } from './github' -import { Issue, Octokit } from './types' +import { appendOrUpdateBody } from './body.js' +import { getOctokit } from './github.js' +import { Issue, Octokit } from './types.js' export type Inputs = { issueNumbers: number[] diff --git a/src/types.ts b/src/types.ts index 75c9f0f6..a54a19dc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ -import { GitHub } from '@actions/github/lib/utils' +import * as github from '@actions/github' -export type Octokit = InstanceType +export type Octokit = ReturnType export type Issue = { owner: string diff --git a/tests/body.test.ts b/tests/body.test.ts index b2b3acae..11db3343 100644 --- a/tests/body.test.ts +++ b/tests/body.test.ts @@ -1,4 +1,4 @@ -import { computeBody } from '../src/body' +import { computeBody } from '../src/body.js' const marker = '' diff --git a/tests/run.test.ts b/tests/run.test.ts index 36d10a2d..18637899 100644 --- a/tests/run.test.ts +++ b/tests/run.test.ts @@ -1,4 +1,4 @@ -import { run } from '../src/run' +import { run } from '../src/run.js' import { RequestError } from '@octokit/request-error' const octokitMock = { diff --git a/tsconfig.json b/tsconfig.json index d852dfc1..92ebc1fd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,4 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "strict": true, - "outDir": "./lib", - "rootDirs": ["./src"], - } + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@tsconfig/node20/tsconfig.json" }