Skip to content

Commit

Permalink
Migrate to ESM (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Apr 21, 2024
1 parent c79b1ba commit 0a9fa26
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
File renamed without changes.
12 changes: 7 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"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",
"@octokit/plugin-retry": "6.0.1",
"@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",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/body.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import { run } from './run'
import { run } from './run.js'

const main = async (): Promise<void> => {
await run({
Expand Down
6 changes: 3 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GitHub } from '@actions/github/lib/utils'
import * as github from '@actions/github'

export type Octokit = InstanceType<typeof GitHub>
export type Octokit = ReturnType<typeof github.getOctokit>

export type Issue = {
owner: string
Expand Down
2 changes: 1 addition & 1 deletion tests/body.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computeBody } from '../src/body'
import { computeBody } from '../src/body.js'

const marker = '<!-- marker -->'

Expand Down
2 changes: 1 addition & 1 deletion tests/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run } from '../src/run'
import { run } from '../src/run.js'
import { RequestError } from '@octokit/request-error'

const octokitMock = {
Expand Down
9 changes: 2 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 0a9fa26

Please sign in to comment.