From 4ecbf1b58d3f7b749192d26beb973afc2e3ebca5 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 20 Jan 2026 12:15:17 +0900 Subject: [PATCH] Various modernizations Includes upgrading `whatwg-mimetype` to v5.0.0 and adding auto-publication. --- .github/workflows/build.yml | 9 +++++-- .github/workflows/publish.yml | 24 +++++++++++++++++ eslint.config.mjs | 13 +++++---- lib/parser.js | 2 +- package-lock.json | 16 +++++------ package.json | 7 +++-- ...tests.js => get-latest-platform-tests.mjs} | 27 +++++++------------ test/api.js | 2 +- test/web-platform.js | 8 +++--- 9 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/publish.yml rename scripts/{get-latest-platform-tests.js => get-latest-platform-tests.mjs} (50%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65237c1..3cf9494 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,13 @@ name: Build + on: pull_request: - branches: [main] + branches: + - main push: - branches: [main] + branches: + - main + jobs: build: name: Lint and tests @@ -14,6 +18,7 @@ jobs: node-version: - 20 - 22 + - 24 - latest steps: - uses: actions/checkout@v6 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f5a9e5a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,24 @@ +name: Publish + +on: + push: + tags: + - 'v*' + +permissions: + id-token: write + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version: lts/* + registry-url: https://registry.npmjs.org + - run: npm ci + - run: npm run lint + - run: npm test + - run: npm publish diff --git a/eslint.config.mjs b/eslint.config.mjs index a11b6f6..3abba68 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,13 +9,12 @@ export default [ globals: globals.node } }, - ...domenicConfig, { - files: ["scripts/**.js"], - rules: { - "no-process-env": "off", - "no-process-exit": "off", - "no-console": "off" + files: ["**/*.mjs"], + languageOptions: { + sourceType: "module", + globals: globals.node } - } + }, + ...domenicConfig ]; diff --git a/lib/parser.js b/lib/parser.js index 08e9197..f3f708f 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,5 +1,5 @@ "use strict"; -const MIMEType = require("whatwg-mimetype"); +const { MIMEType } = require("whatwg-mimetype"); const { parseURL, serializeURL, percentDecodeString } = require("whatwg-url"); const { stripLeadingAndTrailingASCIIWhitespace, isomorphicDecode, forgivingBase64Decode } = require("./utils.js"); diff --git a/package-lock.json b/package-lock.json index 96fe2b0..664cf5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "6.0.0", "license": "MIT", "dependencies": { - "whatwg-mimetype": "^4.0.0", + "whatwg-mimetype": "^5.0.0", "whatwg-url": "^15.1.0" }, "devDependencies": { @@ -1718,21 +1718,21 @@ } }, "node_modules/webidl-conversions": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.0.tgz", - "integrity": "sha512-n4W4YFyz5JzOfQeA8oN7dUYpR+MBP3PIUsn2jLjWXwK5ASUzt0Jc/A5sAUZoCYFJRGF0FBKJ+1JjN43rNdsQzA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz", + "integrity": "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==", "license": "BSD-2-Clause", "engines": { "node": ">=20" } }, "node_modules/whatwg-mimetype": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", - "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz", + "integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==", "license": "MIT", "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/whatwg-url": { diff --git a/package.json b/package.json index af69f16..a5618b2 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "scripts": { "test": "node --test", "coverage": "c8 node --test --experimental-test-coverage", - "lint": "eslint .", - "pretest": "node scripts/get-latest-platform-tests.js" + "lint": "eslint", + "pretest": "node scripts/get-latest-platform-tests.mjs" }, "dependencies": { - "whatwg-mimetype": "^4.0.0", + "whatwg-mimetype": "^5.0.0", "whatwg-url": "^15.1.0" }, "devDependencies": { @@ -41,7 +41,6 @@ }, "c8": { "reporter": [ - "text", "html" ], "exclude": [ diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.mjs similarity index 50% rename from scripts/get-latest-platform-tests.js rename to scripts/get-latest-platform-tests.mjs index eb3b7ba..9b9bc28 100644 --- a/scripts/get-latest-platform-tests.js +++ b/scripts/get-latest-platform-tests.mjs @@ -1,36 +1,27 @@ -"use strict"; +import * as path from "node:path"; +import * as fs from "node:fs/promises"; if (process.env.NO_UPDATE) { process.exit(0); } -const path = require("node:path"); -const fs = require("node:fs/promises"); - // Pin to specific version, reflecting the spec version in the readme. // // To get the latest commit: // 1. Go to https://github.com/web-platform-tests/wpt/tree/master/fetch/data-urls // 2. Press "y" on your keyboard to get a permalink // 3. Copy the commit hash -const commitHash = "d9d78543960a04ea8ad8f1aa3c7536b6a9a87d9a"; +const commitHash = "2dc0ad4f330f0b5647d11b00ae7437b668cb8df3"; const urlPrefix = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}` + `/fetch/data-urls/resources/`; const files = ["base64.json", "data-urls.json"]; -async function main() { - await Promise.all(files.map(async file => { - const url = urlPrefix + file; - const targetFile = path.resolve(__dirname, "..", "test", "web-platform-tests", file); - - const res = await fetch(url); - await fs.writeFile(targetFile, res.body); - })); -} +await Promise.all(files.map(async file => { + const url = urlPrefix + file; + const targetFile = path.resolve(import.meta.dirname, "..", "test", "web-platform-tests", file); -main().catch(e => { - console.error(e.stack); - process.exit(1); -}); + const res = await fetch(url); + await fs.writeFile(targetFile, res.body); +})); diff --git a/test/api.js b/test/api.js index 372a91d..8a3f294 100644 --- a/test/api.js +++ b/test/api.js @@ -1,6 +1,6 @@ "use strict"; const { describe, it } = require("node:test"); -const assert = require("node:assert"); +const assert = require("node:assert/strict"); const parseDataURL = require(".."); /* eslint diff --git a/test/web-platform.js b/test/web-platform.js index 2842a49..869d0ac 100644 --- a/test/web-platform.js +++ b/test/web-platform.js @@ -1,15 +1,15 @@ "use strict"; const { describe, test } = require("node:test"); -const assert = require("node:assert"); +const assert = require("node:assert/strict"); const base64TestCases = require("./web-platform-tests/base64.json"); const dataURLsTestCases = require("./web-platform-tests/data-urls.json"); -const parse = require("../lib/parser.js"); +const parseDataURL = require(".."); describe("base64.json", () => { for (const [input, expectedBodyBytes] of base64TestCases) { const dataURL = `data:;base64,${input}`; test(dataURL, () => { - const result = parse(dataURL); + const result = parseDataURL(dataURL); if (expectedBodyBytes === null) { assert.equal(result, null); @@ -29,7 +29,7 @@ describe("base64.json", () => { describe("data-urls.json", () => { for (const [dataURL, expectedMIMEType, expectedBodyBytes] of dataURLsTestCases) { test(dataURL, () => { - const result = parse(dataURL); + const result = parseDataURL(dataURL); if (expectedMIMEType === null) { assert.equal(result, null);