Skip to content

Commit 6c8e277

Browse files
authored
fix(gatsby-source-contentful): use reporter progressbar instead of own (#29853)
1 parent 86b8b26 commit 6c8e277

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

packages/gatsby-source-contentful/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"lodash": "^4.17.20",
2727
"node-fetch": "^2.6.1",
2828
"p-queue": "^6.6.2",
29-
"progress": "^2.0.3",
3029
"qs": "^6.9.6",
3130
"retry-axios": "^2.4.0"
3231
},

packages/gatsby-source-contentful/src/__tests__/download-contentful-assets.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
const { downloadContentfulAssets } = require(`../download-contentful-assets`)
22

3-
jest.mock(
4-
`progress`,
5-
() =>
6-
class MockProgress {
7-
constructor() {
8-
this.tick = jest.fn()
9-
}
10-
}
11-
)
12-
133
jest.mock(`gatsby-source-filesystem`, () => {
144
return {
155
createRemoteFileNode: jest.fn(({ url }) => {
@@ -20,6 +10,15 @@ jest.mock(`gatsby-source-filesystem`, () => {
2010
}
2111
})
2212

13+
const reporter = {
14+
createProgress: jest.fn(() => {
15+
return {
16+
start: jest.fn(),
17+
tick: jest.fn(),
18+
}
19+
}),
20+
}
21+
2322
const fixtures = [
2423
{
2524
id: `aa1beda4-b14a-50f5-89a8-222992a46a41`,
@@ -66,6 +65,7 @@ describe.only(`downloadContentfulAssets`, () => {
6665
getNodesByType: () => fixtures,
6766
cache,
6867
assetDownloadWorkers: 50,
68+
reporter,
6969
})
7070

7171
fixtures.forEach(n => {

packages/gatsby-source-contentful/src/download-contentful-assets.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
const ProgressBar = require(`progress`)
21
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)
32

4-
const bar = new ProgressBar(
5-
`Downloading Contentful Assets [:bar] :current/:total :elapsed secs :percent`,
6-
{
7-
total: 0,
8-
width: 30,
9-
}
10-
)
11-
123
/**
134
* @name distributeWorkload
145
* @param workers A list of async functions to complete
@@ -51,15 +42,19 @@ const downloadContentfulAssets = async gatsbyFunctions => {
5142
// regardless of if you use `localFile` to link an asset or not.
5243

5344
const assetNodes = getNodesByType(`ContentfulAsset`)
54-
bar.total = assetNodes.length
55-
45+
const bar = reporter.createProgress(
46+
`Downloading Contentful Assets`,
47+
assetNodes.length
48+
)
49+
bar.start()
5650
await distributeWorkload(
5751
assetNodes.map(node => async () => {
5852
let fileNodeID
5953
const { contentful_id: id, node_locale: locale } = node
6054
const remoteDataCacheKey = `contentful-asset-${id}-${locale}`
6155
const cacheRemoteData = await cache.get(remoteDataCacheKey)
6256
if (!node.file) {
57+
reporter.log(id, locale)
6358
reporter.warn(`The asset with id: ${id}, contains no file.`)
6459
return Promise.resolve()
6560
}

0 commit comments

Comments
 (0)