Skip to content

Commit f167412

Browse files
committed
Various modernizations
Includes upgrading `whatwg-mimetype` to v5.0.0 and adding auto-publication.
1 parent 4a3662d commit f167412

File tree

9 files changed

+63
-45
lines changed

9 files changed

+63
-45
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
name: Build
2+
23
on:
34
pull_request:
4-
branches: [main]
5+
branches:
6+
- main
57
push:
6-
branches: [main]
8+
branches:
9+
- main
10+
711
jobs:
812
build:
913
name: Lint and tests
@@ -14,6 +18,7 @@ jobs:
1418
node-version:
1519
- 20
1620
- 22
21+
- 24
1722
- latest
1823
steps:
1924
- uses: actions/checkout@v6

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6
17+
- uses: actions/setup-node@v6
18+
with:
19+
node-version: lts/*
20+
registry-url: https://registry.npmjs.org
21+
- run: npm ci
22+
- run: npm run lint
23+
- run: npm test
24+
- run: npm publish

eslint.config.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ export default [
99
globals: globals.node
1010
}
1111
},
12-
...domenicConfig,
1312
{
14-
files: ["scripts/**.js"],
15-
rules: {
16-
"no-process-env": "off",
17-
"no-process-exit": "off",
18-
"no-console": "off"
13+
files: ["**/*.mjs"],
14+
languageOptions: {
15+
sourceType: "module",
16+
globals: globals.node
1917
}
20-
}
18+
},
19+
...domenicConfig
2120
];

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
const MIMEType = require("whatwg-mimetype");
2+
const { MIMEType } = require("whatwg-mimetype");
33
const { parseURL, serializeURL, percentDecodeString } = require("whatwg-url");
44
const { stripLeadingAndTrailingASCIIWhitespace, isomorphicDecode, forgivingBase64Decode } = require("./utils.js");
55

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"scripts": {
2424
"test": "node --test",
2525
"coverage": "c8 node --test --experimental-test-coverage",
26-
"lint": "eslint .",
27-
"pretest": "node scripts/get-latest-platform-tests.js"
26+
"lint": "eslint",
27+
"pretest": "node scripts/get-latest-platform-tests.mjs"
2828
},
2929
"dependencies": {
30-
"whatwg-mimetype": "^4.0.0",
30+
"whatwg-mimetype": "^5.0.0",
3131
"whatwg-url": "^15.1.0"
3232
},
3333
"devDependencies": {
@@ -41,7 +41,6 @@
4141
},
4242
"c8": {
4343
"reporter": [
44-
"text",
4544
"html"
4645
],
4746
"exclude": [
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
1-
"use strict";
1+
import * as path from "node:path";
2+
import * as fs from "node:fs/promises";
23

34
if (process.env.NO_UPDATE) {
45
process.exit(0);
56
}
67

7-
const path = require("node:path");
8-
const fs = require("node:fs/promises");
9-
108
// Pin to specific version, reflecting the spec version in the readme.
119
//
1210
// To get the latest commit:
1311
// 1. Go to https://github.com/web-platform-tests/wpt/tree/master/fetch/data-urls
1412
// 2. Press "y" on your keyboard to get a permalink
1513
// 3. Copy the commit hash
16-
const commitHash = "d9d78543960a04ea8ad8f1aa3c7536b6a9a87d9a";
14+
const commitHash = "2dc0ad4f330f0b5647d11b00ae7437b668cb8df3";
1715

1816
const urlPrefix = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}` +
1917
`/fetch/data-urls/resources/`;
2018

2119
const files = ["base64.json", "data-urls.json"];
2220

23-
async function main() {
24-
await Promise.all(files.map(async file => {
25-
const url = urlPrefix + file;
26-
const targetFile = path.resolve(__dirname, "..", "test", "web-platform-tests", file);
27-
28-
const res = await fetch(url);
29-
await fs.writeFile(targetFile, res.body);
30-
}));
31-
}
21+
await Promise.all(files.map(async file => {
22+
const url = urlPrefix + file;
23+
const targetFile = path.resolve(import.meta.dirname, "..", "test", "web-platform-tests", file);
3224

33-
main().catch(e => {
34-
console.error(e.stack);
35-
process.exit(1);
36-
});
25+
const res = await fetch(url);
26+
await fs.writeFile(targetFile, res.body);
27+
}));

test/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
const { describe, it } = require("node:test");
3-
const assert = require("node:assert");
3+
const assert = require("node:assert/strict");
44
const parseDataURL = require("..");
55
/*
66
eslint

test/web-platform.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"use strict";
22
const { describe, test } = require("node:test");
3-
const assert = require("node:assert");
3+
const assert = require("node:assert/strict");
44
const base64TestCases = require("./web-platform-tests/base64.json");
55
const dataURLsTestCases = require("./web-platform-tests/data-urls.json");
6-
const parse = require("../lib/parser.js");
6+
const parseDataURL = require("..");
77

88
describe("base64.json", () => {
99
for (const [input, expectedBodyBytes] of base64TestCases) {
1010
const dataURL = `data:;base64,${input}`;
1111
test(dataURL, () => {
12-
const result = parse(dataURL);
12+
const result = parseDataURL(dataURL);
1313

1414
if (expectedBodyBytes === null) {
1515
assert.equal(result, null);
@@ -29,7 +29,7 @@ describe("base64.json", () => {
2929
describe("data-urls.json", () => {
3030
for (const [dataURL, expectedMIMEType, expectedBodyBytes] of dataURLsTestCases) {
3131
test(dataURL, () => {
32-
const result = parse(dataURL);
32+
const result = parseDataURL(dataURL);
3333

3434
if (expectedMIMEType === null) {
3535
assert.equal(result, null);

0 commit comments

Comments
 (0)