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

feat: support browser runtime for tw plugin #1072

Merged
merged 8 commits into from
Dec 3, 2024
Merged

Conversation

juliusmarminge
Copy link
Collaborator

@juliusmarminge juliusmarminge commented Nov 27, 2024

Closes #1070

adds a version of the /tw subpath that doesn't use node so you can import your tailwind config in the browser

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new Tailwind CSS plugin for UploadThing, allowing for custom variants for UI components.
    • Added a browser-specific entry point for the tw module.
  • Improvements

    • Updated the bunchee dependency across multiple packages to enhance build tool performance and compatibility.
    • Enhanced type declaration paths for media types in the mime-types package.
  • Bug Fixes

    • Resolved issues related to Tailwind CSS configuration integration.
  • Documentation

    • Updated documentation to guide users on integrating the new Tailwind CSS plugin.

Copy link

changeset-bot bot commented Nov 27, 2024

🦋 Changeset detected

Latest commit: 6a5265f

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

This PR includes changesets to release 1 package
Name Type
uploadthing Minor

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

Copy link

vercel bot commented Nov 27, 2024

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing 🛑 Canceled (Inspect) Dec 3, 2024 5:43pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 5:43pm

@juliusmarminge juliusmarminge marked this pull request as draft November 27, 2024 16:04
Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Warning

Rate limit exceeded

@juliusmarminge has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6ea99f2 and 6a5265f.

Walkthrough

The pull request includes updates to multiple package.json files across various packages in the UploadThing project. The primary change is the upgrade of the bunchee dependency from version ^5.2.1 to ^5.6.2 in several packages. Additionally, the uploadthing package has a new browser-specific entry point added to its exports. There are also new TypeScript files introduced for Tailwind CSS integration, while an old Tailwind CSS plugin file has been removed.

Changes

File Path Change Summary
packages/expo/package.json Updated bunchee dependency from ^5.2.1 to ^5.6.2.
packages/mime-types/package.json Updated version from 0.3.2 to 0.3.2, updated bunchee from ^5.2.1 to ^5.6.2, changed types paths in exports from .d.ts to .d.cts.
packages/react/package.json Updated bunchee dependency from ^5.2.1 to ^5.6.2.
packages/shared/package.json Updated bunchee dependency from ^5.2.1 to ^5.6.2.
packages/uploadthing/package.json Updated version to 7.3.0, added browser entry point ./tw/index.browser.js, updated bunchee from ^5.2.1 to ^5.6.2.
packages/uploadthing/src/tw.ts Removed Tailwind CSS plugin file (tw.ts).
packages/uploadthing/src/tw/index.browser.ts Added new file for Tailwind CSS plugin integration.
packages/uploadthing/src/tw/index.ts Added Tailwind CSS configuration helper function.
packages/uploadthing/src/tw/plugin.ts Introduced new Tailwind CSS plugin with custom variants.
packages/vue/package.json Updated bunchee dependency from ^5.2.1 to ^5.6.2.

Assessment against linked issues

