Skip to content

Commit c0ba394

Browse files
Laurie BarthLaurie Barth
authored andcommitted
error handling
1 parent 4b5bbb3 commit c0ba394

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/gatsby-plugin-theme-ui/gatsby-node.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@ exports.onPreInit = (__, options) => {
44
options.themeModulePath = require(themeModulePath)
55
}
66
if(prismPreset) {
7-
options.prismPreset = require(`@theme-ui/prism/presets/${prismPreset}.json`)
7+
try {
8+
options.prismPreset = require(`@theme-ui/prism/presets/${prismPreset}.json`)
9+
} catch {
10+
reporter.error(`It appears the prism dependency is not installed. Try running \`${generateInstallInstructions()} @theme-ui/prism\``)
11+
}
812
}
913
}
1014

15+
function generateInstallInstructions() {
16+
const { getConfigStore } = require(`gatsby-core-utils`)
17+
18+
const packageMangerConfigKey = `cli.packageManager`
19+
const PACKAGE_MANGER = getConfigStore().get(packageMangerConfigKey) || `yarn`
20+
21+
const installKeyWord = PACKAGE_MANGER === `yarn` ? "add" : "install"
22+
23+
return `${PACKAGE_MANGER} ${installKeyWord}`
24+
}
25+
1126
exports.createSchemaCustomization = ({ actions }) => {
1227
const { createTypes } = actions
1328

packages/gatsby-plugin-theme-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"peerDependencies": {
88
"gatsby": "^2.13.1",
99
"theme-ui": "^0.3.0",
10-
"@theme-ui/prism": "0.3.0"
10+
"@theme-ui/prism": "0.3.0",
11+
"gatsby-core-utils": "^1.2.0"
1112
},
1213
"keywords": [
1314
"gatsby",

0 commit comments

Comments
 (0)