Skip to content

Conversation

@juraj98
Copy link
Contributor

@juraj98 juraj98 commented Sep 24, 2024

Second attempt at fixing #975. I believe this should work. Tested in solidstart in monorepo, and outside of monorepo.

I hope this does what I think it does, but the idea is to add current working directory via process.cwd() to paths require.resolve looks for.

Summary by CodeRabbit

  • New Features
    • Enhanced module resolution for the withUt feature, improving its functionality in monorepo environments.
    • Introduced documentation for the patch related to the uploadthing functionality, focusing on compatibility within monorepos.
  • Documentation
    • Updated references in TypeScript configuration comments to direct users to the latest Next.js documentation for better clarity.
  • Chores
    • Simplified Tailwind configuration by removing problematic paths and ensuring it only includes necessary source file paths.

@changeset-bot
Copy link

changeset-bot bot commented Sep 24, 2024

🦋 Changeset detected

Latest commit: 9e5d416

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

This PR includes changesets to release 1 package
Name Type
uploadthing 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

@vercel
Copy link

vercel bot commented Sep 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 25, 2024 8:00am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Sep 25, 2024 8:00am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The pull request introduces enhancements to the withUt function in the packages/uploadthing/src/tw.ts file, focusing on improving module resolution by updating the require.resolve function. This adjustment involves incorporating an options object with a paths property for more flexible module resolution. Additionally, several next-env.d.ts files across examples have been updated to reflect new documentation URLs for TypeScript configuration in Next.js, ensuring clarity and accuracy. A new markdown file documenting a patch for the "uploadthing" functionality has also been added.

Changes

Files Change Summary
packages/uploadthing/src/tw.ts Modified the withUt function to improve module resolution with an updated require.resolve function.
examples/minimal-appdir/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/minimal-pagedir/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/profile-picture/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/with-novel/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/with-react-image-crop/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/with-serveractions/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
examples/with-tailwindcss/next-env.d.ts Updated comment to change TypeScript configuration URL for Next.js documentation.
.changeset/shiny-singers-live.md Introduced a new markdown file documenting a patch for the "uploadthing" functionality for monorepo compatibility.

Possibly related PRs

  • fix(docs): force path resolution #953: This PR addresses path resolution issues in the Tailwind CSS configuration, which is directly related to the changes made in the withUt function for module resolution in the main PR.
  • chore: Update solidstart example #985: This PR introduces a new Tailwind CSS configuration that utilizes the withUt function, indicating a direct connection to the changes made in the main PR regarding the withUt function's operation.
  • docs: Fixed SolidStart and slightly changed Tanstack/Start #988: This PR enhances the documentation for SolidStart and includes adjustments related to the uploadRouter, which is relevant to the changes made in the main PR regarding the withUt function and its integration with UploadThing.

Suggested labels

📚 documentation

Suggested reviewers

  • juliusmarminge

Poem

In the code where rabbits play,
A patch was made, hip-hip-hooray!
With paths aligned, the modules cheer,
In monorepos, they have no fear.
So hop along, let changes flow,
With withUt, the features grow! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
.changeset/shiny-singers-live.md (1)

1-5: Changeset looks good, with a minor suggestion for improvement.

The changeset file correctly documents the patch update for the "uploadthing" package, which aligns with the PR objectives. The use of a patch version is appropriate for this bug fix.

Consider expanding the change description slightly to provide more context. For example:

-Fixed withUt to work in monorepos
+Fixed withUt to work in monorepos by adjusting module resolution process

This addition gives users a bit more insight into the nature of the fix without going into unnecessary technical details.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 073c4ec and 030e4f4.

Files selected for processing (2)
  • .changeset/shiny-singers-live.md (1 hunks)
  • packages/uploadthing/src/tw.ts (1 hunks)
Additional comments not posted (1)
packages/uploadthing/src/tw.ts (1)

13-16: Approve changes with suggestions for improvement

The modification to require.resolve aligns well with the PR objectives, addressing the issue with withUt in monorepos by incorporating the current working directory in the module resolution process. This change should improve the reliability of module resolution in various monorepo setups.

Here are some suggestions to further improve the code:

  1. Add a comment explaining the reasoning behind this change, e.g.:

    // Include process.cwd() to support module resolution in monorepos
  2. Consider potential edge cases:

    • What happens if process.cwd() is already included in module.paths?
    • Are there any performance implications of adding an extra path to resolve?
  3. It would be beneficial to verify this change in different monorepo setups to ensure it works as expected across various configurations.