Objective Addressed Explanation
Fix NextJS build failure with withUt function (#1070) Unclear if the changes fully resolve the issue.

Possibly related PRs

Suggested labels

@uploadthing/react, 📚 documentation, examples

Suggested reviewers

  • markflorkowski

🐇 In the code, we hop and play,
With bunchee updated, hip-hip-hooray!
Tailwind's plugins now shine bright,
In the UploadThing, all feels right!
Let's build and bundle, make it grand,
A joyful leap, together we stand! 🌟


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

pkg-pr-new bot commented Nov 27, 2024

Open in Stackblitz

More templates

@uploadthing/expo

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/expo@1072

@uploadthing/nuxt

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/nuxt@1072

@uploadthing/mime-types

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/mime-types@1072

@uploadthing/shared

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/shared@1072

@uploadthing/react

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/react@1072

uploadthing

npm i https://pkg.pr.new/pingdotgg/uploadthing@1072

@uploadthing/vue

npm i https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/vue@1072

commit: 6a5265f

Copy link
Contributor

github-actions bot commented Nov 27, 2024

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 27.59KB See Treemap 📊
PR (6ab1538) 27.60KB See Treemap 📊
Diff ↑2.00B

Copy link
Contributor

A new canary is available for testing. You can install this latest build in your project with:

pnpm add @uploadthing/expo@7.1.2-canary.0fa10f9
pnpm add @uploadthing/mime-types@0.3.3-canary.0fa10f9
pnpm add @uploadthing/nuxt@7.1.2-canary.0fa10f9
pnpm add @uploadthing/react@7.1.2-canary.0fa10f9
pnpm add @uploadthing/shared@7.1.2-canary.0fa10f9
pnpm add @uploadthing/solid@7.1.2-canary.0fa10f9
pnpm add @uploadthing/svelte@7.1.2-canary.0fa10f9
pnpm add uploadthing@7.3.1-canary.0fa10f9
pnpm add @uploadthing/vue@7.1.2-canary.0fa10f9

@github-actions github-actions bot removed the release canary Trigger a canary release to npm label Nov 28, 2024
@juliusmarminge juliusmarminge marked this pull request as ready for review December 2, 2024 21:00
@juliusmarminge juliusmarminge added the release canary Trigger a canary release to npm label Dec 2, 2024
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: 4

🧹 Outside diff range and nitpick comments (3)
packages/mime-types/package.json (1)

⚠️ Package exports configuration needs adjustment

The package.json exports field references files in non-existent directories. The source files (application.ts, audio.ts, etc.) are located in the src directory, but the exports field incorrectly points to root-level directories. The exports paths should be updated to point to the dist directory where the built files will be located.

  • Update the exports field paths to use dist/ prefix:
    "./application": {
      "import": {
        "types": "./dist/application/index.d.ts",
        "default": "./dist/application/index.js"
      }
    }
  • Similar updates needed for audio, image, text, and video exports
🔗 Analysis chain

Line range hint 9-67: Verify dual package hazard prevention

The exports field is well-structured for dual CJS/ESM support. However, let's verify that all entry points are properly built and that there are no dual package hazards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all exported paths exist and match the expected format

# Check if all the declared export paths exist
for type in application audio image text video; do
  echo "Checking $type exports..."
  fd -t f "index\.(js|cjs|d\.ts|d\.cts)$" "$type"
done

# Check if package.json has proper "type": "module" field
grep -r "require.*\.js\"" . && echo "Warning: Found .js extension in require conditions"

Length of output: 1486


Script:

#!/bin/bash
# Let's check if these directories exist in the dist folder instead
echo "Checking dist directory structure..."
fd -t d "^(application|audio|image|text|video)$" dist

echo -e "\nChecking for entry point files in dist..."
fd -t f "index\.(js|cjs|d\.ts|d\.cts)$" dist

echo -e "\nChecking package.json type field..."
grep '"type":' packages/mime-types/package.json

echo -e "\nChecking build scripts in package.json..."
grep -A 5 '"build":' packages/mime-types/package.json

Length of output: 1054


Script:

#!/bin/bash
# Let's check the source files and build configuration
echo "Checking source files structure..."
fd -t f "index\.ts$" src

echo -e "\nChecking tsconfig.build.json contents..."
cat packages/mime-types/tsconfig.build.json

echo -e "\nChecking if bunchee is configured..."
cat packages/mime-types/bunchee.config.ts 2>/dev/null || echo "No bunchee config found"

echo -e "\nChecking source directory structure..."
fd -t d "^(application|audio|image|text|video)$" src

Length of output: 863


Script:

#!/bin/bash
# Let's check the correct paths within the package directory
echo "Checking source files in package directory..."
fd -t f "index\.ts$" packages/mime-types/src

echo -e "\nChecking source directory structure in package..."
ls -la packages/mime-types/src 2>/dev/null

echo -e "\nChecking if dist directory exists in package..."
ls -la packages/mime-types/dist 2>/dev/null

echo -e "\nChecking package root structure..."
ls -la packages/mime-types/

Length of output: 1726

packages/uploadthing/src/tw/plugin.ts (1)

11-23: LGTM! Clean implementation of the Tailwind plugin.

The plugin implementation follows best practices by using data attributes for variants and provides clear separation between element and state selectors.

Consider adding variants for additional upload states.

The current implementation covers basic states (readying, ready, uploading), but common upload workflows might benefit from additional states:

  • ut-error for failed uploads
  • ut-completed for successful uploads
  • ut-rejected for invalid file types
 // Variants to select specific state
 addVariant("ut-readying", '&[data-state="readying"]');
 addVariant("ut-ready", '&[data-state="ready"]');
 addVariant("ut-uploading", '&[data-state="uploading"]');
+addVariant("ut-error", '&[data-state="error"]');
+addVariant("ut-completed", '&[data-state="completed"]');
+addVariant("ut-rejected", '&[data-state="rejected"]');
packages/uploadthing/src/tw/index.ts (1)

32-44: Enhance warning message clarity

The warning message could be more specific about the environment context.

Consider updating the message:

- [uploadthing]: Unable to resolve path for uploadthing UI packages.
+ [uploadthing]: Unable to resolve path for uploadthing UI packages. This is expected when running in a browser environment.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa5db8 and 6ea99f2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • packages/expo/package.json (1 hunks)
  • packages/mime-types/package.json (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/shared/package.json (1 hunks)
  • packages/uploadthing/package.json (2 hunks)
  • packages/uploadthing/src/tw.ts (0 hunks)
  • packages/uploadthing/src/tw/index.browser.ts (1 hunks)
  • packages/uploadthing/src/tw/index.ts (1 hunks)
  • packages/uploadthing/src/tw/plugin.ts (1 hunks)
  • packages/vue/package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/uploadthing/src/tw.ts
🔇 Additional comments (7)
packages/mime-types/package.json (1)

92-92: Verify the bunchee upgrade impact

The upgrade of bunchee from ^5.2.1 to ^5.6.2 might be related to the browser runtime support needed for the tw plugin. Let's verify the changelog for any breaking changes.

✅ Verification successful

Bunchee upgrade is safe and aligned with browser runtime support

The upgrade from 5.2.1 to 5.6.2 brings improvements that align well with the PR's objective of browser runtime support:

  • v5.6.2: Improved handling of conditional imports for shared modules
  • v5.6.1: Added support for browserlists from package.json
  • v5.6.0: Mainly dependency updates
  • v5.5.1: Enhanced support for special fields of target runtime

No breaking changes were introduced in this version range, and the changes actually improve browser-related functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check bunchee's changelog for breaking changes between 5.2.1 and 5.6.2

# Get the changelog or release notes
gh api repos/huozhi/bunchee/releases | jq -r '.[].body' | grep -A 10 "5\.6\."

Length of output: 1662

packages/shared/package.json (1)

46-46: Verify bunchee upgrade compatibility.

The upgrade from ^5.2.1 to ^5.6.2 is a minor version bump, but please verify:

  1. Any breaking changes in the bunchee changelog
  2. Compatibility with the browser bundle requirements for this PR
✅ Verification successful

Bunchee version upgrade is safe to proceed

The version upgrade from ^5.2.1 to ^5.6.2 appears safe as:

  1. Bunchee is consistently used across multiple packages in the monorepo with the same version ^5.6.2
  2. It's used primarily for building TypeScript/JavaScript packages with similar configuration patterns
  3. The minor version bump (5.2 to 5.6) follows semver, indicating backward compatibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check bunchee changelog for breaking changes between 5.2.1 and 5.6.2

# Fetch the changelog
curl -s https://raw.githubusercontent.com/huozhi/bunchee/main/CHANGELOG.md | grep -A 10 "5\.6\.2\|5\.6\.1\|5\.6\.0\|5\.5\.0\|5\.4\.0\|5\.3\.0"

Length of output: 144


Script:

#!/bin/bash
# Let's check the build configuration and usage of bunchee in the codebase

# Find files that mention bunchee
rg -l "bunchee" --type-add 'config:*.{json,js,ts,cjs,mjs}' -t config

# Check package.json files for bunchee version across packages
fd package.json --exec grep -l "bunchee" {} \; | xargs cat

# Look for bunchee configuration files
fd -e bunche.config.js -e bunchee.config.ts -e bunchee.config.mjs

Length of output: 19072

packages/uploadthing/src/tw/index.ts (1)

22-24: ⚠️ Potential issue

Review Node.js-specific API usage

The require.resolve call with module.paths is Node.js specific and won't work in browsers. This needs a browser-compatible alternative.

Let's verify if there's a browser version of this file:

packages/expo/package.json (1)

43-43: Verify bunchee version compatibility

The upgrade to bunchee 5.6.2 might be related to browser bundle support.

Let's check the changelog for relevant changes:

✅ Verification successful

Let me gather more information about the specific changes in these versions.


Let me check the changes in intermediate versions to ensure we don't miss any significant browser-related changes.


Bunchee upgrade includes important browser support improvements

The upgrade from 5.2.1 to 5.6.2 includes significant browser-related enhancements:

  • Support for browserlists from package.json (v5.6.0)
  • Improved special fields handling for target runtime (v5.5.0)
  • Enhanced ESM-shim matching (v5.6.2)

These changes are beneficial for browser bundle support and compatibility. The upgrade is appropriate and recommended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch bunchee releases between 5.2.1 and 5.6.2
gh release list -R huozhi/bunchee -L 10 | grep -E "v5\.[2-6]"

Length of output: 315


Script:

#!/bin/bash
# Fetch release notes for relevant versions
gh release view v5.6.2 -R huozhi/bunchee
gh release view v5.2.1 -R huozhi/bunchee

Length of output: 961


Script:

#!/bin/bash
# Check intermediate versions for browser-related changes
gh release view v5.6.0 -R huozhi/bunchee
gh release view v5.5.0 -R huozhi/bunchee
gh release view v5.4.0 -R huozhi/bunchee
gh release view v5.3.0 -R huozhi/bunchee

Length of output: 2552

packages/vue/package.json (1)

50-50: Verify consistent bunchee version

The bunchee version update matches other packages, maintaining consistency.

packages/react/package.json (1)

85-85: LGTM: Bunchee version bump as requested

The update to bunchee ^5.6.2 aligns with the requested change from the previous review and should help resolve the build issues.

packages/uploadthing/package.json (1)

169-169: LGTM: Bunchee version bump as requested

The update to bunchee ^5.6.2 aligns with the requested change from the previous review and should help resolve the build issues.

packages/uploadthing/src/tw/index.browser.ts Show resolved Hide resolved
Comment on lines +46 to +51
if (Array.isArray(twConfig.content)) {
twConfig.content.push(...contentPaths);
} else {
// content can be an object too with `files` property
twConfig.content.files.push(...contentPaths);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add type checking for content object structure

The code assumes the content object has a files property without type checking.

Add type checking to prevent runtime errors:

  } else {
    // content can be an object too with `files` property
+   if (!twConfig.content || !Array.isArray(twConfig.content.files)) {
+     twConfig.content = { files: [] };
+   }
    twConfig.content.files.push(...contentPaths);
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Array.isArray(twConfig.content)) {
twConfig.content.push(...contentPaths);
} else {
// content can be an object too with `files` property
twConfig.content.files.push(...contentPaths);
}
if (Array.isArray(twConfig.content)) {
twConfig.content.push(...contentPaths);
} else {
// content can be an object too with `files` property
if (!twConfig.content || !Array.isArray(twConfig.content.files)) {
twConfig.content = { files: [] };
}
twConfig.content.files.push(...contentPaths);
}

@@ -0,0 +1,60 @@
import { dirname, sep } from "node:path";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider browser compatibility for Node.js imports

The node:path import will cause issues in browser environments. Given the PR's objective to support browser runtime, this needs to be addressed.

Consider creating a browser-specific version without Node.js dependencies:

- import { dirname, sep } from "node:path";
+ // For browser version:
+ const sep = '/';
+ const dirname = (path: string) => path.substring(0, path.lastIndexOf(sep));

Committable suggestion skipped: line range outside the PR's diff.

packages/uploadthing/package.json Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Dec 2, 2024

A new canary is available for testing. You can install this latest build in your project with:

pnpm add @uploadthing/expo@7.1.2-canary.2352c0f
pnpm add @uploadthing/mime-types@0.3.3-canary.2352c0f
pnpm add @uploadthing/nuxt@7.1.2-canary.2352c0f
pnpm add @uploadthing/react@7.1.2-canary.2352c0f
pnpm add @uploadthing/shared@7.1.2-canary.2352c0f
pnpm add @uploadthing/solid@7.1.2-canary.2352c0f
pnpm add @uploadthing/svelte@7.1.2-canary.2352c0f
pnpm add uploadthing@7.3.1-canary.2352c0f
pnpm add @uploadthing/vue@7.1.2-canary.2352c0f

@github-actions github-actions bot removed the release canary Trigger a canary release to npm label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: NextJS build fails with withUt tailwind config function
3 participants