Skip to content

Commit

Permalink
chore: migrate to esm (#418)
Browse files Browse the repository at this point in the history
* chore: migrate to esm

* rename files back to .js
  • Loading branch information
Uzlopak authored Dec 23, 2024
1 parent bb4a376 commit ca88bf9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
14 changes: 5 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'
import fastify from 'fastify'

const fastify = require('fastify')
import { fetchIssues as defaultFetchIssues, getGithubClient as defaultGetGithubClient } from './fetch-issues.js'
import { createCache } from 'async-cache-dedupe'

const { fetchIssues: defaultFetchIssues, getGithubClient: defaultGetGithubClient } = require('./fetchIssues')
const { createCache } = require('async-cache-dedupe')

function build (opts) {
export async function build (opts) {
const app = fastify(opts)
const cache = createCache({
ttl: 5 * 60, // 5 minutes
Expand All @@ -22,7 +20,7 @@ function build (opts) {
...opts
}

app.register(require('@fastify/cors'), {})
app.register(await import('@fastify/cors'), {})

cache.define('fetchIssues', async ({ includeBody, labels, org }) => {
return await fetchIssues(includeBody, labels, org, getGithubClient())
Expand Down Expand Up @@ -74,5 +72,3 @@ function build (opts) {
})
return app
}

module.exports = build
6 changes: 3 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
import neostandard from 'neostandard'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
export default neostandard({
ignores: (await import('neostandard')).resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 2 additions & 4 deletions fetchIssues.js → fetch-issues.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

const { Octokit } = require('@octokit/rest')
import { Octokit } from '@octokit/rest'

/* c8 ignore start */
const getGithubClient = () => {
Expand Down Expand Up @@ -53,4 +51,4 @@ const fetchIssues = async (includeBody, labels, org, client) => {
return Array.from(dedupeMap.values())
}

module.exports = { fetchIssues, getGithubClient }
export { fetchIssues, getGithubClient }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "Tool to help find issues hat you can contribute to",
"main": "server.js",
"type": "commonjs",
"type": "module",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
import { build } from './app.js'

const server = require('./app')({
const server = await build({
logger: true
})

Expand Down
10 changes: 4 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const { test } = require('node:test')
const { fetchIssues } = require('./fetchIssues')
import { test } from 'node:test'
import { fetchIssues } from './fetch-issues.js'

const mockIssue = {
url: 'https://api.github.com/repos/fastify/help/issues/478',
Expand Down Expand Up @@ -107,8 +105,8 @@ test('tests the "/api/find-issues" route', async t => {
}
}

const build = require('./app')
const app = build({
const { build } = await import('./app.js')
const app = await build({
fetchIssues,
getGithubClient: () => {
return {
Expand Down

0 comments on commit ca88bf9

Please sign in to comment.