Skip to content

Commit

Permalink
Migrate to ESM (#265)
Browse files Browse the repository at this point in the history
* Migrate to ESM

* Fix
  • Loading branch information
int128 authored Apr 7, 2024
1 parent e8a382e commit 8343489
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion graphql-codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config: CodegenConfig = {
preset: 'import-types',
plugins: ['typescript-operations'],
presetConfig: {
typesPath: './graphql-types',
typesPath: './graphql-types.js',
},
},
},
Expand Down
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',
},
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "jest",
"graphql-codegen": "graphql-codegen --config graphql-codegen.ts"
},
"type": "module",
"dependencies": {
"@actions/core": "1.10.1",
"@actions/exec": "1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/checks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert'
import * as minimatch from 'minimatch'
import { ListChecksQuery } from './generated/graphql'
import { CheckConclusionState, CheckStatusState, StatusState } from './generated/graphql-types'
import { ListChecksQuery } from './generated/graphql.js'
import { CheckConclusionState, CheckStatusState, StatusState } from './generated/graphql-types.js'

export type Rollup = {
state: State
Expand Down
2 changes: 1 addition & 1 deletion src/generated/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Types from './graphql-types';
import * as Types from './graphql-types.js';

export type ListChecksQueryVariables = Types.Exact<{
owner: Types.Scalars['String']['input'];
Expand Down
9 changes: 3 additions & 6 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { getOctokitOptions, GitHub } from '@actions/github/lib/utils'
import * as github from '@actions/github'
import * as pluginRetry from '@octokit/plugin-retry'

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

export const getOctokit = (token: string): Octokit => {
const MyOctokit = GitHub.plugin(pluginRetry.retry)
return new MyOctokit(getOctokitOptions(token))
}
export const getOctokit = (token: string): Octokit => github.getOctokit(token, pluginRetry.retry)
2 changes: 1 addition & 1 deletion src/main.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 { run } from './run'
import { run } from './run.js'

const main = async (): Promise<void> => {
await run({
Expand Down
4 changes: 2 additions & 2 deletions src/queries/listChecks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert'
import * as core from '@actions/core'
import { ListChecksQuery, ListChecksQueryVariables } from '../generated/graphql'
import { Octokit } from '../github'
import { ListChecksQuery, ListChecksQueryVariables } from '../generated/graphql.js'
import { Octokit } from '../github.js'

const query = /* GraphQL */ `
query listChecks($owner: String!, $name: String!, $oid: GitObjectID!, $appId: Int!, $afterCursor: String) {
Expand Down
8 changes: 4 additions & 4 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import * as listChecks from './queries/listChecks'
import { Rollup, filterFailedWorkflowRuns, rollupChecks } from './checks'
import { StatusState } from './generated/graphql-types'
import { getOctokit } from './github'
import * as listChecks from './queries/listChecks.js'
import { Rollup, filterFailedWorkflowRuns, rollupChecks } from './checks.js'
import { StatusState } from './generated/graphql-types.js'
import { getOctokit } from './github.js'

// https://api.github.com/apps/github-actions
const GITHUB_ACTIONS_APP_ID = 15368
Expand Down
6 changes: 3 additions & 3 deletions tests/checks.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rollup, rollupWorkflowRuns, rollupChecks } from '../src/checks'
import { ListChecksQuery } from '../src/generated/graphql'
import { CheckConclusionState, CheckStatusState, StatusState } from '../src/generated/graphql-types'
import { Rollup, rollupWorkflowRuns, rollupChecks } from '../src/checks.js'
import { ListChecksQuery } from '../src/generated/graphql.js'
import { CheckConclusionState, CheckStatusState, StatusState } from '../src/generated/graphql-types.js'

describe('rollupChecks', () => {
const query: ListChecksQuery = {
Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
}
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/node20/tsconfig.json"
}

0 comments on commit 8343489

Please sign in to comment.