Skip to content

Stylus CLI updates #7502

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Stylus CLI updates #7502

wants to merge 8 commits into from

Conversation

kumaryash90
Copy link
Member

@kumaryash90 kumaryash90 commented Jul 2, 2025


PR-Codex overview

This PR focuses on enhancing the Stylus extension in the thirdweb SDK by adding new functionalities for contract deployment and event handling, including the stylus_constructor and deploy methods, along with their respective event definitions.

Detailed summary

  • Added stylus_constructor function in IStylusConstructor.json.
  • Introduced deploy function and ContractDeployed event in IStylusDeployer.json.
  • Implemented contractDeployedEvent in IStylusDeployer/events/ContractDeployed.ts.
  • Created isStylus_constructorSupported and stylus_constructor functions in stylus_constructor.ts.
  • Enhanced deployContract logic to handle Stylus deployment.
  • Added isDeploySupported and encodeDeployParams functions in IStylusDeployer/write/deploy.ts.
  • Updated createStylusProject command to support multiple project types.
  • Improved error handling and user feedback in the CLI commands.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added an "ERC721" project template option for project creation.
  • Improvements

    • Enhanced error handling with a unified success and failure check during project creation.

@kumaryash90 kumaryash90 requested review from a team as code owners July 2, 2025 10:29
Copy link

vercel bot commented Jul 2, 2025

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

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 11:54pm
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 11:54pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 11:54pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 11:54pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 11:54pm

Copy link

changeset-bot bot commented Jul 2, 2025

⚠️ No Changeset found

Latest commit: c37aff8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The code introduces an "ERC721" project template option to the CLI's project creation flow. It adds logic to handle this new type by cloning a specific repository, consolidates project creation into a single variable, and unifies error handling after all project types are attempted.

Changes

File(s) Change Summary
packages/thirdweb/src/cli/commands/stylus/create.ts Added "ERC721" project template option, unified project creation logic into a single variable, consolidated error handling for all branches.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant GitRepo

    User->>CLI: Select project type (ERC20, ERC721, etc.)
    CLI->>CLI: Assign newProject via spawnSync (based on type)
    alt type is ERC721
        CLI->>GitRepo: Clone ERC721 template repo
    else type is other
        CLI->>GitRepo: Clone/copy corresponding template
    end
    CLI->>CLI: Check newProject status
    alt Success
        CLI->>User: Project created
    else Failure
        CLI->>User: Show error and exit
    end
Loading

Possibly related PRs

  • Stylus ERC20 template for CLI #7192: Adds an ERC20 template and enhances ABI contract selection in the build process, modifying similar project creation logic in the same file as this PR.

Suggested labels

packages


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@kumaryash90 kumaryash90 marked this pull request as draft July 2, 2025 10:29
Copy link
Contributor

graphite-app bot commented Jul 2, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jul 2, 2025
@kumaryash90 kumaryash90 added the DO NOT MERGE This pull request is still in progress and is not ready to be merged. label Jul 2, 2025
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

🧹 Nitpick comments (1)
packages/thirdweb/src/cli/commands/stylus/create.ts (1)

66-72: Consider refactoring to reduce code duplication.

The ERC721 branch is nearly identical to the ERC20 branch, differing only in the repository URL and spinner message. Consider extracting the common logic into a helper function.

