diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86072cb..d9d1e32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: - node-version: '20' + node-version: '24' - run: npm ci diff --git a/.node-version b/.node-version index 209e3ef..a45fd52 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -20 +24 diff --git a/action.yml b/action.yml index 97f0541..26245e8 100644 --- a/action.yml +++ b/action.yml @@ -14,5 +14,5 @@ outputs: jsonString: description: 'JSON string' runs: - using: 'node20' + using: 'node24' main: 'dist/index.js' diff --git a/fixtures/full-example/issue.js b/fixtures/full-example/issue.js index b83a5cfe..d8098d4 100644 --- a/fixtures/full-example/issue.js +++ b/fixtures/full-example/issue.js @@ -1,6 +1,8 @@ -const { resolve } = require("path"); -const { readFileSync } = require("fs"); +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +const __dirname = fileURLToPath(new URL(".", import.meta.url)); const issueBodyPath = resolve(__dirname, "issue-body.md"); -module.exports = readFileSync(issueBodyPath, "utf-8"); +export default readFileSync(issueBodyPath, "utf-8"); diff --git a/fixtures/mismatched-parsing/issue.js b/fixtures/mismatched-parsing/issue.js index b83a5cfe..d8098d4 100644 --- a/fixtures/mismatched-parsing/issue.js +++ b/fixtures/mismatched-parsing/issue.js @@ -1,6 +1,8 @@ -const { resolve } = require("path"); -const { readFileSync } = require("fs"); +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +const __dirname = fileURLToPath(new URL(".", import.meta.url)); const issueBodyPath = resolve(__dirname, "issue-body.md"); -module.exports = readFileSync(issueBodyPath, "utf-8"); +export default readFileSync(issueBodyPath, "utf-8"); diff --git a/fixtures/multiple-paragraphs/issue.js b/fixtures/multiple-paragraphs/issue.js index 6851c74..d8098d4 100644 --- a/fixtures/multiple-paragraphs/issue.js +++ b/fixtures/multiple-paragraphs/issue.js @@ -1,6 +1,8 @@ -const { resolve } = require("path"); -const { readFileSync } = require("fs"); +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +const __dirname = fileURLToPath(new URL(".", import.meta.url)); const issueBodyPath = resolve(__dirname, "issue-body.md"); -module.exports = readFileSync(issueBodyPath, "utf-8") +export default readFileSync(issueBodyPath, "utf-8"); diff --git a/fixtures/readme-example/issue.js b/fixtures/readme-example/issue.js index b83a5cfe..d8098d4 100644 --- a/fixtures/readme-example/issue.js +++ b/fixtures/readme-example/issue.js @@ -1,6 +1,8 @@ -const { resolve } = require("path"); -const { readFileSync } = require("fs"); +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +const __dirname = fileURLToPath(new URL(".", import.meta.url)); const issueBodyPath = resolve(__dirname, "issue-body.md"); -module.exports = readFileSync(issueBodyPath, "utf-8"); +export default readFileSync(issueBodyPath, "utf-8"); diff --git a/index.js b/index.js index 53cc884..cab1bce 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ // @ts-check -const fs = require("fs"); -const yaml = require("js-yaml"); -const core = require("@actions/core"); +import fs from "node:fs"; +import yaml from "js-yaml"; +import * as core from "@actions/core"; /** * @param {NodeJS.ProcessEnv} env @@ -10,7 +10,7 @@ const core = require("@actions/core"); * @param {fs} fs * @param {core} core */ -async function run(env, body, fs, core) { +export async function run(env, body, fs, core) { body = body ?? "" let form = {}; try { @@ -180,5 +180,3 @@ if (process.env.GITHUB_ACTIONS && process.env.NODE_ENV !== "test") { run(process.env, body, fs, core); } - -module.exports.run = run; diff --git a/package-lock.json b/package-lock.json index cbad899..186960b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.2.3", "license": "ISC", "dependencies": { - "@actions/core": "^2.0.1", + "@actions/core": "^3.0.1", "js-yaml": "^4.1.1" }, "devDependencies": { @@ -18,35 +18,39 @@ } }, "node_modules/@actions/core": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.1.tgz", - "integrity": "sha512-oBfqT3GwkvLlo1fjvhQLQxuwZCGTarTE5OuZ2Wg10hvhBj7LRIlF611WT4aZS6fDhO5ZKlY7lCAZTlpmyaHaeg==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.1.tgz", + "integrity": "sha512-a6d/Nwahm9fliVGRhdhofo40HjHQasUPusmc7vBfyky+7Z+P2A1J68zyFVaNcEclc/Se+eO595oAr5nwEIoIUA==", + "license": "MIT", "dependencies": { - "@actions/exec": "^2.0.0", - "@actions/http-client": "^3.0.0" + "@actions/exec": "^3.0.0", + "@actions/http-client": "^4.0.0" } }, "node_modules/@actions/exec": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz", - "integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz", + "integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==", + "license": "MIT", "dependencies": { - "@actions/io": "^2.0.0" + "@actions/io": "^3.0.2" } }, "node_modules/@actions/http-client": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.0.tgz", - "integrity": "sha512-1s3tXAfVMSz9a4ZEBkXXRQD4QhY3+GAsWSbaYpeknPOKEeyRiU3lH+bHiLMZdo2x/fIeQ/hscL1wCkDLVM2DZQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.1.tgz", + "integrity": "sha512-+Nvd1ImaOZBSoPbsUtEhv+1z99H12xzncCkz0a3RuehINE81FZSe2QTj3uvAPTcJX/SCzUQHQ0D1GrPMbrPitg==", + "license": "MIT", "dependencies": { "tunnel": "^0.0.6", - "undici": "^5.28.5" + "undici": "^6.23.0" } }, "node_modules/@actions/io": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz", - "integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==" + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", + "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", + "license": "MIT" }, "node_modules/@babel/code-frame": { "version": "7.29.0", @@ -540,14 +544,6 @@ "tslib": "^2.4.0" } }, - "node_modules/@fastify/busboy": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", - "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", - "engines": { - "node": ">=14" - } - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -3765,6 +3761,7 @@ "version": "0.0.6", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", "engines": { "node": ">=0.6.11 <=0.7.0 || >=0.7.3" } @@ -3791,14 +3788,12 @@ } }, "node_modules/undici": { - "version": "5.29.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", - "integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==", - "dependencies": { - "@fastify/busboy": "^2.0.0" - }, + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.25.0.tgz", + "integrity": "sha512-ZgpWDC5gmNiuY9CnLVXEH8rl50xhRCuLNA97fAUnKi8RRuV4E6KG31pDTsLVUKnohJE0I3XDrTeEydAXRw47xg==", + "license": "MIT", "engines": { - "node": ">=14.0" + "node": ">=18.17" } }, "node_modules/undici-types": { @@ -4114,35 +4109,35 @@ }, "dependencies": { "@actions/core": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.1.tgz", - "integrity": "sha512-oBfqT3GwkvLlo1fjvhQLQxuwZCGTarTE5OuZ2Wg10hvhBj7LRIlF611WT4aZS6fDhO5ZKlY7lCAZTlpmyaHaeg==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.1.tgz", + "integrity": "sha512-a6d/Nwahm9fliVGRhdhofo40HjHQasUPusmc7vBfyky+7Z+P2A1J68zyFVaNcEclc/Se+eO595oAr5nwEIoIUA==", "requires": { - "@actions/exec": "^2.0.0", - "@actions/http-client": "^3.0.0" + "@actions/exec": "^3.0.0", + "@actions/http-client": "^4.0.0" } }, "@actions/exec": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz", - "integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz", + "integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==", "requires": { - "@actions/io": "^2.0.0" + "@actions/io": "^3.0.2" } }, "@actions/http-client": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.0.tgz", - "integrity": "sha512-1s3tXAfVMSz9a4ZEBkXXRQD4QhY3+GAsWSbaYpeknPOKEeyRiU3lH+bHiLMZdo2x/fIeQ/hscL1wCkDLVM2DZQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.1.tgz", + "integrity": "sha512-+Nvd1ImaOZBSoPbsUtEhv+1z99H12xzncCkz0a3RuehINE81FZSe2QTj3uvAPTcJX/SCzUQHQ0D1GrPMbrPitg==", "requires": { "tunnel": "^0.0.6", - "undici": "^5.28.5" + "undici": "^6.23.0" } }, "@actions/io": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz", - "integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==" + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", + "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==" }, "@babel/code-frame": { "version": "7.29.0", @@ -4506,11 +4501,6 @@ "tslib": "^2.4.0" } }, - "@fastify/busboy": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", - "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==" - }, "@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -6895,12 +6885,9 @@ "dev": true }, "undici": { - "version": "5.29.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", - "integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==", - "requires": { - "@fastify/busboy": "^2.0.0" - } + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.25.0.tgz", + "integrity": "sha512-ZgpWDC5gmNiuY9CnLVXEH8rl50xhRCuLNA97fAUnKi8RRuV4E6KG31pDTsLVUKnohJE0I3XDrTeEydAXRw47xg==" }, "undici-types": { "version": "7.18.2", diff --git a/package.json b/package.json index eef9560..10e99d2 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "version": "3.2.3", "description": "", "main": "index.js", + "type": "module", "scripts": { "build": "ncc build", - "test": "jest ." + "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js ." }, "repository": { "type": "git", @@ -20,7 +21,7 @@ }, "homepage": "https://github.com/stefanbuck/github-issue-parser#readme", "dependencies": { - "@actions/core": "^2.0.1", + "@actions/core": "^3.0.1", "js-yaml": "^4.1.1" }, "devDependencies": { diff --git a/test.spec.js b/test.spec.js index c3ce9bc..a7d380d 100644 --- a/test.spec.js +++ b/test.spec.js @@ -1,6 +1,16 @@ -const { readFileSync } = require("fs"); +import { readFileSync } from "node:fs"; +import { jest, it, expect } from "@jest/globals"; -const { run } = require("."); +import { run } from "./index.js"; + +import readmeExampleIssue from "./fixtures/readme-example/issue.js"; +import fullExampleIssue from "./fixtures/full-example/issue.js"; +import mismatchedParsingIssue from "./fixtures/mismatched-parsing/issue.js"; +import multipleParagraphsIssue from "./fixtures/multiple-paragraphs/issue.js"; + +function loadJson(path) { + return JSON.parse(readFileSync(path, "utf-8")); +} it("smoke test", () => { expect(run).toBeDefined(); @@ -8,7 +18,7 @@ it("smoke test", () => { }); it("readme example", () => { - const expectedOutput = require("./fixtures/readme-example/expected.json"); + const expectedOutput = loadJson("./fixtures/readme-example/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); // mock ENV @@ -17,7 +27,7 @@ it("readme example", () => { }; // mock event payload - const eventPayload = require("./fixtures/readme-example/issue"); + const eventPayload = readmeExampleIssue; // mock fs const fs = { @@ -47,7 +57,7 @@ it("readme example", () => { }); it("full example", () => { - const expectedOutput = require("./fixtures/full-example/expected.json"); + const expectedOutput = loadJson("./fixtures/full-example/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); // mock ENV @@ -56,7 +66,7 @@ it("full example", () => { }; // mock event payload - const eventPayload = require("./fixtures/full-example/issue"); + const eventPayload = fullExampleIssue; // mock fs const fs = { @@ -91,7 +101,7 @@ it("full example", () => { }); it("mismatched parsing", () => { - const expectedOutput = require("./fixtures/mismatched-parsing/expected.json"); + const expectedOutput = loadJson("./fixtures/mismatched-parsing/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); // mock ENV @@ -100,7 +110,7 @@ it("mismatched parsing", () => { }; // mock event payload - const eventPayload = require("./fixtures/mismatched-parsing/issue"); + const eventPayload = mismatchedParsingIssue; // mock fs const fs = { @@ -135,7 +145,7 @@ it("mismatched parsing", () => { }); it("multiple paragraphs", () => { - const expectedOutput = require("./fixtures/multiple-paragraphs/expected.json"); + const expectedOutput = loadJson("./fixtures/multiple-paragraphs/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); // mock ENV @@ -144,7 +154,7 @@ it("multiple paragraphs", () => { }; // mock event payload - const eventPayload = require("./fixtures/multiple-paragraphs/issue"); + const eventPayload = multipleParagraphsIssue; // mock fs const fs = { @@ -175,7 +185,7 @@ it("multiple paragraphs", () => { }); it("blank", () => { - const expectedOutput = require("./fixtures/blank/expected.json"); + const expectedOutput = loadJson("./fixtures/blank/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); // mock ENV