ChristopherBiscardi / gatsby-theme-examples

Examples of using gatsby themes
141 stars 11 forks source link

Swap typography-js paths if user defines one #5

Closed ChristopherBiscardi closed 5 years ago

ChristopherBiscardi commented 6 years ago

Use the withThemePath helper to replace the require'd typography util path with the user's if they defined one.

Can't merge because it requires the following diff to gatsby-plugin-typography, which hasn't been merged yet.

diff --git a/packages/gatsby-plugin-typography/src/gatsby-node.js b/packages/gatsby-plugin-typography/src/gatsby-node.js
index 12b90c478..260c77146 100644
--- a/packages/gatsby-plugin-typography/src/gatsby-node.js
+++ b/packages/gatsby-plugin-typography/src/gatsby-node.js
@@ -5,14 +5,14 @@ const os = require(`os`)
 // Write out a typography module to .cache.

 exports.onPreBootstrap = ({ store }, pluginOptions) => {
-  const program = store.getState().program
-
   let module
   if (pluginOptions.pathToConfigModule) {
-    module = `module.exports = require("${path.join(
-      program.directory,
-      pluginOptions.pathToConfigModule
-    )}")`
+    module = `module.exports = require("${
+      path.isAbsolute(pluginOptions.pathToConfigModule)
+        ? console.log("isAbsolute") || pluginOptions.pathToConfigModule
+        : console.log("isRelative") ||
+          path.join(program.directory, pluginOptions.pathToConfigModule)
+    }")`
     if (os.platform() == `win32`) {
       module = module.split(`\\`).join(`\\\\`)
     }
@@ -22,11 +22,11 @@ const typography = new Typography()
 module.exports = typography`
   }

-  const dir = `${__dirname}/.cache`
+  const dir = `${store.getState().program.directory}/.cache`

   if (!fs.existsSync(dir)) {
     fs.mkdirSync(dir)
   }
-
+  console.log("typography ::::::::: ", module)
   fs.writeFileSync(`${dir}/typography.js`, module)
 }
KyleAMathews commented 5 years ago

Published https://github.com/gatsbyjs/gatsby/pull/10859#issuecomment-451715656