Skip to content

Commit 412217d

Browse files
piehDSchau
authored andcommitted
fix: don't crash if cpu-core-count is not available (#12332)
1 parent 0f79fef commit 412217d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

packages/gatsby-plugin-manifest/src/gatsby-node.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ const { defaultIcons, doesIconExist } = require(`./common.js`)
66

77
sharp.simd(true)
88

9-
// Handle Sharp's concurrency based on the Gatsby CPU count
10-
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
11-
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
12-
const cpuCoreCount = require(`gatsby/dist/utils/cpu-core-count`)
13-
sharp.concurrency(cpuCoreCount())
9+
try {
10+
// Handle Sharp's concurrency based on the Gatsby CPU count
11+
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
12+
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
13+
const cpuCoreCount = require(`gatsby/dist/utils/cpu-core-count`)
14+
sharp.concurrency(cpuCoreCount())
15+
} catch {
16+
// if above throws error this probably means that used Gatsby version
17+
// doesn't support cpu-core-count utility.
18+
}
1419

1520
function generateIcons(icons, srcIcon) {
1621
return Promise.map(icons, icon => {

packages/gatsby-plugin-sharp/src/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ Promise.promisifyAll(sharp.prototype, { multiArgs: true })
6262
// adventurous and see what happens with it on.
6363
sharp.simd(true)
6464

65-
// Handle Sharp's concurrency based on the Gatsby CPU count
66-
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
67-
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
68-
const cpuCoreCount = require(`gatsby/dist/utils/cpu-core-count`)
69-
sharp.concurrency(cpuCoreCount())
65+
try {
66+
// Handle Sharp's concurrency based on the Gatsby CPU count
67+
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
68+
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
69+
const cpuCoreCount = require(`gatsby/dist/utils/cpu-core-count`)
70+
sharp.concurrency(cpuCoreCount())
71+
} catch {
72+
// if above throws error this probably means that used Gatsby version
73+
// doesn't support cpu-core-count utility.
74+
}
7075

7176
const bar = new ProgressBar(
7277
`Generating image thumbnails [:bar] :current/:total :elapsed secs :percent`,

0 commit comments

Comments
 (0)