Skip to content

Commit fec54e6

Browse files
authoredApr 21, 2024··
Migrate to ESM (#932)
1 parent aa67a46 commit fec54e6

11 files changed

+25
-25
lines changed
 

‎eslint.config.mjs ‎eslint.config.js

File renamed without changes.

‎graphql-codegen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config: CodegenConfig = {
1212
preset: 'import-types',
1313
plugins: ['typescript-operations'],
1414
presetConfig: {
15-
typesPath: './graphql-types',
15+
typesPath: './graphql-types.js',
1616
},
1717
},
1818
},

‎jest.config.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
module.exports = {
2-
preset: 'ts-jest',
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: 'ts-jest/presets/default-esm',
34
clearMocks: true,
4-
testEnvironment: 'node',
5-
testMatch: ['**/*.test.ts'],
6-
verbose: true
5+
// https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
6+
moduleNameMapper: {
7+
'^(\\.{1,2}/.*)\\.js$': '$1',
8+
},
79
}

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test": "jest",
88
"graphql-codegen": "graphql-codegen --config graphql-codegen.ts"
99
},
10+
"type": "module",
1011
"dependencies": {
1112
"@actions/core": "1.10.1",
1213
"@actions/github": "6.0.0",

‎src/generated/graphql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Types from './graphql-types';
1+
import * as Types from './graphql-types.js';
22

33
export type CommentsQueryVariables = Types.Exact<{
44
owner: Types.Scalars['String']['input'];

‎src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as core from '@actions/core'
2-
import { run } from './run'
2+
import { run } from './run.js'
33

44
const main = async (): Promise<void> => {
55
await run({

‎src/queries/comments.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { GitHub } from '@actions/github/lib/utils'
2-
import { CommentsQuery, CommentsQueryVariables } from '../generated/graphql'
1+
import * as github from '@actions/github'
2+
import { CommentsQuery, CommentsQueryVariables } from '../generated/graphql.js'
33

4-
type Octokit = InstanceType<typeof GitHub>
4+
type Octokit = ReturnType<typeof github.getOctokit>
55

66
const query = /* GraphQL */ `
77
query comments($owner: String!, $name: String!, $number: Int!) {

‎src/queries/minimize.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { GitHub } from '@actions/github/lib/utils'
2-
import { MinimizeCommentMutation, MinimizeCommentMutationVariables } from '../generated/graphql'
1+
import * as github from '@actions/github'
2+
import { MinimizeCommentMutation, MinimizeCommentMutationVariables } from '../generated/graphql.js'
33

4-
type Octokit = InstanceType<typeof GitHub>
4+
type Octokit = ReturnType<typeof github.getOctokit>
55

66
const query = /* GraphQL */ `
77
mutation minimizeComment($id: ID!) {
@@ -13,7 +13,7 @@ const query = /* GraphQL */ `
1313

1414
export const minimizeComment = async (
1515
o: Octokit,
16-
v: MinimizeCommentMutationVariables
16+
v: MinimizeCommentMutationVariables,
1717
): Promise<MinimizeCommentMutation> => {
1818
return await o.graphql<MinimizeCommentMutation>(query, v)
1919
}

‎src/run.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
3-
import { GitHub } from '@actions/github/lib/utils'
4-
import { CommentsQuery } from './generated/graphql'
5-
import { queryComments } from './queries/comments'
6-
import { minimizeComment } from './queries/minimize'
3+
import { CommentsQuery } from './generated/graphql.js'
4+
import { queryComments } from './queries/comments.js'
5+
import { minimizeComment } from './queries/minimize.js'
76

8-
type Octokit = InstanceType<typeof GitHub>
7+
type Octokit = ReturnType<typeof github.getOctokit>
98

109
type Inputs = {
1110
authors: string[]

‎tests/run.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toMinimize } from '../src/run'
1+
import { toMinimize } from '../src/run.js'
22

33
describe('filter to minimize', () => {
44
test('no filter', () => {

‎tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"extends": "@tsconfig/node20/tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "./lib"
5-
}
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "@tsconfig/node20/tsconfig.json"
64
}

0 commit comments

Comments
 (0)
Please sign in to comment.