Skip to content

Commit f5a6843

Browse files
committed
fix: remove make-fetch-happen
BREAKING CHANGE: make-fetch-happen would respect cache headers by saving responses in the file system. We no longer use make-fetch-happen and instead use the built-in fetch machanism on your system which could potentially result in no caching depending on your global fetch. Closes #2
1 parent 6bbad29 commit f5a6843

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

src/__tests__/index.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@ const unquoteSerializer = {
1616
expect.addSnapshotSerializer(unquoteSerializer)
1717

1818
const server = setupServer(
19-
http.get('http://oembed.com/providers.json', () =>
19+
http.get('https://oembed.com/providers.json', () =>
2020
HttpResponse.json([
2121
{
2222
provider_name: 'Beautiful.AI',
23-
provider_url: 'http://www.beautiful.ai',
23+
provider_url: 'https://www.beautiful.ai',
2424
endpoints: [
2525
{
26-
url: 'http://www.beautiful.ai/api/oembed',
26+
url: 'https://www.beautiful.ai/api/oembed',
2727
// no scheme 😱
2828
discovery: true,
2929
},
3030
],
3131
},
3232
{
3333
provider_name: 'Twitter',
34-
provider_url: 'http://www.twitter.com',
34+
provider_url: 'https://www.twitter.com',
3535
endpoints: [
3636
{
3737
schemes: [
38-
'http://twitter.com/*/status/*',
39-
'http://*.twitter.com/*/status/*',
40-
'http://twitter.com/*/moments/*',
41-
'http://*.twitter.com/*/moments/*',
38+
'https://twitter.com/*/status/*',
39+
'https://*.twitter.com/*/status/*',
40+
'https://twitter.com/*/moments/*',
41+
'https://*.twitter.com/*/moments/*',
4242
],
43-
url: 'http://publish.twitter.com/oembed',
43+
url: 'https://publish.twitter.com/oembed',
4444
},
4545
],
4646
},
4747
]),
4848
),
49-
http.get('http://publish.twitter.com/oembed', () =>
49+
http.get('https://publish.twitter.com/oembed', () =>
5050
HttpResponse.json({
51-
html: '<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>',
51+
html: '<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>',
5252
}),
5353
),
5454
)
@@ -74,19 +74,19 @@ test('smoke test', async () => {
7474
`
7575
Here's a great tweet:
7676
77-
http://twitter.com/kentcdodds/status/783161196945944580
77+
https://twitter.com/kentcdodds/status/783161196945944580
7878
7979
And here's an example of no provider:
8080
81-
http://example.com
81+
https://example.com
8282
`.trim(),
8383
)
8484

8585
expect(result.toString()).toMatchInlineSnapshot(`
8686
<p>Here's a great tweet:</p>
87-
<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>
87+
<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>
8888
<p>And here's an example of no provider:</p>
89-
<p>http://example.com</p>
89+
<p>https://example.com</p>
9090
`)
9191
})
9292

@@ -96,10 +96,10 @@ test('no config required', async () => {
9696
transformers: [transformer],
9797
})
9898
.use(remarkHTML, {sanitize: false})
99-
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)
99+
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
100100

101101
expect(result.toString()).toMatchInlineSnapshot(
102-
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
102+
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
103103
)
104104
})
105105

@@ -112,10 +112,10 @@ test('config can be a function', async () => {
112112
transformers: [[transformer, config]],
113113
})
114114
.use(remarkHTML, {sanitize: false})
115-
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)
115+
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
116116

117117
expect(result.toString()).toMatchInlineSnapshot(
118-
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
118+
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
119119
)
120120
})
121121

@@ -126,18 +126,18 @@ test('config function does not need to return anything', async () => {
126126
transformers: [[transformer, config]],
127127
})
128128
.use(remarkHTML, {sanitize: false})
129-
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)
129+
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
130130

131131
expect(result.toString()).toMatchInlineSnapshot(
132-
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
132+
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
133133
)
134134
})
135135

136136
test('sends the correct search params', async () => {
137137
let request: Request
138138

139139
server.use(
140-
http.get('http://publish.twitter.com/oembed', ({request: req}) => {
140+
http.get('https://publish.twitter.com/oembed', ({request: req}) => {
141141
request = req
142142
return HttpResponse.json({
143143
html: 'whatever',
@@ -155,10 +155,10 @@ test('sends the correct search params', async () => {
155155
],
156156
})
157157
.use(remarkHTML, {sanitize: false})
158-
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)
158+
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
159159

160160
// @ts-expect-error it doesn't think request will be assigned by now... But it will!
161161
expect(request.url.toString()).toMatchInlineSnapshot(
162-
`http://publish.twitter.com/oembed?url=http%3A%2F%2Ftwitter.com%2Fkentcdodds%2Fstatus%2F783161196945944580&dnt=true&omit_script=true&theme=dark&format=json`,
162+
`https://publish.twitter.com/oembed?url=https%3A%2F%2Ftwitter.com%2Fkentcdodds%2Fstatus%2F783161196945944580&dnt=true&omit_script=true&theme=dark&format=json`,
163163
)
164164
})

src/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import path from 'path'
21
import {URL} from 'url'
32
import {type Transformer} from '@remark-embedder/core'
4-
import fetch from 'make-fetch-happen'
5-
6-
fetch.defaults({
7-
cachePath: path.join(
8-
process.cwd(),
9-
'node_modules/.cache/@remark-embedder/transformer-oembed/fetch',
10-
),
11-
})
123

134
type Provider = {
145
provider_name: string
@@ -28,7 +19,7 @@ declare namespace getProviders {
2819

2920
async function getProviders(): Promise<Providers> {
3021
if (!getProviders.cache) {
31-
const res = await fetch('http://oembed.com/providers.json')
22+
const res = await fetch('https://oembed.com/providers.json')
3223
getProviders.cache = (await res.json()) as Providers
3324
}
3425

0 commit comments

Comments
 (0)