@metascraper/helpers 5.49.24 → 5.49.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/index.js +4 -2
- package/src/load-iframe/index.js +30 -5
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@metascraper/helpers",
|
|
3
3
|
"description": "Collection of helper functions used by metascraper",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-helpers",
|
|
5
|
-
"version": "5.49.
|
|
5
|
+
"version": "5.49.25",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"cheerio": "latest"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
|
-
"node": ">=
|
|
56
|
+
"node": ">= 22"
|
|
57
57
|
},
|
|
58
58
|
"files": [
|
|
59
59
|
"src"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "b656312fda1e8c1cd65b4e92cdf9713a16cfdd3b"
|
|
69
69
|
}
|
package/src/index.js
CHANGED
|
@@ -349,8 +349,10 @@ const title = (value, { removeSeparator = false, ...opts } = {}) =>
|
|
|
349
349
|
const isMime = (contentType, type) =>
|
|
350
350
|
type === get(EXTENSIONS, mimeExtension(contentType))
|
|
351
351
|
|
|
352
|
+
const isSameHtmlDom = (newHtmlDom, oldHtmlDom) => newHtmlDom === oldHtmlDom
|
|
353
|
+
|
|
352
354
|
memoizeOne.EqualityUrlAndHtmlDom = (newArgs, oldArgs) =>
|
|
353
|
-
newArgs[0] === oldArgs[0] && newArgs[1]
|
|
355
|
+
newArgs[0] === oldArgs[0] && isSameHtmlDom(newArgs[1], oldArgs[1])
|
|
354
356
|
|
|
355
357
|
memoizeOne.EqualityFirstArgument = (newArgs, oldArgs) =>
|
|
356
358
|
newArgs[0] === oldArgs[0]
|
|
@@ -384,7 +386,7 @@ const jsonld = memoizeOne(
|
|
|
384
386
|
})
|
|
385
387
|
.get()
|
|
386
388
|
.filter(Boolean),
|
|
387
|
-
(newArgs, oldArgs) => newArgs[0]
|
|
389
|
+
(newArgs, oldArgs) => isSameHtmlDom(newArgs[0], oldArgs[0])
|
|
388
390
|
)
|
|
389
391
|
|
|
390
392
|
const $jsonld = propName => $ => {
|
package/src/load-iframe/index.js
CHANGED
|
@@ -10,12 +10,37 @@ const SCRIPT_PATH = (
|
|
|
10
10
|
|
|
11
11
|
module.exports = (url, $, { timeout = 5000 } = {}) => {
|
|
12
12
|
const worker = new Worker(SCRIPT_PATH(), {
|
|
13
|
-
workerData: { url, html: $.html(), timeout }
|
|
14
|
-
stdout: true,
|
|
15
|
-
stderr: true
|
|
13
|
+
workerData: { url, html: $.html(), timeout }
|
|
16
14
|
})
|
|
17
15
|
const { promise, resolve, reject } = Promise.withResolvers()
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
let settled = false
|
|
17
|
+
|
|
18
|
+
const onMessage = html => {
|
|
19
|
+
if (settled) return
|
|
20
|
+
settled = true
|
|
21
|
+
resolve($.load(html || ''))
|
|
22
|
+
worker.terminate().catch(() => {})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const onError = error => {
|
|
26
|
+
if (settled) return
|
|
27
|
+
settled = true
|
|
28
|
+
reject(error)
|
|
29
|
+
worker.terminate().catch(() => {})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const onExit = code => {
|
|
33
|
+
if (settled) return
|
|
34
|
+
settled = true
|
|
35
|
+
if (code === 0) {
|
|
36
|
+
resolve($.load(''))
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
reject(new Error(`loadIframe worker exited unexpectedly with code ${code}`))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
worker.once('message', onMessage)
|
|
43
|
+
worker.once('error', onError)
|
|
44
|
+
worker.once('exit', onExit)
|
|
20
45
|
return promise
|
|
21
46
|
}
|