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: use path.normalize to convert POSIX paths to OS-specific paths #5327

Closed
wants to merge 1 commit into from

Conversation

haines
Copy link
Contributor

@haines haines commented Jan 31, 2023

Closes: #5322

(from #5324): The build currently breaks when loading routes

ENOENT: no such file or directory, open '<root>/app/outes/<route file>'

Note it is trying to load from outes not routes!

The bug was introduced in #5266. By splitting and rejoining the paths, it drops the leading / on Unix-like systems, converting /Users/me/... to Users/me/.... However appDirectory still has a leading / so removing directory prefixes with slice drops one too many characters.

This PR resolves the issue by using path.normalize to covert / to \ on Windows, rather than splitting and rejoining the paths.

  • Tests

Testing Strategy:

This test covers this code (sort of... the test mirrors the production code so does not expose the bug):

describe("should return the correct route hierarchy", () => {

@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2023

🦋 Changeset detected

Latest commit: 1050325

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@remix-run/dev Patch
create-remix Patch
@remix-run/css-bundle Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/netlify Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch
@remix-run/vercel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jan 31, 2023

Hi @haines,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jan 31, 2023

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@machour
Copy link
Collaborator

machour commented Jan 31, 2023

Hey @haines, could you target the dev branch instead ? 🙏🏼

@haines haines changed the base branch from main to dev January 31, 2023 12:11
@haines
Copy link
Contributor Author

haines commented Jan 31, 2023

@machour done! Could you please re-approve the workflow run?

@@ -28,7 +28,7 @@ export function flatRoutes(
// fast-glob will return posix paths even on windows
// convert posix to os specific paths
let routePathsForOS = routePaths.map((routePath) => {
return path.join(...routePath.split(path.posix.sep));
return path.normalize(routePath);

Choose a reason for hiding this comment

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

TIL 👍

@machour
Copy link
Collaborator

machour commented Jan 31, 2023

As far as I see, this PR is modifying a test already passing.
Could you revert that and add a new test case to verify what you're fixing instead? 🤔

@haines
Copy link
Contributor Author

haines commented Jan 31, 2023

@machour the existing test just mirrors the production code, so the test has the same bug and it needs to be modified. The problem is that the test exercises the internal function flatRoutesUniversal (to avoid having to run against a real filesystem), but the bug occurs in flatRoutes.

I could rewrite the test to exercise flatRoutes instead, but that'd require writing the test files to the filesystem (in a temporary directory). What do you think?

@MichaelDeBoey
Copy link
Member

Superseded by #5228

@haines haines deleted the fix-flat-routes branch February 6, 2023 22:54
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

🤖 Hello there,

We just published version v0.0.0-nightly-a024557-20230207 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging this pull request may close these issues.

1.12 ENOENT: no such file or directory referencing outes instead of routes
4 participants