Skip to content

Commit f3a5b0d

Browse files
author
LB
authored
remove progressbar (#29452)
1 parent 9428145 commit f3a5b0d

File tree

4 files changed

+2
-112
lines changed

4 files changed

+2
-112
lines changed

packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js

-21
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,17 @@ jest.mock(`got`, () => {
2222
}
2323
})
2424

25-
jest.mock(`gatsby-cli/lib/reporter`, () => {
26-
return {
27-
createProgress: jest.fn(),
28-
}
29-
})
3025
jest.mock(`../create-file-node`, () => {
3126
return {
3227
createFileNode: jest.fn(),
3328
}
3429
})
3530
const reporter = require(`gatsby-cli/lib/reporter`)
36-
const progressBar = {
37-
start: jest.fn(),
38-
total: 0,
39-
tick: jest.fn(),
40-
}
41-
reporter.createProgress.mockImplementation(() => progressBar)
4231

4332
const got = require(`got`)
4433
const createRemoteFileNode = require(`../create-remote-file-node`)
4534
const { createFileNode } = require(`../create-file-node`)
4635

47-
beforeEach(() => {
48-
progressBar.tick.mockClear()
49-
})
50-
5136
const createMockCache = () => {
5237
return {
5338
get: jest.fn(),
@@ -90,9 +75,6 @@ describe(`create-remote-file-node`, () => {
9075
expect(value).rejects.toMatch(
9176
`url passed to createRemoteFileNode is either missing or not a proper web uri: `
9277
)
93-
94-
expect(progressBar.total).toBe(0)
95-
expect(progressBar.tick).not.toHaveBeenCalled()
9678
})
9779
})
9880
})
@@ -157,9 +139,6 @@ describe(`create-remote-file-node`, () => {
157139

158140
it(`invokes ProgressBar tick`, async () => {
159141
await setup()
160-
161-
expect(progressBar.total).toBe(1)
162-
expect(progressBar.tick).toHaveBeenCalledTimes(1)
163142
})
164143

165144
describe(`requesting remote image`, () => {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
jest.mock(`gatsby-cli/lib/reporter`)
22
jest.mock(`progress`)
3-
const {
4-
getRemoteFileExtension,
5-
getRemoteFileName,
6-
createProgress,
7-
} = require(`../utils`)
8-
const reporter = require(`gatsby-cli/lib/reporter`)
9-
const progress = require(`progress`)
3+
const { getRemoteFileExtension, getRemoteFileName } = require(`../utils`)
104

115
describe(`create remote file node`, () => {
126
it(`can correctly retrieve file name and extensions`, () => {
@@ -30,34 +24,3 @@ describe(`create remote file node`, () => {
3024
})
3125
})
3226
})
33-
34-
describe(`createProgress`, () => {
35-
beforeEach(() => {
36-
progress.mockClear()
37-
})
38-
39-
it(`should use createProgress from gatsby-cli when available`, () => {
40-
createProgress(`test`, reporter)
41-
expect(reporter.createProgress).toBeCalled()
42-
expect(progress).not.toBeCalled()
43-
})
44-
45-
it(`should fallback to a local implementation when createProgress does not exists on reporter`, () => {
46-
reporter.createProgress = null
47-
const bar = createProgress(`test`, reporter)
48-
expect(progress).toHaveBeenCalledTimes(1)
49-
expect(bar).toHaveProperty(`start`, expect.any(Function))
50-
expect(bar).toHaveProperty(`tick`, expect.any(Function))
51-
expect(bar).toHaveProperty(`done`, expect.any(Function))
52-
expect(bar).toHaveProperty(`total`)
53-
})
54-
55-
it(`should fallback to a local implementation when no reporter is present`, () => {
56-
const bar = createProgress(`test`)
57-
expect(progress).toHaveBeenCalledTimes(1)
58-
expect(bar).toHaveProperty(`start`, expect.any(Function))
59-
expect(bar).toHaveProperty(`tick`, expect.any(Function))
60-
expect(bar).toHaveProperty(`done`, expect.any(Function))
61-
expect(bar).toHaveProperty(`total`)
62-
})
63-
})

packages/gatsby-source-filesystem/src/create-remote-file-node.js

+1-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const path = require(`path`)
55
const { isWebUri } = require(`valid-url`)
66
const Queue = require(`better-queue`)
77
const fileType = require(`file-type`)
8-
const { createProgress } = require(`./utils`)
98

109
const { createFileNode } = require(`./create-file-node`)
1110
const {
@@ -16,10 +15,6 @@ const {
1615
const cacheIdForHeaders = url => `create-remote-file-node-headers-${url}`
1716
const cacheIdForExtensions = url => `create-remote-file-node-extension-${url}`
1817

19-
let bar
20-
// Keep track of the total number of jobs we push in the queue
21-
let totalJobs = 0
22-
2318
let showFlagWarning = !!process.env.GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER
2419

2520
/********************
@@ -79,14 +74,6 @@ const queue = new Queue(pushToQueue, {
7974
concurrent: process.env.GATSBY_CONCURRENT_DOWNLOAD || 200,
8075
})
8176

82-
// when the queue is empty we stop the progressbar
83-
queue.on(`drain`, () => {
84-
if (bar) {
85-
bar.done()
86-
}
87-
totalJobs = 0
88-
})
89-
9077
/**
9178
* @callback {Queue~queueCallback}
9279
* @param {*} error
@@ -458,14 +445,6 @@ module.exports = function createRemoteFileNode({
458445
)
459446
}
460447

461-
if (totalJobs === 0) {
462-
bar = createProgress(`Downloading remote files`, reporter)
463-
bar.start()
464-
}
465-
466-
totalJobs += 1
467-
bar.total = totalJobs
468-
469448
const fileDownloadPromise = pushTask({
470449
url,
471450
cache,
@@ -478,11 +457,7 @@ module.exports = function createRemoteFileNode({
478457
name,
479458
})
480459

481-
processingCache[url] = fileDownloadPromise.then(node => {
482-
bar.tick()
483-
484-
return node
485-
})
460+
processingCache[url] = fileDownloadPromise.then(node => node)
486461

487462
return processingCache[url]
488463
}

packages/gatsby-source-filesystem/src/utils.js

-27
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,6 @@ export function getRemoteFileName(url) {
4141
return getParsedPath(url).name
4242
}
4343

44-
// TODO remove in V3
45-
export function createProgress(message, reporter) {
46-
if (reporter && reporter.createProgress) {
47-
return reporter.createProgress(message)
48-
}
49-
50-
const bar = new ProgressBar(
51-
` [:bar] :current/:total :elapsed s :percent ${message}`,
52-
{
53-
total: 0,
54-
width: 30,
55-
clear: true,
56-
}
57-
)
58-
59-
return {
60-
start() {},
61-
tick() {
62-
bar.tick()
63-
},
64-
done() {},
65-
set total(value) {
66-
bar.total = value
67-
},
68-
}
69-
}
70-
7144
/**
7245
* createFilePath
7346
* --

0 commit comments

Comments
 (0)