Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdx.macro generating invalid documentPath on windows #67

Open
Zemnmez opened this issue Jul 28, 2020 · 1 comment
Open

mdx.macro generating invalid documentPath on windows #67

Zemnmez opened this issue Jul 28, 2020 · 1 comment

Comments

@Zemnmez
Copy link

Zemnmez commented Jul 28, 2020

Using mdx.macro on Windows gets me:

ERROR in C:/Users/thoma/OneDrive/Documents/devel/linear/node_modules/.cache/mdx.macro/icloud.c3ec31aebc.mdx.js
Module not found: Error: Can't resolve 'C:Users homaOneDriveDocumentsdevellinearpackagesarticleicloud.mdx' in 'C:\Users\thoma\OneDrive\Documents\devel\linear\node_modules\.cache\mdx.macro'

I tracked this down to a generated line that looks like this (in the cache):

import React from 'react';
import { MDXTag } from '@mdx-js/tag';
import "C:Users\thomaOneDriveDocumentsdevellinearpackagesarticlehow-to-hack-icloudicloud.mdx"; // here
export default (function (_ref) {
  var components = _ref.components,
      props = _objectWithoutProperties(_ref, ["components"]);

It looks like some part of mdx.macro is incorrectly processing windows slashes as escapes.

I'm guessing that what is happening here is that mdx.macro generates some code via concatenation, rather than via AST manipulation, so this line is generated by:

https://github.com/frontarm/mdx-util/blob/master/packages/mdx.macro/mdx.macro.js#L123

    imports += `import '${documentPath}'\n`

then converted to an AST and transformed here, like this:
https://github.com/frontarm/mdx-util/blob/master/packages/mdx.macro/mdx.macro.js#L129

  let transformedSource =
    babel.transformSync(
      imports+mdx.sync(source),
      {
        presets: [babelPresetReactApp],
        filename: documentPath,
      },
    ).code

I imagine what's going on here is that injecting the import via string concatenation on Windows is giving us something like:

import "c:\path\to\file"

which, after transformation by babel ends up being:

import "c:path\tofile"

The absolute quickest and dirtiest we can do here is just to escape all \.

@Zemnmez
Copy link
Author

Zemnmez commented Jul 28, 2020

should be fixed by #68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant