Skip to content

Commit 75adee3

Browse files
devdigitalChristopherBiscardi
authored andcommitted
fix: use platform agnostic paths
1 parent 38bf79b commit 75adee3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/gatsby-plugin-mdx/component-with-mdx-scope.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require("path");
44
const babel = require("@babel/core");
55
const syntaxObjRestSpread = require("@babel/plugin-syntax-object-rest-spread");
66
const debug = require("debug")("gatsby-mdx:component-with-mdx-scope");
7+
const slash = require("slash");
78

89
const BabelPluginPluckExports = require("babel-plugin-pluck-exports");
910

@@ -28,11 +29,8 @@ module.exports = function componentWithMDXScope(
2829

2930
const scopeHashes = codeScopeAbsPaths.map(codeScopeAbsPath => {
3031
// get the preexisting hash for the scope file to use in the new wrapper filename
31-
const scopePathSegments = codeScopeAbsPath.split("/");
32-
const scopeHash = scopePathSegments[scopePathSegments.length - 1].slice(
33-
0,
34-
-3
35-
);
32+
const base = path.parse(codeScopeAbsPath).base;
33+
const scopeHash = base.slice(0, -3);
3634
return scopeHash;
3735
});
3836

@@ -44,10 +42,10 @@ import React from 'react';
4442
import { MDXScopeProvider } from 'gatsby-mdx/context';
4543
4644
${codeScopeAbsPaths
47-
.map((scopePath, i) => `import __mdxScope_${i} from '${scopePath}';`)
45+
.map((scopePath, i) => `import __mdxScope_${i} from '${slash(scopePath)}';`)
4846
.join("\n")}
4947
50-
import OriginalWrapper from '${absWrapperPath}';
48+
import OriginalWrapper from '${slash(absWrapperPath)}';
5149
5250
import { graphql } from 'gatsby';
5351

packages/gatsby-plugin-mdx/loaders/mdx-loader.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const getSourcePluginsAsRemarkPlugins = require("../utils/get-source-plugins-as-
1919
const withDefaultOptions = require("../utils/default-options");
2020
const createMDXNode = require("../utils/create-mdx-node");
2121
const { createFileNode } = require("../utils/create-fake-file-node");
22+
const slash = require("slash");
2223

2324
const DEFAULT_OPTIONS = {
2425
footnotes: true,
@@ -129,7 +130,7 @@ module.exports = async function(content) {
129130
debug("inserting default layout", defaultLayout);
130131
const { content: contentWithoutFrontmatter } = grayMatter(content);
131132

132-
code = `import DefaultLayout from "${defaultLayout}"
133+
code = `import DefaultLayout from "${slash(defaultLayout)}"
133134
134135
135136
export default DefaultLayout

packages/gatsby-plugin-mdx/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"mdast-util-toc": "^2.0.1",
2727
"remark": "^9.0.0",
2828
"retext": "^5.0.0",
29+
"slash": "^2.0.0",
2930
"strip-markdown": "^3.0.1",
3031
"underscore.string": "^3.3.4",
3132
"unist-util-map": "^1.0.4",

0 commit comments

Comments
 (0)