From cb35da32776a7661bfba55b4e6f317a9aa0aed6d Mon Sep 17 00:00:00 2001 From: Aaron Dewes Date: Mon, 29 Apr 2024 22:50:06 +0200 Subject: [PATCH] Convert repository to ESM Converts the repository to use ESM syntax, enabling module support. - Adds `"type": "module"` to `package.json` to specify ESM support. - Updates `app.js` and `netlify/functions/webhooks.js` by replacing `require` statements with `import` statements and changing `module.exports` to `export default`. - Modifies `test.js` to use ESM import/export syntax, including updating `require` statements to `import` and changing `module.exports` to `export default` for the test suite. --- app.js | 2 +- netlify/functions/webhooks.js | 6 +++--- package.json | 1 + test.js | 10 +++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 7aed666..2f28ad3 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,7 @@ /** * @param {import('probot').Probot} app */ -module.exports = (app) => { +export default (app) => { app.log.info("Yay! The app was loaded!"); app.on("issues.opened", async (context) => { diff --git a/netlify/functions/webhooks.js b/netlify/functions/webhooks.js index a9e290e..195723d 100644 --- a/netlify/functions/webhooks.js +++ b/netlify/functions/webhooks.js @@ -1,5 +1,5 @@ -const { createProbot } = require("probot"); -const app = require("../../app"); +import { createProbot } from "probot"; +import app from "../../app.js"; const probot = createProbot(); const loadingApp = probot.load(app); @@ -10,7 +10,7 @@ const loadingApp = probot.load(app); * @param {import("@netlify/functions").HandlerEvent} event * @param {import("@netlify/functions").HandlerContext} context */ -exports.handler = async function (event, context) { +export const handler = async function (event, context) { try { await loadingApp; diff --git a/package.json b/package.json index dc1148f..b6b25f0 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "description": "Probot & Netlify Functions example", "main": "app.js", + "type": "module", "scripts": { "start": "probot run ./app.js", "test": "node test.js" diff --git a/test.js b/test.js index 5eb379c..ba430b7 100644 --- a/test.js +++ b/test.js @@ -1,12 +1,12 @@ -const { suite } = require("uvu"); -const assert = require("uvu/assert"); +import { suite } from "uvu"; +import * as assert from "uvu/assert"; -const nock = require("nock"); +import nock from "nock"; nock.disableNetConnect(); -const { Probot, ProbotOctokit } = require("probot"); +import { Probot, ProbotOctokit } from "probot"; -const app = require("./app"); +import app from "./app.js"; /** @type {import('probot').Probot */ let probot;