From 50c1942f79b60c402451c4552995141518a0cf6a Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Thu, 27 Dec 2018 18:23:03 +0530 Subject: [PATCH 1/6] Bail early if sharp isn't working --- packages/gatsby-plugin-sharp/src/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 3805260eb7df3..36b0f9c740f3e 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -1,4 +1,16 @@ -const sharp = require(`sharp`) +let sharp + +try { + sharp = require(`sharp`) +} catch (error) { + // Bail early if sharp isn't working + reportError( + `Sharp doesn't seem to have been built or installed correctly`, + error + ) + process.exit(1) +} + const crypto = require(`crypto`) const imageSize = require(`probe-image-size`) const { promisify } = require(`bluebird`) From 0353d584ebd33a5f0c092f9845f8478852411d8b Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Thu, 27 Dec 2018 20:12:02 +0530 Subject: [PATCH 2/6] Move sharp check to pre init --- .../gatsby-plugin-sharp/src/gatsby-node.js | 65 ++++--------------- packages/gatsby-plugin-sharp/src/index.js | 14 +--- 2 files changed, 15 insertions(+), 64 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index 8e2abdfd08145..36d28a1b2eeb8 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -1,55 +1,18 @@ -const { - setBoundActionCreators, - setPluginOptions, - // queue: jobQueue, - // reportError, -} = require(`./index`) -// const { scheduleJob } = require(`./scheduler`) -// let normalizedOptions = {} - -// const getQueueFromCache = store => { -// const pluginStatus = store.getState().status.plugins[`gatsby-plugin-sharp`] - -// if (!pluginStatus || !pluginStatus.queue) { -// return new Map() -// } - -// return new Map(pluginStatus.queue) -// } - -// const saveQueueToCache = async (store, setPluginStatus, queue) => { -// const cachedQueue = getQueueFromCache(store) - -// // merge both queues -// for (const [key, job] of cachedQueue) { -// if (!queue.has(key)) { -// queue.set(key, job) -// } -// } - -// // JSON.stringify doesn't work on an Map so we need to convert it to an array -// setPluginStatus({ queue: Array.from(queue) }) -// } - -// const processQueue = (store, boundActionCreators, options) => { -// const cachedQueue = getQueueFromCache(store) - -// const promises = [] -// for (const [, job] of cachedQueue) { -// promises.push(scheduleJob(job, boundActionCreators, options)) -// } - -// return promises -// } - -// const cleanupQueueAfterProcess = (imageJobs, setPluginStatus, reporter) => -// Promise.all(imageJobs) -// .then(() => setPluginStatus({ queue: [] })) -// .catch(({ err, message }) => { -// reportError(message || err.message, err, reporter) -// }) +exports.onPreInit = ({ actions, reporter }, pluginOptions) => { + try { + require(`sharp`) + } catch (error) { + // Bail early if sharp isn't working + // TODO: Add link to docs + reporter.panic( + ` + "sharp" doesn't seem to have been built or installed correctly + ` + ) + } + + const { setBoundActionCreators, setPluginOptions } = require(`./index`) -exports.onPreBootstrap = ({ actions }, pluginOptions) => { setBoundActionCreators(actions) setPluginOptions(pluginOptions) // normalizedOptions = setPluginOptions(pluginOptions) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 36b0f9c740f3e..3805260eb7df3 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -1,16 +1,4 @@ -let sharp - -try { - sharp = require(`sharp`) -} catch (error) { - // Bail early if sharp isn't working - reportError( - `Sharp doesn't seem to have been built or installed correctly`, - error - ) - process.exit(1) -} - +const sharp = require(`sharp`) const crypto = require(`crypto`) const imageSize = require(`probe-image-size`) const { promisify } = require(`bluebird`) From 6cba4b455f276e3577d1c572834f97b453fb3724 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 26 Feb 2019 07:03:47 +0530 Subject: [PATCH 3/6] Improve error messaging when sharp isn't available --- packages/gatsby-plugin-sharp/src/gatsby-node.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index 36d28a1b2eeb8..d9b3b88ee7445 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -2,11 +2,15 @@ exports.onPreInit = ({ actions, reporter }, pluginOptions) => { try { require(`sharp`) } catch (error) { - // Bail early if sharp isn't working - // TODO: Add link to docs + // Bail early if sharp isn't available reporter.panic( - ` - "sharp" doesn't seem to have been built or installed correctly + reporter.stripIndent` + The dependency "sharp" does not seem to have been built or installed correctly. + + - Try to reinstall packages and look for errors during installation + - Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/ + + If neither of the above work, please open an issue in https://github.com/gatsbyjs/gatsby/issues ` ) } From a71f3c714db89f05791c3cd893335fbf824dd5df Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 20 Mar 2019 18:13:44 +0530 Subject: [PATCH 4/6] Check for sharp in entrypoint --- .../gatsby-plugin-sharp/src/gatsby-node.js | 16 ---------------- packages/gatsby-plugin-sharp/src/index.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index d9b3b88ee7445..7d266b1b043d8 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -1,20 +1,4 @@ exports.onPreInit = ({ actions, reporter }, pluginOptions) => { - try { - require(`sharp`) - } catch (error) { - // Bail early if sharp isn't available - reporter.panic( - reporter.stripIndent` - The dependency "sharp" does not seem to have been built or installed correctly. - - - Try to reinstall packages and look for errors during installation - - Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/ - - If neither of the above work, please open an issue in https://github.com/gatsbyjs/gatsby/issues - ` - ) - } - const { setBoundActionCreators, setPluginOptions } = require(`./index`) setBoundActionCreators(actions) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 3805260eb7df3..a412dcf5bee5a 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -1,3 +1,21 @@ +try { + require(`sharp`) +} catch (error) { + // Bail early if sharp isn't available + console.error( + ` + The dependency "sharp" does not seem to have been built or installed correctly. + + - Try to reinstall packages and look for errors during installation + - Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/ + + If neither of the above work, please open an issue in https://github.com/gatsbyjs/gatsby/issues + `, + error + ) + process.exit(1) +} + const sharp = require(`sharp`) const crypto = require(`crypto`) const imageSize = require(`probe-image-size`) From 7ab7c139de47405d9d20cf98b60225c8891fb4b8 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 20 Mar 2019 18:25:07 +0530 Subject: [PATCH 5/6] Add back comments --- .../gatsby-plugin-sharp/src/gatsby-node.js | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index 7d266b1b043d8..8e2abdfd08145 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -1,6 +1,55 @@ -exports.onPreInit = ({ actions, reporter }, pluginOptions) => { - const { setBoundActionCreators, setPluginOptions } = require(`./index`) +const { + setBoundActionCreators, + setPluginOptions, + // queue: jobQueue, + // reportError, +} = require(`./index`) +// const { scheduleJob } = require(`./scheduler`) +// let normalizedOptions = {} + +// const getQueueFromCache = store => { +// const pluginStatus = store.getState().status.plugins[`gatsby-plugin-sharp`] + +// if (!pluginStatus || !pluginStatus.queue) { +// return new Map() +// } + +// return new Map(pluginStatus.queue) +// } + +// const saveQueueToCache = async (store, setPluginStatus, queue) => { +// const cachedQueue = getQueueFromCache(store) + +// // merge both queues +// for (const [key, job] of cachedQueue) { +// if (!queue.has(key)) { +// queue.set(key, job) +// } +// } + +// // JSON.stringify doesn't work on an Map so we need to convert it to an array +// setPluginStatus({ queue: Array.from(queue) }) +// } + +// const processQueue = (store, boundActionCreators, options) => { +// const cachedQueue = getQueueFromCache(store) + +// const promises = [] +// for (const [, job] of cachedQueue) { +// promises.push(scheduleJob(job, boundActionCreators, options)) +// } + +// return promises +// } + +// const cleanupQueueAfterProcess = (imageJobs, setPluginStatus, reporter) => +// Promise.all(imageJobs) +// .then(() => setPluginStatus({ queue: [] })) +// .catch(({ err, message }) => { +// reportError(message || err.message, err, reporter) +// }) +exports.onPreBootstrap = ({ actions }, pluginOptions) => { setBoundActionCreators(actions) setPluginOptions(pluginOptions) // normalizedOptions = setPluginOptions(pluginOptions) From 32f3289a632e890847a541e3ab1715abf3754d33 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 20 Mar 2019 18:35:47 +0530 Subject: [PATCH 6/6] Add a new line between message and error from sharp --- packages/gatsby-plugin-sharp/src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index a412dcf5bee5a..29cef649d5c0e 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -10,9 +10,10 @@ try { - Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/ If neither of the above work, please open an issue in https://github.com/gatsbyjs/gatsby/issues - `, - error + ` ) + console.log() + console.error(error) process.exit(1) }