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

fix: create-dojo + update manifest path #338

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Nov 25, 2024

Fixes create-dojo start command with providing correct path to manifest

Summary by CodeRabbit

  • New Features

    • Updated the application to use a release manifest for configuration, enhancing stability.
    • Introduced a new function to ensure proper configuration file paths during project initialization.
  • Bug Fixes

    • Improved error handling for configuration updates, providing better feedback on potential issues.
  • Refactor

    • Changed import paths for better clarity and organization in the codebase.
    • Streamlined project setup by removing unnecessary cloning steps and adjusting directory structures.

Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

This pull request includes modifications to several files, primarily focusing on updating import paths and restructuring the project initialization process. The dojoConfig.ts file's manifest import path has been changed to point to a release manifest. Additionally, the main.tsx file's import path for the dojoConfig module has been updated from an absolute to a relative path. The start.ts file has undergone significant changes, including the renaming of variables, removal of the dojo-starter cloning process, and the introduction of a new function to rewrite configuration file paths.

Changes

File Path Change Summary
examples/example-vite-kitchen-sink/dojoConfig.ts Updated import path for manifest from ../../worlds/dojo-starter/manifest_dev.json to ../../worlds/onchain-dash/manifests/release/deployment/manifest.json.
examples/example-vite-kitchen-sink/src/main.tsx Changed import path for dojoConfig from @/dojo.config to ../dojoConfig.
packages/create-dojo/src/commands/start.ts Renamed dojoStarterPath to contractPath, removed dojo-starter directory creation, added rewriteDojoConfigFile function for updating import paths.

Possibly related PRs

  • fix: docs and example #231: The changes in the main PR involve updating import paths for the manifest variable, which may relate to the documentation and example updates in this PR.
  • feat: subscription clauses #235: The modifications in the main PR regarding the dojoConfig and init function could be relevant to the changes in entity handling and synchronization introduced in this PR.
  • fix: submodule #272: The changes in the main PR regarding the import paths for the manifest variable may connect with the updates to the CI workflow and submodule paths in this PR.
  • feat: add kitchen sink example #281: The introduction of a new kitchen sink example in this PR may relate to the changes in the dojoConfig and manifest paths in the main PR.
  • fix: paths #311: The changes in the main PR regarding the import paths for the manifest variable are directly related to the path fixes addressed in this PR.
  • feat: fix for create-dojo cli #312: The modifications in the main PR regarding the dojoConfig could be relevant to the CLI fixes introduced in this PR.

Suggested reviewers

  • ponderingdemocritus

🐇 In the code, I hop and play,
Changing paths in a clever way.
From dojo-starter to onchain-dash,
Configs updated in a flash!
With each new line, I make it right,
Hopping through code, what a delight! 🌟


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

@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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3c442a6 and ca7ed9c.

📒 Files selected for processing (3)
  • examples/example-vite-kitchen-sink/dojoConfig.ts (1 hunks)
  • examples/example-vite-kitchen-sink/src/main.tsx (1 hunks)
  • packages/create-dojo/src/commands/start.ts (3 hunks)
🔇 Additional comments (6)
examples/example-vite-kitchen-sink/dojoConfig.ts (1)

Line range hint 5-7: LGTM: Configuration setup looks correct

The usage of createDojoConfig with the manifest looks correct.

examples/example-vite-kitchen-sink/src/main.tsx (1)

12-12: Verify the dojoConfig path resolution

The import path has been changed from an alias-based import to a relative import. Let's verify that the new path correctly resolves to the config file.

✅ Verification successful

Import path resolution is correct

The verification confirms that:

  • The dojoConfig.ts file exists at the expected location: examples/example-vite-kitchen-sink/dojoConfig.ts
  • The relative import path "../dojoConfig" in main.tsx correctly resolves to this file
  • No other files in the project are importing dojoConfig differently
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and location of dojoConfig file
# Expected: Find the config file in examples/example-vite-kitchen-sink/dojoConfig.ts

# Check if the file exists at the expected location
fd -e ts -e js "dojoConfig" examples/example-vite-kitchen-sink/