+  const cloneTemplate = (templateType: string, repoUrl: string, projectName: string) => {
+    spinner.start(`Creating new ${templateType} Stylus project: ${projectName}...`);
+    return spawnSync("git", ["clone", repoUrl, projectName], {
+      stdio: "inherit",
+    });
+  };
+
   } else if (projectType === "erc20") {
-    const repoUrl = "git@github.com:thirdweb-example/stylus-erc20-template.git";
-    spinner.start(`Creating new ERC20 Stylus project: ${projectName}...`);
-    newProject = spawnSync("git", ["clone", repoUrl, projectName], {
-      stdio: "inherit",
-    });
+    newProject = cloneTemplate("ERC20", "git@github.com:thirdweb-example/stylus-erc20-template.git", projectName);
   } else if (projectType === "erc721") {
-    const repoUrl = "git@github.com:thirdweb-example/stylus-erc721-template.git";
-    spinner.start(`Creating new ERC721 Stylus project: ${projectName}...`);
-    newProject = spawnSync("git", ["clone", repoUrl, projectName], {
-      stdio: "inherit",
-    });
+    newProject = cloneTemplate("ERC721", "git@github.com:thirdweb-example/stylus-erc721-template.git", projectName);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85c4ef1 and c01e0a8.

📒 Files selected for processing (1)
  • packages/thirdweb/src/cli/commands/stylus/create.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Write idiomatic TypeScript with explicit function declarations ...

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • packages/thirdweb/src/cli/commands/stylus/create.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: thirdweb-dev/js#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T10:25:29.488Z
Learning: Surface breaking changes prominently in PR descriptions
Learnt from: MananTank
PR: thirdweb-dev/js#7315
File: apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/nft/form.ts:25-42
Timestamp: 2025-06-10T00:46:00.514Z
Learning: In NFT creation functions, the setClaimConditions function signatures are intentionally different between ERC721 and ERC1155. ERC721 setClaimConditions accepts the full CreateNFTFormValues, while ERC1155 setClaimConditions accepts a custom object with nftCollectionInfo and nftBatch parameters because it processes batches differently than the entire form data.
packages/thirdweb/src/cli/commands/stylus/create.ts (1)
Learnt from: MananTank
PR: thirdweb-dev/js#7434
File: apps/dashboard/src/app/(app)/team/~/~/contract/[chain]/[contractAddress]/components/project-selector.tsx:62-76
Timestamp: 2025-06-24T21:38:03.155Z
Learning: In the project-selector.tsx component for contract imports, the addToProject.mutate() call is intentionally not awaited (fire-and-forget pattern) to allow immediate navigation to the contract page while the import happens in the background. This is a deliberate design choice to prioritize user experience.
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Build Packages
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/cli/commands/stylus/create.ts (1)

46-46: LGTM: ERC721 template option added correctly.

The new ERC721 template option follows the existing pattern and integrates well with the project type selection.

],
message: "Select a template:",
name: "projectType",
type: "select",
});

// Step 5: Create the project
let newProject;
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 explicit type annotation to comply with coding guidelines.

The variable declaration violates the coding guidelines which require explicit types and avoiding any. The implicit any type should be replaced with the proper return type.

-  let newProject;
+  let newProject: ReturnType<typeof spawnSync>;
📝 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
let newProject;
let newProject: ReturnType<typeof spawnSync>;
🤖 Prompt for AI Agents
In packages/thirdweb/src/cli/commands/stylus/create.ts at line 54, the variable
newProject is declared without an explicit type, causing an implicit any type
violation. Add an explicit type annotation to newProject that matches the
expected return type of the value it will hold, ensuring compliance with coding
guidelines that forbid implicit any types.

Comment on lines 74 to 77
if (!newProject?.status || newProject.status !== 0) {
spinner.fail("Failed to create Stylus project.");
process.exit(1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add explicit handling for unexpected project types.

The unified error handling is good, but if projectType doesn't match any known values, newProject remains undefined and triggers the error condition. Consider adding an explicit else clause or validation.

+  } else {
+    spinner.fail(`Unknown project type: ${projectType}`);
+    process.exit(1);
+  }
+
-  if (!newProject?.status || newProject.status !== 0) {
+  if (!newProject || newProject.status !== 0) {

This makes the error handling more explicit and removes the need for optional chaining since newProject will always be defined at this point.

🤖 Prompt for AI Agents
In packages/thirdweb/src/cli/commands/stylus/create.ts around lines 74 to 77,
add explicit validation for the projectType before creating newProject to ensure
it matches known values. Include an else clause that handles unexpected
projectType values by setting newProject to a defined error state or throwing an
error. This will guarantee newProject is always defined, allowing you to remove
optional chaining and make error handling more explicit and clear.

Copy link
Contributor

github-actions bot commented Jul 2, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.11 KB (0%) 1.3 s (0%) 476 ms (+121.86% 🔺) 1.8 s
thirdweb (cjs) 352.76 KB (0%) 7.1 s (0%) 1.8 s (+17.29% 🔺) 8.8 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 211 ms (+1613.71% 🔺) 325 ms
thirdweb/chains (tree-shaking) 530 B (0%) 11 ms (0%) 74 ms (+1124.03% 🔺) 84 ms
thirdweb/react (minimal + tree-shaking) 19.59 KB (0%) 392 ms (0%) 183 ms (+616.89% 🔺) 575 ms

Copy link

codecov bot commented Jul 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.96%. Comparing base (85c4ef1) to head (3fdb5be).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7502      +/-   ##
==========================================
+ Coverage   51.93%   51.96%   +0.03%     
==========================================
  Files         950      952       +2     
  Lines       64163    64224      +61     
  Branches     4229     4237       +8     
==========================================
+ Hits        33326    33377      +51     
- Misses      30731    30740       +9     
- Partials      106      107       +1     
Flag Coverage Δ
packages 51.96% <ø> (+0.03%) ⬆️

see 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE This pull request is still in progress and is not ready to be merged. packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant