robwalkerco / gatsby-plugin-compile-es6-packages

Easily add support for compiling ES6 packages into Gasby projects
https://www.gatsbyjs.org/packages/gatsby-plugin-compile-es6-packages/
MIT License
24 stars 3 forks source link

The module rule does not work correctly for scoped package in windows OS #4

Closed malcolm-kee closed 5 years ago

malcolm-kee commented 5 years ago

First of all, thanks for creating this plugin!

It seems like the regex rule doesn't work in Windows for scoped package.

Investigation

Upon investigation, it's because the scoped package path will be backslash in windows, e.g. package @philpl/buble will have the path value in Windows OS as my\path\node_modules\@philpl\buble, and the regex could not detect it.

Suggested Solution

To fix it, the following regex rule at here can be changed from

!new RegExp(
   `node_modules[\\\\/](${modules
      .map(regexEscape)
      .join("|")})[\\\\/]`
).test(modulePath)

to

!new RegExp(
   `node_modules[\\\\/](${modules
      .map(mod => mod.replace(/\//, path.sep))
      .map(regexEscape)
      .join("|")})[\\\\/]`
).test(modulePath)

Let me know if you prefer me to create a PR to add the changes.

Thanks!

SeanKilleen commented 5 years ago

@malcolm-kee can I suggest creating the PR so that @robwalkerco has that much less overhead should they choose to merge it? I'm happy to do so as well but figured you deserved the credit in PR form. :)

FWIW I am also affected by this, and agree with Malcom's assessment that this would likely fix the issue.

robwalkerco commented 5 years ago

A PR would be great 😀

SeanKilleen commented 5 years ago

Created #5 with credit to @malcolm-kee. If he feels strongly about it, feel free to close or do whatever is needed to give credit. 👍 My guess is he'll be OK with getting the fix in sooner than later but don't want to speak for him