From cfdcbc9193c238fb1068749d0239ad3e4c8924fb Mon Sep 17 00:00:00 2001 From: Toby Hsieh Date: Wed, 11 Feb 2026 10:51:42 -0800 Subject: [PATCH] Convert codebase to ESM --- __tests__/comment-renderer.test.ts | 9 +- __tests__/configuration-reader.test.ts | 2 +- __tests__/main.test.ts | 88 ++++-- __tests__/moduleMocks/core.ts | 10 + __tests__/runner.test.ts | 2 +- eslint.config.mjs | 8 +- jest.config.js | 7 +- package-lock.json | 385 +++++++++++++++++++++++-- package.json | 9 +- run.js | 4 +- src/comment-renderer.ts | 4 +- src/comment-upserter.ts | 6 +- src/configuration-reader.ts | 4 +- src/files-changed-reader.ts | 2 +- src/main.ts | 10 +- src/runner.ts | 10 +- src/template-types.ts | 2 +- tsconfig.base.json | 5 +- 18 files changed, 487 insertions(+), 80 deletions(-) create mode 100644 __tests__/moduleMocks/core.ts diff --git a/__tests__/comment-renderer.test.ts b/__tests__/comment-renderer.test.ts index d91f9b5..924ed52 100644 --- a/__tests__/comment-renderer.test.ts +++ b/__tests__/comment-renderer.test.ts @@ -1,13 +1,14 @@ -import * as core from '@actions/core' import {beforeEach, describe, expect, it, jest} from '@jest/globals' import dedent from 'dedent' -import {CommentRendererImpl} from '../src/comment-renderer' +import * as core from './moduleMocks/core' +jest.unstable_mockModule('@actions/core', () => core) -jest.mock('@actions/core') +import {CommentRenderer} from '../src/comment-renderer' +const {CommentRendererImpl} = await import('../src/comment-renderer') describe('CommentRendererImpl', () => { - let renderer: CommentRendererImpl + let renderer: CommentRenderer beforeEach(() => { renderer = new CommentRendererImpl() diff --git a/__tests__/configuration-reader.test.ts b/__tests__/configuration-reader.test.ts index 3a0b22b..f262e70 100644 --- a/__tests__/configuration-reader.test.ts +++ b/__tests__/configuration-reader.test.ts @@ -40,7 +40,7 @@ describe('ConfigurationReaderImpl', () => { it('returns configuration from .github/codemention.yml', async () => { const fileContents = fs.readFileSync( - path.join(__dirname, 'fixtures', 'codemention.yml'), + path.join(import.meta.dirname, 'fixtures', 'codemention.yml'), 'utf8', ) const data = {content: Buffer.from(fileContents).toString('base64')} diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 0930aaf..2f32d23 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,26 +1,61 @@ -import * as core from '@actions/core' -import * as github from '@actions/github' import {GitHub} from '@actions/github/lib/utils' import {beforeEach, describe, expect, it, jest} from '@jest/globals' import {Api} from '@octokit/plugin-rest-endpoint-methods' import {randomUUID} from 'crypto' -import {mockDeep} from 'jest-mock-extended' +import {MockProxy, mock, mockDeep} from 'jest-mock-extended' + +import * as core from './moduleMocks/core' +jest.unstable_mockModule('@actions/core', () => core) +import * as origGithub from '@actions/github' +const github = { + getOctokit: jest.fn(), + context: mock(), +} +jest.unstable_mockModule('@actions/github', () => github) + +function mockModuleAndInstance( + modulePath: string, + ctor: new (...args: CP) => T, + exportName?: string, +): [typeof ctor, MockProxy] { + const instance = mock() + const ctorMock = jest.fn((..._args: CP) => instance) + jest.unstable_mockModule(modulePath, () => ({ + [exportName ?? ctor.name]: ctorMock, + })) + return [ctorMock, instance] +} import {CommentRendererImpl} from '../src/comment-renderer' +const [CommentRendererImplMock, commentRenderer] = mockModuleAndInstance( + '../src/comment-renderer', + CommentRendererImpl, +) + import {CommentUpserterImpl} from '../src/comment-upserter' +const [CommentUpserterImplMock, commentUpserter] = mockModuleAndInstance( + '../src/comment-upserter', + CommentUpserterImpl, +) + import {ConfigurationReaderImpl} from '../src/configuration-reader' +const [ConfigurationReaderImplMock, configurationReader] = + mockModuleAndInstance('../src/configuration-reader', ConfigurationReaderImpl) + import {FilesChangedReaderImpl} from '../src/files-changed-reader' -import {run} from '../src/main' -import Runner from '../src/runner' +const [FilesChangedReaderImplMock, filesChangedReader] = mockModuleAndInstance( + '../src/files-changed-reader', + FilesChangedReaderImpl, +) -jest.mock('@actions/core') -jest.mock('@actions/github') +import Runner from '../src/runner' +const [RunnerMock, runner] = mockModuleAndInstance( + '../src/runner', + Runner, + 'default', +) -jest.mock('../src/comment-renderer') -jest.mock('../src/comment-upserter') -jest.mock('../src/configuration-reader') -jest.mock('../src/files-changed-reader') -jest.mock('../src/runner') +const {run} = await import('../src/main') describe('run', () => { const githubToken = randomUUID() @@ -28,7 +63,7 @@ describe('run', () => { let octokitRest: Api['rest'] beforeEach(() => { - jest.mocked(core).getInput.mockImplementation(input => { + core.getInput.mockImplementation(input => { if (input === 'githubToken') { return githubToken } else { @@ -38,33 +73,32 @@ describe('run', () => { octokit = mockDeep>() octokitRest = octokit.rest - jest.mocked(github).getOctokit.mockReturnValue(octokit) + github.getOctokit.mockReturnValue(octokit) }) it('calls Runner.run', async () => { await run() expect(github.getOctokit).toHaveBeenCalledWith(githubToken) - expect(ConfigurationReaderImpl).toHaveBeenCalledWith(octokitRest) - expect(FilesChangedReaderImpl).toHaveBeenCalledWith(octokit) - expect(CommentUpserterImpl).toHaveBeenCalledWith(octokitRest) - - expect(Runner).toHaveBeenCalledWith( - jest.mocked(ConfigurationReaderImpl).mock.instances[0], - jest.mocked(FilesChangedReaderImpl).mock.instances[0], - jest.mocked(CommentRendererImpl).mock.instances[0], - jest.mocked(CommentUpserterImpl).mock.instances[0], - ) + expect(ConfigurationReaderImplMock).toHaveBeenCalledWith(octokitRest) + expect(FilesChangedReaderImplMock).toHaveBeenCalledWith(octokit) + expect(CommentRendererImplMock).toHaveBeenCalled() + expect(CommentUpserterImplMock).toHaveBeenCalledWith(octokitRest) - expect(jest.mocked(Runner).mock.instances[0].run).toHaveBeenCalledWith( - github.context, + expect(RunnerMock).toHaveBeenCalledWith( + configurationReader, + filesChangedReader, + commentRenderer, + commentUpserter, ) + + expect(runner.run).toHaveBeenCalledWith(github.context) expect(core.setFailed).not.toHaveBeenCalled() }) describe('when an error is thrown', () => { it('sets the action status to failed', async () => { - jest.mocked(core).getInput.mockImplementation(() => { + core.getInput.mockImplementation(() => { throw new Error('getInput error') }) await run() diff --git a/__tests__/moduleMocks/core.ts b/__tests__/moduleMocks/core.ts new file mode 100644 index 0000000..4db736b --- /dev/null +++ b/__tests__/moduleMocks/core.ts @@ -0,0 +1,10 @@ +import * as core from '@actions/core' +import {jest} from '@jest/globals' + +export const debug = jest.fn() +export const error = jest.fn() +export const getInput = jest.fn() +export const info = jest.fn() +export const setFailed = jest.fn() +export const setOutput = jest.fn() +export const warning = jest.fn() diff --git a/__tests__/runner.test.ts b/__tests__/runner.test.ts index 99b18af..2a0c28e 100644 --- a/__tests__/runner.test.ts +++ b/__tests__/runner.test.ts @@ -31,7 +31,7 @@ describe('Runner', () => { let pullRequest: PullRequest const configuration: Configuration = yaml.load( fs.readFileSync( - path.join(__dirname, 'fixtures', 'codemention.yml'), + path.join(import.meta.dirname, 'fixtures', 'codemention.yml'), 'utf8', ), ) as Configuration diff --git a/eslint.config.mjs b/eslint.config.mjs index c9499d0..cd19468 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -61,7 +61,13 @@ export default defineConfig([ 'eslint-comments/no-use': 'off', 'import/no-namespace': 'off', 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'error', + + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + }, + ], '@typescript-eslint/explicit-member-accessibility': [ 'error', diff --git a/jest.config.js b/jest.config.js index 631cc3b..74950cd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,11 +1,14 @@ export default { + preset: 'ts-jest', clearMocks: true, moduleFileExtensions: ['js', 'ts'], + extensionsToTreatAsEsm: ['.ts'], + resolver: 'ts-jest-resolver', testMatch: ['**/*.test.ts'], + testPathIgnorePatterns: ['/node_modules/'], transform: { - '^.+\\.[jt]s$': 'ts-jest', + '^.+\\.ts$': ['ts-jest', {tsconfig: 'tsconfig.json', useESM: true}], }, - transformIgnorePatterns: ['/node_modules/(?!(@octokit|before-after-hook|universal-user-agent)/)'], verbose: true, collectCoverageFrom: ['src/**/*.ts'], coverageThreshold: { diff --git a/package-lock.json b/package-lock.json index 868f392..09840b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,8 +6,8 @@ "": { "license": "MIT", "dependencies": { - "@actions/core": "^2.0.3", - "@actions/github": "^8.0.1", + "@actions/core": "^3.0.0", + "@actions/github": "^9.0.0", "handlebars": "^4.7.8", "js-yaml": "^4.1.1", "markdown-escape": "^2.0.0", @@ -32,32 +32,43 @@ "jest-mock-extended": "^4.0.0", "prettier": "^3.6.2", "ts-jest": "^29.4.1", + "ts-jest-resolver": "^2.0.1", "typescript": "^5.9.2" } }, "node_modules/@actions/core": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.3.tgz", - "integrity": "sha512-Od9Thc3T1mQJYddvVPM4QGiLUewdh+3txmDYHHxoNdkqysR1MbCT+rFOtNUxYAz+7+6RIsqipVahY2GJqGPyxA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.0.tgz", + "integrity": "sha512-zYt6cz+ivnTmiT/ksRVriMBOiuoUpDCJJlZ5KPl2/FRdvwU3f7MPh9qftvbkXJThragzUZieit2nyHUyw53Seg==", + "license": "MIT", + "dependencies": { + "@actions/exec": "^3.0.0", + "@actions/http-client": "^4.0.0" + } + }, + "node_modules/@actions/core/node_modules/@actions/http-client": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz", + "integrity": "sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==", "license": "MIT", "dependencies": { - "@actions/exec": "^2.0.0", - "@actions/http-client": "^3.0.2" + "tunnel": "^0.0.6", + "undici": "^6.23.0" } }, "node_modules/@actions/exec": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz", - "integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz", + "integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==", "license": "MIT", "dependencies": { - "@actions/io": "^2.0.0" + "@actions/io": "^3.0.2" } }, "node_modules/@actions/github": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@actions/github/-/github-8.0.1.tgz", - "integrity": "sha512-cue7mS+kx1/2Dnc/094pitRUm+0uPXVXYVaqOdZwD15BsXATWYHW3idJDYOlyBc5gJlzAQ/w5YLU4LR8D7hjVg==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-9.0.0.tgz", + "integrity": "sha512-yJ0RoswsAaKcvkmpCE4XxBRiy/whH2SdTBHWzs0gi4wkqTDhXMChjSdqBz/F4AeiDlP28rQqL33iHb+kjAMX6w==", "license": "MIT", "dependencies": { "@actions/http-client": "^3.0.2", @@ -80,9 +91,9 @@ } }, "node_modules/@actions/io": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz", - "integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", + "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", "license": "MIT" }, "node_modules/@babel/code-frame": { @@ -1719,6 +1730,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/graceful-fs": { + "version": "4.1.9", + "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", + "integrity": "sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", @@ -3555,6 +3576,16 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -3690,6 +3721,19 @@ "node": ">=8" } }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -3790,6 +3834,22 @@ "dev": true, "license": "MIT" }, + "node_modules/is-core-module": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", + "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -4173,6 +4233,16 @@ "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" } }, + "node_modules/jest-get-type": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/jest-haste-map": { "version": "30.2.0", "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-30.2.0.tgz", @@ -5053,6 +5123,13 @@ "node": ">=8" } }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true, + "license": "MIT" + }, "node_modules/path-scurry": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", @@ -5307,6 +5384,27 @@ "node": ">=0.10.0" } }, + "node_modules/resolve": { + "version": "1.22.11", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.11.tgz", + "integrity": "sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-core-module": "^2.16.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/resolve-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz", @@ -5340,6 +5438,16 @@ "node": ">=4" } }, + "node_modules/resolve.exports": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.3.tgz", + "integrity": "sha512-OcXjMsGdhL4XnbShKpAcSqPMzQoYkYyhbEaeSko47MjRP9NfEQMhZkXL1DoFlt9LWQn4YttrdnV6X2OiyzBi+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + } + }, "node_modules/reusify": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", @@ -5671,6 +5779,19 @@ "node": ">=8" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/synckit": { "version": "0.11.11", "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.11.tgz", @@ -5848,6 +5969,236 @@ } } }, + "node_modules/ts-jest-resolver": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ts-jest-resolver/-/ts-jest-resolver-2.0.1.tgz", + "integrity": "sha512-FolE73BqVZCs8/RbLKxC67iaAtKpBWx7PeLKFW2zJQlOf9j851I7JRxSDenri2NFvVH3QP7v3S8q1AmL24Zb9Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "jest-resolve": "^29.5.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/@jest/schemas": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sinclair/typebox": "^0.27.8" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/@jest/types": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/schemas": "^29.6.3", + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^17.0.8", + "chalk": "^4.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/@sinclair/typebox": { + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", + "dev": true, + "license": "MIT" + }, + "node_modules/ts-jest-resolver/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/ts-jest-resolver/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ts-jest-resolver/node_modules/ci-info": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", + "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-haste-map": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", + "integrity": "sha512-fP8u2pyfqx0K1rGn1R9pyE0/KTn+G7PxktWidOBTqFPLYX0b9ksaMFkhK5vrS3DVun09pckLdlx90QthlW7AmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/types": "^29.6.3", + "@types/graceful-fs": "^4.1.3", + "@types/node": "*", + "anymatch": "^3.0.3", + "fb-watchman": "^2.0.0", + "graceful-fs": "^4.2.9", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", + "micromatch": "^4.0.4", + "walker": "^1.0.8" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "optionalDependencies": { + "fsevents": "^2.3.2" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-regex-util": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-resolve": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-29.7.0.tgz", + "integrity": "sha512-IOVhZSrg+UvVAshDSDtHyFCCBUl/Q3AAJv8iZ6ZjnZ74xzvwuzLXid9IIIPgTnY62SJjfuupMKZsZQRsCvxEgA==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.0.0", + "graceful-fs": "^4.2.9", + "jest-haste-map": "^29.7.0", + "jest-pnp-resolver": "^1.2.2", + "jest-util": "^29.7.0", + "jest-validate": "^29.7.0", + "resolve": "^1.20.0", + "resolve.exports": "^2.0.0", + "slash": "^3.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-util": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", + "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/types": "^29.6.3", + "@types/node": "*", + "chalk": "^4.0.0", + "ci-info": "^3.2.0", + "graceful-fs": "^4.2.9", + "picomatch": "^2.2.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-validate": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", + "integrity": "sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/types": "^29.6.3", + "camelcase": "^6.2.0", + "chalk": "^4.0.0", + "jest-get-type": "^29.6.3", + "leven": "^3.1.0", + "pretty-format": "^29.7.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/jest-worker": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", + "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "jest-util": "^29.7.0", + "merge-stream": "^2.0.0", + "supports-color": "^8.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/pretty-format": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/schemas": "^29.6.3", + "ansi-styles": "^5.0.0", + "react-is": "^18.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/ts-jest-resolver/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/ts-jest/node_modules/type-fest": { "version": "4.41.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", diff --git a/package.json b/package.json index a9c0e5c..4cc9b4e 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "private": true, - "main": "lib/main.js", + "type": "module", "scripts": { "build": "tsc", "format": "prettier --write '**/*.ts'", "format-check": "prettier --check '**/*.ts'", "lint": "eslint .", - "test": "jest --coverage", + "test": "NODE_OPTIONS=--experimental-vm-modules jest --coverage", "all": "npm run build && npm run format && npm run lint && npm test", "ci": "npm run build && npm run format-check && npm run lint && npm test" }, @@ -21,8 +21,8 @@ ], "license": "MIT", "dependencies": { - "@actions/core": "^2.0.3", - "@actions/github": "^8.0.1", + "@actions/core": "^3.0.0", + "@actions/github": "^9.0.0", "handlebars": "^4.7.8", "js-yaml": "^4.1.1", "markdown-escape": "^2.0.0", @@ -47,6 +47,7 @@ "jest-mock-extended": "^4.0.0", "prettier": "^3.6.2", "ts-jest": "^29.4.1", + "ts-jest-resolver": "^2.0.1", "typescript": "^5.9.2" } } diff --git a/run.js b/run.js index ef3b9c9..b3425b4 100644 --- a/run.js +++ b/run.js @@ -1,2 +1,2 @@ -const main = require('./lib/main') -main.run() +import {run} from './lib/main.js' +await run() diff --git a/src/comment-renderer.ts b/src/comment-renderer.ts index 9e70a78..29566aa 100644 --- a/src/comment-renderer.ts +++ b/src/comment-renderer.ts @@ -2,8 +2,8 @@ import * as core from '@actions/core' import Handlebars from 'handlebars' import markdownEscape from 'markdown-escape' -import {CommentConfiguration} from './configuration' -import {MatchedRule, Mention, TemplateContext} from './template-types' +import {CommentConfiguration} from './configuration.js' +import {MatchedRule, Mention, TemplateContext} from './template-types.js' export const FOOTER = '' diff --git a/src/comment-upserter.ts b/src/comment-upserter.ts index 67a1063..276c3d9 100644 --- a/src/comment-upserter.ts +++ b/src/comment-upserter.ts @@ -1,9 +1,9 @@ import * as core from '@actions/core' import {Api} from '@octokit/plugin-rest-endpoint-methods' -import {FOOTER} from './comment-renderer' -import {Repo} from './github-types' -import {MatchedRule} from './template-types' +import {FOOTER} from './comment-renderer.js' +import {Repo} from './github-types.js' +import {MatchedRule} from './template-types.js' /** * @see {@link upsert} diff --git a/src/configuration-reader.ts b/src/configuration-reader.ts index deec744..7d2f2cf 100644 --- a/src/configuration-reader.ts +++ b/src/configuration-reader.ts @@ -2,8 +2,8 @@ import * as core from '@actions/core' import {Api} from '@octokit/plugin-rest-endpoint-methods' import * as yaml from 'js-yaml' -import {Configuration} from './configuration' -import {Repo} from './github-types' +import {Configuration} from './configuration.js' +import {Repo} from './github-types.js' /** * @see {@link read} diff --git a/src/files-changed-reader.ts b/src/files-changed-reader.ts index db2a887..a919955 100644 --- a/src/files-changed-reader.ts +++ b/src/files-changed-reader.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core' import {GitHub} from '@actions/github/lib/utils' -import {Repo} from './github-types' +import {Repo} from './github-types.js' /** * @see {@link read} diff --git a/src/main.ts b/src/main.ts index 4a66cce..2f4eb7e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,11 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import {CommentRendererImpl} from './comment-renderer' -import {CommentUpserterImpl} from './comment-upserter' -import {ConfigurationReaderImpl} from './configuration-reader' -import {FilesChangedReaderImpl} from './files-changed-reader' -import Runner from './runner' +import {CommentRendererImpl} from './comment-renderer.js' +import {CommentUpserterImpl} from './comment-upserter.js' +import {ConfigurationReaderImpl} from './configuration-reader.js' +import {FilesChangedReaderImpl} from './files-changed-reader.js' +import Runner from './runner.js' export async function run(): Promise { try { diff --git a/src/runner.ts b/src/runner.ts index a447277..5356de8 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -1,12 +1,12 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import {PullRequestEvent} from '@octokit/webhooks-types/schema.d' +import {PullRequestEvent} from '@octokit/webhooks-types' import micromatch from 'micromatch' -import {CommentRenderer} from './comment-renderer' -import {CommentUpserter} from './comment-upserter' -import {ConfigurationReader} from './configuration-reader' -import {FilesChangedReader} from './files-changed-reader' +import {CommentRenderer} from './comment-renderer.js' +import {CommentUpserter} from './comment-upserter.js' +import {ConfigurationReader} from './configuration-reader.js' +import {FilesChangedReader} from './files-changed-reader.js' /** * @see {@link run} diff --git a/src/template-types.ts b/src/template-types.ts index 43756b3..2f19fa2 100644 --- a/src/template-types.ts +++ b/src/template-types.ts @@ -1,4 +1,4 @@ -import {MentionRule} from './configuration' +import {MentionRule} from './configuration.js' /** * A MentionRule that was matched to some files changed in a pull request diff --git a/tsconfig.base.json b/tsconfig.base.json index da8e6ca..c3315ff 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,9 +1,10 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "allowJs": true, "target": "ES2022", - "module": "commonjs", + "isolatedModules": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", "outDir": "./lib", "rootDir": "./src", "strict": true,