From 6cd114f8de13fbd4bea5a9859195d144f920757d Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 13 Nov 2017 12:27:34 -0800 Subject: [PATCH] Use normalize-path so tests pass on windows (#2908) * Use normalize-path so tests pass on windows * Format * Fix last test * Almost got them all... --- packages/gatsby-remark-code-repls/package.json | 1 + packages/gatsby-remark-code-repls/src/constants.js | 6 +++--- packages/gatsby-remark-code-repls/src/gatsby-node.js | 4 +++- packages/gatsby-remark-code-repls/src/index.js | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-remark-code-repls/package.json b/packages/gatsby-remark-code-repls/package.json index 6695172dc5468..7aa54610f2e5d 100644 --- a/packages/gatsby-remark-code-repls/package.json +++ b/packages/gatsby-remark-code-repls/package.json @@ -6,6 +6,7 @@ "dependencies": { "babel-runtime": "^6.26.0", "lz-string": "^1.4.4", + "normalize-path": "^2.1.1", "recursive-readdir-synchronous": "^0.0.3", "unist-util-map": "^1.0.3" }, diff --git a/packages/gatsby-remark-code-repls/src/constants.js b/packages/gatsby-remark-code-repls/src/constants.js index e700beb1385e4..7cdbfa6f51082 100644 --- a/packages/gatsby-remark-code-repls/src/constants.js +++ b/packages/gatsby-remark-code-repls/src/constants.js @@ -1,12 +1,12 @@ "use strict" const { join } = require(`path`) +const normalizePath = require(`normalize-path`) module.exports = { OPTION_DEFAULT_LINK_TEXT: `REPL`, - OPTION_DEFAULT_REDIRECT_TEMPLATE_PATH: join( - __dirname, - `default-redirect-template.js` + OPTION_DEFAULT_REDIRECT_TEMPLATE_PATH: normalizePath( + join(__dirname, `default-redirect-template.js`) ), PROTOCOL_BABEL: `babel://`, PROTOCOL_CODEPEN: `codepen://`, diff --git a/packages/gatsby-remark-code-repls/src/gatsby-node.js b/packages/gatsby-remark-code-repls/src/gatsby-node.js index 311aeb29b4276..9a90fa00162e9 100644 --- a/packages/gatsby-remark-code-repls/src/gatsby-node.js +++ b/packages/gatsby-remark-code-repls/src/gatsby-node.js @@ -3,6 +3,7 @@ const fs = require(`fs`) const { extname, resolve } = require(`path`) const recursiveReaddir = require(`recursive-readdir-synchronous`) +const normalizePath = require(`normalize-path`) const { OPTION_DEFAULT_LINK_TEXT, @@ -65,7 +66,8 @@ exports.createPages = ( createPage({ path: slug, - component: resolve(redirectTemplate), + // Normalize the path so tests pass on Linux + Windows + component: normalizePath(resolve(redirectTemplate)), context: { action, payload, diff --git a/packages/gatsby-remark-code-repls/src/index.js b/packages/gatsby-remark-code-repls/src/index.js index 1e34afbc9dd99..34499a0e17bc8 100644 --- a/packages/gatsby-remark-code-repls/src/index.js +++ b/packages/gatsby-remark-code-repls/src/index.js @@ -4,6 +4,7 @@ const fs = require(`fs`) const LZString = require(`lz-string`) const { join } = require(`path`) const map = require(`unist-util-map`) +const normalizePath = require(`normalize-path`) const { OPTION_DEFAULT_LINK_TEXT, @@ -48,7 +49,7 @@ module.exports = ( if (!filePath.endsWith(`.js`)) { filePath += `.js` } - filePath = join(directory, filePath) + filePath = normalizePath(join(directory, filePath)) return filePath }