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

fix: handle Windows style path in generateWildcardRequire #153

Merged
merged 2 commits into from Mar 22, 2022
Merged

fix: handle Windows style path in generateWildcardRequire #153

merged 2 commits into from Mar 22, 2022

Conversation

yichi-yang
Copy link
Contributor

@yichi-yang yichi-yang commented Mar 19, 2022

Fixes #154

styfle
styfle previously approved these changes Mar 22, 2022
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It would be great to add a test for this so we can ensure we don't regress (I'll have to enable windows CI in the future)

@yichi-yang
Copy link
Contributor Author

yichi-yang commented Mar 22, 2022

Thanks! It would be great to add a test for this so we can ensure we don't regress (I'll have to enable windows CI in the future)

I added a unit test for #154. I tried on my Windows machine and it passes after the fix 48d3692 (but fails before the fix, reproducing the bug).


Actually running the tests on my machine caught another bug related to path separators. But I think that might be a separate issue and is better fixed in another PR?

Edit: I've figured this one out. JSON.stringify(curPattern) escapes the \ and .replace turns it into two /s.

assetExpressions += " + \'" + JSON.stringify(curPattern).replace(/\\/g, '/').slice(1, -1) + "'";

Let me know if you want the fix in this PR or a separate one.

  ● should generate correct output for wildcard2

    expect(received).toBe(expected) // Object.is equality

    - Expected  - 1
    + Received  + 1

    @@ -42,11 +42,11 @@
      var __webpack_exports__ = {};
      // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
      (() => {
      const path = __webpack_require__(622);

    - fs.readFileSync(__webpack_require__.ab + "wildcard2/" + unknown + '/asset1.txt');
    + fs.readFileSync(__webpack_require__.ab + "wildcard2/" + unknown + '//asset1.txt');


      })();

      module.exports = __webpack_exports__;

      112 |       .replace(/\r/g, "");
      113 |     try {
    > 114 |       expect(actual).toBe(expected);
          |                      ^
      115 |     } catch (e) {
      116 |       // useful for updating fixtures
      117 |       fs.writeFileSync(`${testDir}/actual.js`, actual);

      at Object.toBe (test/index.test.js:114:22)

@styfle styfle enabled auto-merge (squash) March 22, 2022 14:34
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Lets do a separate PR for the other fix since this one looks good 👍

@styfle styfle merged commit bbb3be9 into vercel:main Mar 22, 2022
@github-actions
Copy link

🎉 This PR is included in version 1.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@styfle
Copy link
Member

styfle commented Mar 22, 2022

I added windows to CI in #155 but looks like there is more work to make it compatible

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

Successfully merging this pull request may close these issues.

Inconsitant handling of path seperators resulting in generateWildcardRequire generating invalid conditions
2 participants