To verify the impact and effectiveness of this change, you can run the following script:

This script will help identify potential areas of impact and verify that the change is comprehensive across the project.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fd648c1 and 9e5d416.

📒 Files selected for processing (2)
  • docs/tailwind.config.ts (1 hunks)
  • examples/minimal-solidstart/tailwind.config.js (1 hunks)

"./src/**/*.{js,jsx,ts,tsx}",
"./node_modules/@uploadthing/solid/dist/**/*.js", // Remove this once #975 is resolved
],
content: ["./src/**/*.{js,jsx,ts,tsx}"],
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Potential Issue with Removing @uploadthing/solid Imports

The removal of the @uploadthing/solid entry from the content array may lead to missing styles or functionalities in components that rely on this package. Given that several files, including examples and documentation, still import @uploadthing/solid, it's crucial to ensure that this change does not adversely affect the project's styling or functionality.

🔗 Analysis chain

Simplified content array: Potential concerns and clarifications needed

The simplification of the content array to focus only on the project's source files is a good step towards improving the build process in a monorepo context. This change aligns with the PR objective of fixing withUt in monorepos.

However, I have a few points to address:

  1. Can you confirm that removing the @uploadthing/solid entry from the content array won't cause any missing styles or functionality? It's important to ensure that all necessary styles are still being included.

  2. The PR objectives mention modifying the require.resolve behavior, but this change doesn't directly address that. Could you clarify how this configuration change relates to the require.resolve modification mentioned in the PR description?

To ensure no critical styles are missing, let's check for any @uploadthing/solid imports in the project:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for @uploadthing/solid imports in the project
# Expected result: No imports found, confirming the removal is safe

rg --type js --type ts '@uploadthing/solid'

Length of output: 372

// to be some local workspace issue, making pnpm fail to resolve `@uploadthing/react`
"./node_modules/@uploadthing/react/dist/**/*.js",
],
content: ["./src/**/*.{js,mjs,jsx,ts,tsx,mdx}"],
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Tailwind classes with ut- prefix are still present in the codebase.

The presence of ut- prefixed Tailwind classes suggests that classes from @uploadthing/react might still be in use. Please review these instances to ensure they align with the intended changes and do not reintroduce the issues the PR aims to resolve.

🔗 Analysis chain

LGTM! Simplified content array may resolve monorepo issues.

The simplification of the content array to only include files from the ./src directory is a good practice and aligns with the PR objectives to fix issues with withUt in monorepos. Removing the commented-out node_modules path should help resolve the workspace resolution problems mentioned in the AI summary.

To ensure this change doesn't negatively impact the functionality of withUt, please run the following verification script:

If the script shows that withUt is still being imported and used, and no Tailwind classes from @uploadthing/react are being directly used in the project, then this change should be safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that withUt is still being properly imported and used after the content array change.

# Test: Check if withUt is still imported and used in the project
rg --type typescript 'import.*withUt' ./src
rg --type typescript 'withUt\(' ./src

# Test: Verify that no Tailwind classes from @uploadthing/react are being used in the project
rg --type typescript --type javascript --type jsx --type tsx 'className="[^"]*ut-[^"]*"' ./src

Length of output: 287


Script:

#!/bin/bash
# Description: Verify that withUt is still being properly imported and used after the content array change.

# Test: Check if withUt is still imported in the project
rg --files -g "*.ts" -g "*.tsx" -g "*.js" -g "*.jsx" -g "*.mjs" -g "*.cjs" | xargs rg 'import\s+.*withUt'

# Test: Check if withUt is being used in the project
rg --files -g "*.ts" -g "*.tsx" -g "*.js" -g "*.jsx" -g "*.mjs" -g "*.cjs" | xargs rg 'withUt\('

# Test: Verify that no Tailwind classes from @uploadthing/react are being used in the project
rg --files -g "*.ts" -g "*.tsx" -g "*.js" -g "*.jsx" -g "*.mjs" -g "*.cjs" | xargs rg 'className="[^"]*ut-[^"]*"'

Length of output: 2944

const resolved = require.resolve(`@uploadthing/${pkg}`);
return resolved.split(sep).slice(0, -1).join(sep) + `${sep}**`;
const resolved = require.resolve(`@uploadthing/${pkg}`, {
paths: [...module.paths, process.cwd()],
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for this, I probably would have spent quite some time to think of trying this xd

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