Skip to content

Commit 00945df

Browse files
authored
Merge pull request #760 from microlinkhq/next
refactor(helpers): make __dirname lazy
2 parents 589beef + b7215b6 commit 00945df

File tree

8 files changed

+9
-71
lines changed

8 files changed

+9
-71
lines changed

packages/metascraper-helpers/src/load-iframe/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
const { Worker } = require('worker_threads')
44
const path = require('path')
55

6-
const SCRIPT_PATH = path.resolve(__dirname, 'worker.js')
6+
const SCRIPT_PATH = (
7+
v => () =>
8+
v ?? (v = path.resolve(__dirname, 'worker.js'))
9+
)()
710

811
module.exports = (url, $, { timeout = 5000 } = {}) => {
9-
const worker = new Worker(SCRIPT_PATH, {
12+
const worker = new Worker(SCRIPT_PATH(), {
1013
workerData: { url, html: $.html(), timeout },
1114
stdout: true,
1215
stderr: true

packages/metascraper-helpers/test/snapshots/load-iframe.js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev).
99
> Snapshot 1
1010
1111
`<html lang="en"><head>␊
12-
<script src="https://assets.transistor.fm/assets/embed-d3cebcc7295560fede438e50d550c8ac24903455d60a461df6c31b92c9ac5c7c.js" defer="defer"></script>␊
12+
<script src="https://assets.transistor.fm/assets/embed-b705895db7302d146f6150438e5afdbc5c69ae8bbcc8d8cffcc0dc19af0b52e6.js" defer="defer"></script>␊
1313
<meta content="nofollow" name="robots">␊
1414
<title>Paul Jarvis: gaining freedom by building an indie business - Audio player</title>␊
1515
<meta content="width=device-width, initial-scale=1.0" name="viewport">␊
3 Bytes
Binary file not shown.

packages/metascraper-x/test/snapshots/index.js.md

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Generated by [AVA](https://avajs.dev).
2727
{
2828
author: '#!/kiko/beats (Kikobeats)',
2929
date: null,
30-
description: 'engineering ▲ @vercel; founder of microlink.io teslahunt.io unavatar.io keyvhq.js.org osom.js.org browserless.js.org metascraper.js.org',
30+
description: 'engineering ▲ @vercel; founder of microlink.io teslahunt.io unavatar.io keyv.js.org osom.js.org browserless.js.org metascraper.js.org',
3131
image: 'https://pbs.twimg.com/profile_images/1846292082501054464/oKUC44PF_400x400.jpg',
3232
lang: 'en',
3333
publisher: 'X',
@@ -99,67 +99,3 @@ Generated by [AVA](https://avajs.dev).
9999
url: 'https://twitter.com/UaSmart/status/934106870834454529',
100100
video: null,
101101
}
102-
103-
## from a X profile with tweets with video
104-
105-
> Snapshot 1
106-
107-
{
108-
author: 'Javi López ⛩️ (javilop)',
109-
date: null,
110-
description: 'Comparto tutoriales, herramientas y noticias de IA. Fundador @Magnific_AI 🔥 Guía IAs: https://t.co/JApwm5Tmfo 🗞️ Newsletter: https://t.co/tMELO1P8Wk',
111-
image: 'https://pbs.twimg.com/profile_images/1581679886267301888/BHGZpOc6_400x400.jpg',
112-
lang: 'en',
113-
publisher: 'X',
114-
title: '@javilop on X',
115-
url: 'https://twitter.com/javilop',
116-
video: null,
117-
}
118-
119-
## from a tweet
120-
121-
> Snapshot 1
122-
123-
{
124-
author: 'Donald J. Trump (realDonaldTrump)',
125-
date: null,
126-
description: '“Schiff blasted for not focusing on California homeless.” @foxandfriends His District is in terrible shape. He is a corrupt pol who only dreams of the Impeachment Hoax. In my opinion he is mentally deranged!',
127-
image: 'https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_400x400.jpg',
128-
lang: 'en',
129-
publisher: 'X',
130-
title: '@realDonaldTrump on X',
131-
url: 'https://twitter.com/realDonaldTrump/status/1222907250383245320',
132-
video: null,
133-
}
134-
135-
## from a tweet with a gif
136-
137-
> Snapshot 1
138-
139-
{
140-
author: '#!/kiko/beats (Kikobeats)',
141-
date: null,
142-
description: 'Experimenting with Clearbit API + Apple TV 3D Parallax https://t.co/Qsm163k4mJ',
143-
image: 'https://pbs.twimg.com/tweet_video_thumb/DDbh3WCXYAAZfz9.jpg:large',
144-
lang: 'en',
145-
publisher: 'X',
146-
title: '@Kikobeats on X',
147-
url: 'https://twitter.com/Kikobeats/status/880139124791029763',
148-
video: null,
149-
}
150-
151-
## from a tweet with an image
152-
153-
> Snapshot 1
154-
155-
{
156-
author: 'SmartUA (UaSmart)',
157-
date: null,
158-
description: 'Y terminamos el dia con Cultura de empresa con @patoroco, @flopezluis, Katia, Angélica en @codemotion_es #codemotion2017',
159-
image: 'https://pbs.twimg.com/media/DPadOKpXcAIL-NW.jpg:large',
160-
lang: 'en',
161-
publisher: 'X',
162-
title: '@UaSmart on X',
163-
url: 'https://twitter.com/UaSmart/status/934106870834454529',
164-
video: null,
165-
}
-61 Bytes
Binary file not shown.

packages/metascraper/test/integration/transistor/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const url = 'https://share.transistor.fm/e/70c487ed'
2525

2626
test('transistor.fm', async t => {
2727
const html = await readFile(resolve(__dirname, 'input.html'))
28-
const { logo, ...metadata } = await metascraper({ html, url })
28+
const metadata = await metascraper({ html, url })
2929
t.snapshot(metadata)
30-
t.is(typeof logo, 'string')
31-
t.true(new URL(logo).hostname.endsWith('transistor.fm'), logo)
3230
})

packages/metascraper/test/integration/transistor/snapshots/index.js.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Generated by [AVA](https://avajs.dev).
1515
description: null,
1616
image: 'https://images.transistor.fm/file/transistor/images/episode/263474/medium_1590257639-artwork.jpg',
1717
lang: null,
18+
logo: 'https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://share.transistor.fm/e/70c487ed&size=128',
1819
publisher: '#032 – Before and After Product-Market Fit with Peter and Calvin from Segment',
1920
title: 'Transistor Embed | #032 – Before and After Product-Market Fit with Peter and Calvin from Segment',
2021
url: 'https://share.transistor.fm/e/70c487ed',
Binary file not shown.

0 commit comments

Comments
 (0)