Skip to content

Commit a812c5f

Browse files
lovellGatsbyJS Bot
authored andcommitted
fix(gatsby): respect the GATSBY_CPU_COUNT env var, if set, by default for sharp (#14624)
* Observe the GATSBY_CPU_COUNT env var, if set, by default Ensures calls to sharp.concurrency have the desired behaviour * test: add a test suite
1 parent 634eb87 commit a812c5f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
jest.mock(`../physical-cpu-count`, () => 1)
2+
const getCPUCoreCount = require(`../cpu-core-count`)
3+
4+
beforeEach(() => {
5+
delete process.env.GATSBY_CPU_COUNT
6+
})
7+
8+
test(`it defaults to physical CPU count, if override not detected`, () => {
9+
expect(getCPUCoreCount()).toBe(1)
10+
})
11+
12+
test(`it does not use env far override, if useEnvVar is false`, () => {
13+
process.env.GATSBY_CPU_COUNT = 9001
14+
15+
expect(getCPUCoreCount(false)).not.toBe(Number(process.env.GATSBY_CPU_COUNT))
16+
})
17+
18+
test(`uses env var override, if exists`, () => {
19+
process.env.GATSBY_CPU_COUNT = 9001
20+
21+
expect(getCPUCoreCount()).toBe(Number(process.env.GATSBY_CPU_COUNT))
22+
})

packages/gatsby/src/utils/cpu-core-count.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @returns {number} Count of the requested type of CPU cores. Defaults to number of physical cores or 1
55
*/
66

7-
const cpuCoreCount = (useEnvVar = false) => {
7+
const cpuCoreCount = (useEnvVar = true) => {
88
try {
99
let coreCount = require(`./physical-cpu-count`) || 1
1010

0 commit comments

Comments
 (0)