From 65cb74faa4a5e39cec4308b00d5d852e302c94b1 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:56:58 +0000 Subject: [PATCH] refactor: port github-bot to ESM This is one of those annoying things. Updating OctoKit updated some transitive sindresorhus dependency which now forces onto ESM. This proves to be a pretty annoying problem because you can't use CommonJS from inside ESM and vice versa. Somehow, as an industry, we've managed to invent "what color is your import" for NodeJS, which is a pretty brutal problem. Anyway. I've made this specific package into an ESM module, and what it compiles to is a module now, too, instead of CommonJS. Luckily, because the github bot is so small and isolated, it means we have very little trouble doing this (and hopefully no brutal side effects). --- github-bot/package.json | 3 ++- github-bot/src/main.ts | 2 +- github-bot/tsconfig.json | 3 ++- pnpm-lock.yaml | 43 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/github-bot/package.json b/github-bot/package.json index ce58c3785..2224ed546 100644 --- a/github-bot/package.json +++ b/github-bot/package.json @@ -4,6 +4,7 @@ "private": true, "description": "A GitHub bot for listening to Tachi's GitHub Repo.", "author": "zk", + "type": "module", "scripts": { "build": "tsc -b", "start": "tsc -b && node js/main.js" @@ -13,7 +14,7 @@ "@octokit/webhooks-types": "7.5.1", "dotenv": "16.0.0", "express": "4.17.2", - "node-fetch": "2.6.7", + "node-fetch": "3.3.2", "prudence": "0.10.0" }, "devDependencies": { diff --git a/github-bot/src/main.ts b/github-bot/src/main.ts index 5afef5994..d275f3bfb 100644 --- a/github-bot/src/main.ts +++ b/github-bot/src/main.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { ProcessEnv } from "./config"; +import { ProcessEnv } from "./config.js"; import { App, createNodeMiddleware } from "@octokit/app"; import express from "express"; import fetch from "node-fetch"; diff --git a/github-bot/tsconfig.json b/github-bot/tsconfig.json index ce059e614..e1e46cbf2 100644 --- a/github-bot/tsconfig.json +++ b/github-bot/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../tsconfig.json", "compilerOptions": { "target": "es6", - "module": "commonjs", + "module": "ES6", + "moduleResolution": "Node16", "lib": [ "es2015", "es2017", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a830378d..1ed8383e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -396,8 +396,8 @@ importers: specifier: 4.17.2 version: 4.17.2 node-fetch: - specifier: 2.6.7 - version: 2.6.7 + specifier: 3.3.2 + version: 3.3.2 prudence: specifier: 0.10.0 version: 0.10.0 @@ -5350,6 +5350,11 @@ packages: assert-plus: 1.0.0 dev: false + /data-uri-to-buffer@4.0.1: + resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==} + engines: {node: '>= 12'} + dev: false + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -6689,6 +6694,14 @@ packages: resolution: {integrity: sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==} dev: false + /fetch-blob@3.2.0: + resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} + engines: {node: ^12.20 || >= 14.13} + dependencies: + node-domexception: 1.0.0 + web-streams-polyfill: 3.3.3 + dev: false + /file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -6858,6 +6871,13 @@ packages: combined-stream: 1.0.8 mime-types: 2.1.35 + /formdata-polyfill@4.0.10: + resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} + engines: {node: '>=12.20.0'} + dependencies: + fetch-blob: 3.2.0 + dev: false + /formidable@2.0.1: resolution: {integrity: sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==} dependencies: @@ -9148,6 +9168,11 @@ packages: clone: 2.1.2 dev: false + /node-domexception@1.0.0: + resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} + engines: {node: '>=10.5.0'} + dev: false + /node-fetch@1.7.3: resolution: {integrity: sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==} dependencies: @@ -9171,6 +9196,15 @@ packages: dependencies: whatwg-url: 5.0.0 + /node-fetch@3.3.2: + resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + data-uri-to-buffer: 4.0.1 + fetch-blob: 3.2.0 + formdata-polyfill: 4.0.10 + dev: false + /node-gyp-build-optional-packages@5.0.3: resolution: {integrity: sha512-k75jcVzk5wnnc/FMxsf4udAoTEUv2jY3ycfdSd3yWu6Cnd1oee6/CfZJApyscA4FJOmdoixWwiwOyf16RzD5JA==} hasBin: true @@ -12021,6 +12055,11 @@ packages: loose-envify: 1.4.0 dev: false + /web-streams-polyfill@3.3.3: + resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==} + engines: {node: '>= 8'} + dev: false + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}