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

Skip typegen for routes outside the app directory #12996

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

wilcoxmd
Copy link

@wilcoxmd wilcoxmd commented Feb 11, 2025

This is a fix for #12993.

This PR limits typegen to only occur for route files in the current project's app directory. This behavior should be consistent with the current getTypesPath logic and generated Module typing, which also seem to assume that route files are located in the app directory.

Adding this check prevents type files from being generated outside .react-router/types (which can cause tsc failures) if a route file is located outside the current project's app directory, which is the case for route definitions imported from a library or monorepo workspace package. For now, route library/workspace packages can rely on their own separate typecheck processes to ensure routes are typesafe before they are imported to another application.

In the future it would be nice to figure out a way to include library route typings into a host project's typegen process. However, I imagine this approach would probably require more thought and input from the team to decide on where to generate those files and how they should be consumed. In the meantime, this PR's goal is just to help prevent unintended issues without changing the current typgen behavior too much.

Very open to feedback on this, particularly on the testing approach! I couldn't find a great pattern for testing workspace-style project structures, so I just created a new set of fixtures and a way to tweak their content as part of setting up the test in 74fed50. Let me know if you'd prefer a different strategy!

Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: 7f1f4b9

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

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve 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 Feb 11, 2025

Hi @wilcoxmd,

Welcome, and thank you for contributing to React Router!

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 hello@remix.run.

Thanks!

- The Remix team

Adds workspace routes fixture and a failing test
@wilcoxmd wilcoxmd force-pushed the mwilcox/skip-imported-route-typegen branch from 88c709a to 50d0f95 Compare February 11, 2025 07:37
@@ -1,5 +1,5 @@
packages:
- "integration"
- "integration/helpers/*"
- "integration/helpers/**"
Copy link
Author

@wilcoxmd wilcoxmd Feb 11, 2025

Choose a reason for hiding this comment

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

This update allows the workspace fixture to install node modules in nested directories

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 12, 2025

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

@wilcoxmd wilcoxmd force-pushed the mwilcox/skip-imported-route-typegen branch 2 times, most recently from 2132477 to 725539b Compare February 12, 2025 16:28
@wilcoxmd wilcoxmd force-pushed the mwilcox/skip-imported-route-typegen branch from 725539b to 9d0dc64 Compare February 12, 2025 16:40
@@ -71,11 +72,21 @@ async function createContext({
};
}

function isRouteInAppDirectory(ctx: Context, route: RouteManifestEntry) {
const absoluteRoutePath = Path.resolve(ctx.config.appDirectory, route.file);
Copy link
Author

Choose a reason for hiding this comment

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

const root = path.resolve(__dirname, "../..");
const TMP_DIR = path.join(root, ".tmp/integration");

export async function writeTestFiles(
Copy link
Author

Choose a reason for hiding this comment

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

This function, and the logic in createTestDirectory below were pulled from other files and just refactored into this file for reuse.

@wilcoxmd wilcoxmd marked this pull request as ready for review February 12, 2025 17:06
@pcattori pcattori self-assigned this Feb 12, 2025
…d-route-typegen

* upstream/dev:
  bump patch to minor for new API: `href`
  Type-safe href (remix-run#12994)
  docs: prerender/ssr:false (remix-run#13005)
  Skip action-only resource routes with prerender:true (remix-run#13004)
  Update docs for spa/prerendering
  Improvements to ssr:false + prerender scenarios (remix-run#12948)
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.

2 participants