[mastodon-client] Switch to happy-dom

This commit is contained in:
Laura Hausmann 2023-11-25 02:04:55 +01:00
parent 60a6e08c0b
commit f350755721
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 64 additions and 10 deletions

25
.pnp.cjs generated
View file

@ -7241,6 +7241,7 @@ const RAW_RUNTIME_STATE =
["fluent-ffmpeg", "npm:2.1.2"],\ ["fluent-ffmpeg", "npm:2.1.2"],\
["got", "npm:12.5.3"],\ ["got", "npm:12.5.3"],\
["gunzip-maybe", "npm:1.4.2"],\ ["gunzip-maybe", "npm:1.4.2"],\
["happy-dom", "npm:12.10.3"],\
["hpagent", "npm:0.1.2"],\ ["hpagent", "npm:0.1.2"],\
["iceshrimp-js", "workspace:packages/iceshrimp-js"],\ ["iceshrimp-js", "workspace:packages/iceshrimp-js"],\
["ioredis", "npm:5.3.2"],\ ["ioredis", "npm:5.3.2"],\
@ -9594,6 +9595,15 @@ const RAW_RUNTIME_STATE =
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
]],\ ]],\
["css.escape", [\
["npm:1.5.1", {\
"packageLocation": "./.yarn/cache/css.escape-npm-1.5.1-b24d2ba77a-f6d38088d8.zip/node_modules/css.escape/",\
"packageDependencies": [\
["css.escape", "npm:1.5.1"]\
],\
"linkType": "HARD"\
}]\
]],\
["cssesc", [\ ["cssesc", [\
["npm:3.0.0", {\ ["npm:3.0.0", {\
"packageLocation": "./.yarn/cache/cssesc-npm-3.0.0-15ec56f86f-0e161912c1.zip/node_modules/cssesc/",\ "packageLocation": "./.yarn/cache/cssesc-npm-3.0.0-15ec56f86f-0e161912c1.zip/node_modules/cssesc/",\
@ -13665,6 +13675,21 @@ const RAW_RUNTIME_STATE =
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
]],\ ]],\
["happy-dom", [\
["npm:12.10.3", {\
"packageLocation": "./.yarn/cache/happy-dom-npm-12.10.3-5cca1a5e23-de82ddd1c9.zip/node_modules/happy-dom/",\
"packageDependencies": [\
["happy-dom", "npm:12.10.3"],\
["css.escape", "npm:1.5.1"],\
["entities", "npm:4.5.0"],\
["iconv-lite", "npm:0.6.3"],\
["webidl-conversions", "npm:7.0.0"],\
["whatwg-encoding", "npm:2.0.0"],\
["whatwg-mimetype", "npm:3.0.0"]\
],\
"linkType": "HARD"\
}]\
]],\
["hard-rejection", [\ ["hard-rejection", [\
["npm:2.1.0", {\ ["npm:2.1.0", {\
"packageLocation": "./.yarn/cache/hard-rejection-npm-2.1.0-a80f2a977d-7baaf80a0c.zip/node_modules/hard-rejection/",\ "packageLocation": "./.yarn/cache/hard-rejection-npm-2.1.0-a80f2a977d-7baaf80a0c.zip/node_modules/hard-rejection/",\

BIN
.yarn/cache/css.escape-npm-1.5.1-b24d2ba77a-f6d38088d8.zip (Stored with Git LFS) vendored Normal file

Binary file not shown.

BIN
.yarn/cache/happy-dom-npm-12.10.3-5cca1a5e23-de82ddd1c9.zip (Stored with Git LFS) vendored Normal file

Binary file not shown.

View file

@ -66,6 +66,7 @@
"fluent-ffmpeg": "2.1.2", "fluent-ffmpeg": "2.1.2",
"got": "12.5.3", "got": "12.5.3",
"gunzip-maybe": "^1.4.2", "gunzip-maybe": "^1.4.2",
"happy-dom": "^12.10.3",
"hpagent": "0.1.2", "hpagent": "0.1.2",
"iceshrimp-js": "workspace:*", "iceshrimp-js": "workspace:*",
"ioredis": "5.3.2", "ioredis": "5.3.2",

View file

@ -1,5 +1,5 @@
import { IMentionedRemoteUsers } from "@/models/entities/note.js"; import { IMentionedRemoteUsers } from "@/models/entities/note.js";
import { JSDOM } from "jsdom"; import { Window as HappyDom } from "happy-dom";
import config from "@/config/index.js"; import config from "@/config/index.js";
import { intersperse } from "@/prelude/array.js"; import { intersperse } from "@/prelude/array.js";
import mfm from "mfm-js"; import mfm from "mfm-js";
@ -17,7 +17,7 @@ export class MfmHelpers {
return null; return null;
} }
const { window } = new JSDOM(""); const { window } = new HappyDom();
const doc = window.document; const doc = window.document;
@ -101,7 +101,7 @@ export class MfmHelpers {
hashtag(node) { hashtag(node) {
const a = doc.createElement("a"); const a = doc.createElement("a");
a.href = `${config.url}/tags/${node.props.hashtag}`; a.setAttribute('href', `${config.url}/tags/${node.props.hashtag}`);
a.textContent = `#${node.props.hashtag}`; a.textContent = `#${node.props.hashtag}`;
a.setAttribute("rel", "tag"); a.setAttribute("rel", "tag");
a.setAttribute("class", "hashtag"); a.setAttribute("class", "hashtag");
@ -130,7 +130,7 @@ export class MfmHelpers {
const a = doc.createElement("a"); const a = doc.createElement("a");
a.setAttribute("rel", "nofollow noopener noreferrer"); a.setAttribute("rel", "nofollow noopener noreferrer");
a.setAttribute("target", "_blank"); a.setAttribute("target", "_blank");
a.href = node.props.url; a.setAttribute('href',node.props.url);
await appendChildren(node.children, a); await appendChildren(node.children, a);
return a; return a;
}, },
@ -146,7 +146,7 @@ export class MfmHelpers {
el.setAttribute("class", "h-card"); el.setAttribute("class", "h-card");
el.setAttribute("translate", "no"); el.setAttribute("translate", "no");
const a = doc.createElement("a"); const a = doc.createElement("a");
a.href = resolved.href; a.setAttribute('href',resolved.href);
a.className = "u-url mention"; a.className = "u-url mention";
const span = doc.createElement("span"); const span = doc.createElement("span");
span.textContent = resolved.username; span.textContent = resolved.username;
@ -181,14 +181,14 @@ export class MfmHelpers {
const a = doc.createElement("a"); const a = doc.createElement("a");
a.setAttribute("rel", "nofollow noopener noreferrer"); a.setAttribute("rel", "nofollow noopener noreferrer");
a.setAttribute("target", "_blank"); a.setAttribute("target", "_blank");
a.href = node.props.url; a.setAttribute('href', node.props.url);
a.textContent = node.props.url.replace(/^https?:\/\//, ''); a.textContent = node.props.url.replace(/^https?:\/\//, '');
return a; return a;
}, },
search(node) { search(node) {
const a = doc.createElement("a"); const a = doc.createElement("a");
a.href = `${config.searchEngine}${node.props.query}`; a.setAttribute('href', `${config.searchEngine}${node.props.query}`);
a.textContent = node.props.content; a.textContent = node.props.content;
return a; return a;
}, },
@ -204,7 +204,7 @@ export class MfmHelpers {
if (quoteUri !== null) { if (quoteUri !== null) {
const a = doc.createElement("a"); const a = doc.createElement("a");
a.href = quoteUri; a.setAttribute('href', quoteUri);
a.textContent = quoteUri.replace(/^https?:\/\//, ''); a.textContent = quoteUri.replace(/^https?:\/\//, '');
const quote = doc.createElement("span"); const quote = doc.createElement("span");

View file

@ -5541,6 +5541,7 @@ __metadata:
fluent-ffmpeg: "npm:2.1.2" fluent-ffmpeg: "npm:2.1.2"
got: "npm:12.5.3" got: "npm:12.5.3"
gunzip-maybe: "npm:^1.4.2" gunzip-maybe: "npm:^1.4.2"
happy-dom: "npm:^12.10.3"
hpagent: "npm:0.1.2" hpagent: "npm:0.1.2"
iceshrimp-js: "workspace:*" iceshrimp-js: "workspace:*"
ioredis: "npm:5.3.2" ioredis: "npm:5.3.2"
@ -7430,6 +7431,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"css.escape@npm:^1.5.1":
version: 1.5.1
resolution: "css.escape@npm:1.5.1"
checksum: f6d38088d870a961794a2580b2b2af1027731bb43261cfdce14f19238a88664b351cc8978abc20f06cc6bbde725699dec8deb6fe9816b139fc3f2af28719e774
languageName: node
linkType: hard
"css@npm:^3.0.0": "css@npm:^3.0.0":
version: 3.0.0 version: 3.0.0
resolution: "css@npm:3.0.0" resolution: "css@npm:3.0.0"
@ -8451,7 +8459,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"entities@npm:^4.2.0, entities@npm:^4.4.0": "entities@npm:^4.2.0, entities@npm:^4.4.0, entities@npm:^4.5.0":
version: 4.5.0 version: 4.5.0
resolution: "entities@npm:4.5.0" resolution: "entities@npm:4.5.0"
checksum: ede2a35c9bce1aeccd055a1b445d41c75a14a2bb1cd22e242f20cf04d236cdcd7f9c859eb83f76885327bfae0c25bf03303665ee1ce3d47c5927b98b0e3e3d48 checksum: ede2a35c9bce1aeccd055a1b445d41c75a14a2bb1cd22e242f20cf04d236cdcd7f9c859eb83f76885327bfae0c25bf03303665ee1ce3d47c5927b98b0e3e3d48
@ -10968,6 +10976,20 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"happy-dom@npm:^12.10.3":
version: 12.10.3
resolution: "happy-dom@npm:12.10.3"
dependencies:
css.escape: "npm:^1.5.1"
entities: "npm:^4.5.0"
iconv-lite: "npm:^0.6.3"
webidl-conversions: "npm:^7.0.0"
whatwg-encoding: "npm:^2.0.0"
whatwg-mimetype: "npm:^3.0.0"
checksum: de82ddd1c981f24a95011c62c2d03e12c4c48f86c0234fa7a1a309d8fa1481885956c783fb3cc56371fa49193d2323822a583196156b10db179e7ac754ef7864
languageName: node
linkType: hard
"hard-rejection@npm:^2.1.0": "hard-rejection@npm:^2.1.0":
version: 2.1.0 version: 2.1.0
resolution: "hard-rejection@npm:2.1.0" resolution: "hard-rejection@npm:2.1.0"
@ -11490,7 +11512,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"iconv-lite@npm:0.6.3, iconv-lite@npm:^0.6.2": "iconv-lite@npm:0.6.3, iconv-lite@npm:^0.6.2, iconv-lite@npm:^0.6.3":
version: 0.6.3 version: 0.6.3
resolution: "iconv-lite@npm:0.6.3" resolution: "iconv-lite@npm:0.6.3"
dependencies: dependencies: