Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions packages/thirdweb/src/cli/commands/stylus/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,37 @@ export async function createStylusProject() {
choices: [
{ title: "Default", value: "default" },
{ title: "ERC20", value: "erc20" },
{ title: "ERC721", value: "erc721" },
],
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.

if (projectType === "default") {
spinner.start(`Creating new Stylus project: ${projectName}...`);
const newProject = spawnSync("cargo", ["stylus", "new", projectName], {
newProject = spawnSync("cargo", ["stylus", "new", projectName], {
stdio: "inherit",
});
if (newProject.status !== 0) {
spinner.fail("Failed to create Stylus project.");
process.exit(1);
}
} else if (projectType === "erc20") {
const repoUrl = "[email protected]:thirdweb-example/stylus-erc20-template.git";
spinner.start(`Creating new ERC20 Stylus project: ${projectName}...`);
const clone = spawnSync("git", ["clone", repoUrl, projectName], {
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
if (clone.status !== 0) {
spinner.fail("Failed to create Stylus project.");
process.exit(1);
}
} else if (projectType === "erc721") {
const repoUrl = "[email protected]:thirdweb-example/stylus-erc721-template.git";
spinner.start(`Creating new ERC721 Stylus project: ${projectName}...`);
newProject = spawnSync("git", ["clone", repoUrl, projectName], {
stdio: "inherit",
});
}

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.


spinner.succeed("Project created successfully.");
Expand Down
Loading