# Verify any other files that might be importing dojoConfig to ensure consistency
rg "from.*dojoConfig" examples/example-vite-kitchen-sink/

Length of output: 264

packages/create-dojo/src/commands/start.ts (4)

47-47: Definition of contractPath is correct

The contractPath is appropriately defined as a subdirectory of projectPath, pointing to the "contract" directory.


52-52: Creation of contractPath directory

Using fs.mkdir with { recursive: true } ensures that the "contract" directory is created successfully, even if parent directories do not exist.


69-70: Invocation of rewriteDojoConfigFile function

The call to await rewriteDojoConfigFile(clientPath); correctly introduces the function to update import paths in dojoConfig.ts, aligning with the new directory structure.


121-124: Verify that the regular expression correctly updates import paths

Ensure that the regular expression accurately matches all relevant import statements and that the replacement string points to the correct manifest file in the new directory structure.

Run the following script to confirm all import paths have been updated:

✅ Verification successful

Let me gather more information about the context where this replacement is being used.


Let me try a different approach to understand the context of this file modification.


Based on the context gathered, I can now provide the final response:

The regular expression correctly handles manifest import path updates

The regex /from ['"]\.{0,2}\/.*manifest(?:_dev)?\.json['"]/g is correctly implemented to:

  • Match imports using both single/double quotes
  • Handle relative paths with optional ./ or ../
  • Match both manifest.json and manifest_dev.json
  • Replace with the standardized path ../contract/target/dev/manifest.json

This is used in the rewriteDojoConfigFile function which updates the import paths when initializing new projects from templates, ensuring consistent manifest file references across all new projects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for manifest import statements in dojoConfig.ts files

rg "from ['\"]\.{0,2}/.*manifest(?:_dev)?\.json['\"]" -g "**/dojoConfig.ts" -A 2

Length of output: 2805


Script:

#!/bin/bash
# Search for the file content where the regex replacement is being used
rg -l "content\.replace\(.*manifest(?:_dev)?\.json" 

# Also check the surrounding context of where this replacement is happening
rg -B 5 -A 5 "content\.replace\(.*manifest(?:_dev)?\.json"

Length of output: 114


Script:

#!/bin/bash
# Let's look at the content of the start.ts file to understand the context
cat packages/create-dojo/src/commands/start.ts

# Also search for any dojoConfig.ts files in the template directory
fd dojoConfig.ts packages/create-dojo/

Length of output: 7102

@@ -1,6 +1,6 @@
import { createDojoConfig } from "@dojoengine/core";

import manifest from "../../worlds/dojo-starter/manifest_dev.json";
import manifest from "../../worlds/onchain-dash/manifests/release/deployment/manifest.json";
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Manifest path is incorrect and inconsistent with other examples

The verification reveals critical issues:

  • The specified manifest path worlds/onchain-dash/manifests/release/deployment/manifest.json does not exist
  • All other example projects consistently use worlds/dojo-starter/manifest_dev.json
  • Only the kitchen-sink example deviates with two files referencing the non-existent path:
    • examples/example-vite-kitchen-sink/dojoConfig.ts
    • examples/example-vite-kitchen-sink/src/dojo.config.ts

The change should be reverted to use the same development manifest as other examples (worlds/dojo-starter/manifest_dev.json) to maintain consistency and ensure the example works out of the box.

🔗 Analysis chain

Verify the manifest path exists and is accessible

The manifest path has been changed to point to a release manifest in the onchain-dash project. Let's verify this path exists and is consistent across the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the manifest path exists and check for other manifest references

# Check if the manifest file exists
if [ -f "worlds/onchain-dash/manifests/release/deployment/manifest.json" ]; then
    echo "✓ Manifest file exists"
else
    echo "✗ Manifest file not found"
fi

# Search for other manifest references to ensure consistency
echo "Checking other manifest references:"
rg -g '!*.json' "manifest.*\.json" 

Length of output: 1925


🛠️ Refactor suggestion

Consider making the manifest path configurable

The hardcoded relative path to the manifest file might be problematic:

  1. It assumes a specific directory structure
  2. It's using a release manifest for what appears to be a development/example setup
  3. The relative path (../../) could break if the file structure changes

Consider making the manifest path configurable through environment variables:

-import manifest from "../../worlds/onchain-dash/manifests/release/deployment/manifest.json";
+import manifest from process.env.DOJO_MANIFEST_PATH || "../../worlds/onchain-dash/manifests/release/deployment/manifest.json";

This would allow developers to:

  • Override the manifest path for local development
  • Use different manifests for different environments
  • Avoid breaking changes if the directory structure changes

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

@@ -9,7 +9,7 @@ import "./app/globals.css";
import { init } from "@dojoengine/sdk";
import { OnchainDashSchemaType, schema } from "@/dojo/models";
import { env, getRpcUrl } from "@/env";
import { dojoConfig } from "@/dojo.config";
import { dojoConfig } from "../dojoConfig";
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Path alias change is inconsistent with project configuration

The change from @/dojo.config to ../dojoConfig should be reverted as the project explicitly configures the @ path alias in both:

  • tsconfig.json with "@/*": ["./src/*"]
  • vite.config.ts with a corresponding Vite alias configuration

Additionally, there are 42 other imports using the @ alias pattern throughout the codebase, making this change inconsistent with the project's established path resolution strategy.

🔗 Analysis chain

Review build configuration for path alias changes

The change from @/dojo.config to ../dojoConfig removes usage of the @ path alias. Ensure that this change is intentional and consistent with the project's build configuration (tsconfig.json/vite.config.ts).


Let me check the build configuration files to complete the verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check build configurations for path alias definitions
# Expected: Confirm if @ alias should be removed or maintained

# Check TypeScript config
fd -e json "tsconfig" examples/example-vite-kitchen-sink/

# Check Vite config
fd -e ts -e js "vite.config" examples/example-vite-kitchen-sink/

# Look for other @ alias usages that might need similar updates
rg "from\s+['\"]@/" examples/example-vite-kitchen-sink/src/

Length of output: 5355


Script:

#!/bin/bash
# Check the content of TypeScript and Vite configs
cat examples/example-vite-kitchen-sink/tsconfig.json
cat examples/example-vite-kitchen-sink/vite.config.ts

Length of output: 1225

Copy link

@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

Reviewing files that changed from the base of the PR and between ca7ed9c and 428cfaf.

📒 Files selected for processing (3)
  • examples/example-vite-kitchen-sink/dojoConfig.ts (1 hunks)
  • examples/example-vite-kitchen-sink/src/main.tsx (1 hunks)
  • packages/create-dojo/src/commands/start.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/example-vite-kitchen-sink/dojoConfig.ts
  • examples/example-vite-kitchen-sink/src/main.tsx
🔇 Additional comments (2)
packages/create-dojo/src/commands/start.ts (2)

47-47: LGTM: Improved directory structure

The separation into client and contract directories provides a clearer project structure.

Also applies to: 52-52


69-70: LGTM: Config update properly sequenced

The config rewrite is correctly placed after template cloning to ensure proper path updates.

Comment on lines +74 to +83
const contractRes = spawn.sync(
"npx",
["degit", `dojoengine/dojo-starter`, contractPath],
{
stdio: "inherit",
}
);
if (contractRes.status !== 0) {
throw new Error(`Failed to clone template: ${template}`);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect error message in contract download

The error message still references the template variable when failing to clone the dojo-starter repository.

Apply this fix:

    if (contractRes.status !== 0) {
-       throw new Error(`Failed to clone template: ${template}`);
+       throw new Error('Failed to clone dojo-starter repository');
    }
📝 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
const contractRes = spawn.sync(
"npx",
["degit", `dojoengine/dojo-starter`, contractPath],
{
stdio: "inherit",
}
);
if (contractRes.status !== 0) {
throw new Error(`Failed to clone template: ${template}`);
}
const contractRes = spawn.sync(
"npx",
["degit", `dojoengine/dojo-starter`, contractPath],
{
stdio: "inherit",
}
);
if (contractRes.status !== 0) {
throw new Error('Failed to clone dojo-starter repository');
}

Comment on lines +114 to +131
async function rewriteDojoConfigFile(clientPath: string) {
const dojoConfigPath = path.join(clientPath, "dojoConfig.ts");

try {
let content = await fs.readFile(dojoConfigPath, "utf-8");

// Update relative imports to account for new directory structure
content = content.replace(
/from ['"]\.{0,2}\/.*manifest(?:_dev)?\.json['"]/g,
'from "../contract/target/dev/manifest.json"'
);

await fs.writeFile(dojoConfigPath, content, "utf-8");
} catch (error) {
console.warn(`Warning: Could not update dojoConfig.ts: ${error}`);
}
}

Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Revise manifest path handling in rewriteDojoConfigFile

The current implementation needs adjustment based on the examples:

  1. The target path "../contract/target/dev/manifest.json" is incorrect. Examples show two common patterns:

    • Most examples use: "../../worlds/dojo-starter/manifest_dev.json"
    • Kitchen sink uses: "../../worlds/onchain-dash/manifests/release/deployment/manifest.json"
  2. The regex pattern should be more specific but flexible enough to handle both patterns.

 async function rewriteDojoConfigFile(clientPath: string) {
     const dojoConfigPath = path.join(clientPath, "dojoConfig.ts");
+    const manifestPath = "../../worlds/dojo-starter/manifest_dev.json";
 
     try {
         let content = await fs.readFile(dojoConfigPath, "utf-8");
 
         content = content.replace(
-            /from ['"]\.{0,2}\/.*manifest(?:_dev)?\.json['"]/g,
-            'from "../contract/target/dev/manifest.json"'
+            /from ['"](?:\.{1,2}\/)+(?:worlds|contract)\/.*?manifest(?:_dev)?\.json['"]/g,
+            `from "${manifestPath}"`
         );
 
         await fs.writeFile(dojoConfigPath, content, "utf-8");
     } catch (error) {
         throw new Error(
             `Failed to update manifest path in dojoConfig.ts: ${error}. ` +
             `Please ensure the file exists and contains a manifest import.`
         );
     }
 }
🔗 Analysis chain

Enhance robustness of config file rewriting

Several improvements could make this function more reliable:

  1. The regex pattern could be more specific to avoid unintended matches
  2. The hardcoded path assumes a specific structure
  3. Error handling should be more robust for a critical setup step

Consider this enhanced implementation:

 async function rewriteDojoConfigFile(clientPath: string) {
     const dojoConfigPath = path.join(clientPath, "dojoConfig.ts");
+    const manifestPath = "../contract/target/dev/manifest.json";
 
     try {
         let content = await fs.readFile(dojoConfigPath, "utf-8");
 
-        // Update relative imports to account for new directory structure
         content = content.replace(
-            /from ['"]\.{0,2}\/.*manifest(?:_dev)?\.json['"]/g,
-            'from "../contract/target/dev/manifest.json"'
+            /from ['"](\.{0,2}\/[^"']*?manifest(?:_dev)?\.json)['"]/g,
+            `from "${manifestPath}"`
         );
 
         await fs.writeFile(dojoConfigPath, content, "utf-8");
     } catch (error) {
-        console.warn(`Warning: Could not update dojoConfig.ts: ${error}`);
+        throw new Error(
+            `Failed to update manifest path in dojoConfig.ts: ${error}. ` +
+            `Please ensure the file exists and contains a manifest import.`
+        );
     }
 }

Let's verify the manifest path structure:


This will help us verify the actual import paths used in the examples to ensure our regex and target path assumptions are correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the manifest path structure is consistent across templates
for template in $(fd -t d -d 1 . examples/ | grep 'example-'); do
  rg -l "manifest(_dev)?\.json" "$template"
done

Length of output: 1956


Script:

#!/bin/bash
# Check the actual manifest import paths in dojoConfig files
for config in $(rg -l "manifest(_dev)?\.json" examples/); do
  echo "=== $config ==="
  rg -A 1 -B 1 "from ['\"].*manifest(_dev)?\.json['\"]" "$config"
done

Length of output: 4433

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.

1 participant