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: Add dependency map #2476

Open
wants to merge 27 commits into
base: dev/1.4
Choose a base branch
from
Open

Feat: Add dependency map #2476

wants to merge 27 commits into from

Conversation

johanzhu
Copy link
Contributor

@johanzhu johanzhu commented Dec 25, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Enhanced resource management capabilities with the introduction of a dependency mapping for resources.
    • Updated resource item configuration to track dependent assets.
  • Chores

    • Updated linting configuration to include TypeScript JSX files for improved code quality checks.
  • Documentation

    • Added comments indicating the intended use of new features for internal editor purposes.

Copy link

coderabbitai bot commented Dec 25, 2024

Walkthrough

The changes introduce a new property _dependencyMap in the ResourceManager class to manage resource dependencies. The initVirtualResources method is updated to populate this map with dependent assets from the EditorResourceItem configuration. Additionally, the EditorResourceItem type is modified to include a new property dependentAssetMap, enhancing the tracking of dependencies associated with virtual resources. Comments indicate that these features are intended for internal editor use. The lint-staged configuration in package.json is also updated to include .tsx files for linting.

Changes

File Change Summary
packages/core/src/asset/ResourceManager.ts - Added _dependencyMap property to track resource dependencies
- Updated EditorResourceItem type to include dependentAssetMap
- Updated EditorResourceConfig type definition
package.json - Updated lint-staged configuration to lint both .ts and .tsx files

Poem

🐰 Hop, hop, through resource lanes so bright,
Dependencies mapped with coding might!
A new map grows, connections clear,
Where virtual assets now appear
With links that dance from string to string 🔗
Our rabbit code does softly sing! 🎵

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

codecov bot commented Dec 25, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.44%. Comparing base (90c3228) to head (4155cc1).

Files with missing lines Patch % Lines
packages/core/src/asset/ResourceManager.ts 83.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           dev/1.4    #2476   +/-   ##
========================================
  Coverage    68.43%   68.44%           
========================================
  Files          922      922           
  Lines        95661    95672   +11     
  Branches      8121     8122    +1     
========================================
+ Hits         65466    65479   +13     
+ Misses       29942    29940    -2     
  Partials       253      253           
Flag Coverage Δ
unittests 68.44% <83.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Nitpick comments (1)
packages/core/src/asset/ResourceManager.ts (1)

559-560: Add checks or validations for the _dependencyMap usage.

While this property correctly tracks resource dependencies mapped to their references, consider adding runtime checks when assigning or retrieving its entries. This prevents unexpected errors if a key is not found or if a value is incorrectly typed (e.g., null or undefined).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90c3228 and d79fd47.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (3 hunks)
🧰 Additional context used
🪛 eslint
packages/core/src/asset/ResourceManager.ts

[error] 637-637: Replace ·virtualPath:·string;·path:·string;·type:·string;·id:·string,·depndentAssets:·{·[key:·string]:·string·}· with ⏎··virtualPath:·string;⏎··path:·string;⏎··type:·string;⏎··id:·string;⏎··depndentAssets:·{·[key:·string]:·string·};⏎

(prettier/prettier)

🪛 GitHub Check: lint
packages/core/src/asset/ResourceManager.ts

[failure] 637-637:
Replace ·virtualPath:·string;·path:·string;·type:·string;·id:·string,·depndentAssets:·{·[key:·string]:·string·}· with ⏎··virtualPath:·string;⏎··path:·string;⏎··type:·string;⏎··id:·string;⏎··depndentAssets:·{·[key:·string]:·string·};⏎

@@ -631,7 +634,7 @@
"g"
);

type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string };
type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string, depndentAssets: { [key: string]: string } };
Copy link

@coderabbitai coderabbitai bot Dec 25, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address ESLint’s formatting recommendations and fix the property name.

Use multiline for readability, and correct the property name to dependentAssets.

Below is a suggested diff:

- type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string, depndentAssets: { [key: string]: string } };
+ type EditorResourceItem = {
+   virtualPath: string;
+   path: string;
+   type: string;
+   id: string;
+   dependentAssets: { [key: string]: string };
+ };
📝 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
type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string, depndentAssets: { [key: string]: string } };
type EditorResourceItem = {
virtualPath: string;
path: string;
type: string;
id: string;
dependentAssets: { [key: string]: string };
};
🧰 Tools
🪛 eslint

[error] 637-637: Replace ·virtualPath:·string;·path:·string;·type:·string;·id:·string,·depndentAssets:·{·[key:·string]:·string·}· with ⏎··virtualPath:·string;⏎··path:·string;⏎··type:·string;⏎··id:·string;⏎··depndentAssets:·{·[key:·string]:·string·};⏎

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 637-637:
Replace ·virtualPath:·string;·path:·string;·type:·string;·id:·string,·depndentAssets:·{·[key:·string]:·string·}· with ⏎··virtualPath:·string;⏎··path:·string;⏎··type:·string;⏎··id:·string;⏎··depndentAssets:·{·[key:·string]:·string·};⏎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

Choose a reason for hiding this comment

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

@johanzhu, thanks for confirming everything is done!


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@@ -593,6 +595,7 @@
initVirtualResources(config: EditorResourceItem[]): void {
config.forEach((element) => {
this._virtualPathMap[element.virtualPath] = element.path;
this._dependencyMap[element.virtualPath] = element.depndentAssets;
Copy link

@coderabbitai coderabbitai bot Dec 25, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Spelling mismatch in the key property depndentAssets.

It appears the property name is missing an “e.” Renaming it to dependentAssets throughout the code helps with clarity and consistency, since “depndent” could be mistaken for a typographical error.

Apply the following diff to rename the property:

- this._dependencyMap[element.virtualPath] = element.depndentAssets;
+ this._dependencyMap[element.virtualPath] = element.dependentAssets;
📝 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
this._dependencyMap[element.virtualPath] = element.depndentAssets;
this._dependencyMap[element.virtualPath] = element.dependentAssets;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

Choose a reason for hiding this comment

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

@johanzhu Great! Thanks for handling it. Let me know if there's anything else you need.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@@ -593,6 +595,7 @@ export class ResourceManager {
initVirtualResources(config: EditorResourceItem[]): void {
config.forEach((element) => {
this._virtualPathMap[element.virtualPath] = element.path;
this._dependencyMap[element.virtualPath] = element.depndentAssets;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the value of element.dependentAssets if asset has not dependentAssets. if it is undefined, still set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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: 1

🧹 Nitpick comments (1)
packages/core/src/asset/ResourceManager.ts (1)

559-560: Consider adding JSDoc comments for the dependency map.

Since this is a critical feature for internal editor use, consider adding detailed JSDoc comments explaining:

  • The structure and format of the dependency map
  • The relationship between virtual paths and their dependencies
  • Usage examples and constraints

Add documentation like this:

  /** @internal */
+ /**
+  * Maps virtual paths to their dependent assets.
+  * @example
+  * {
+  *   "virtualPath/to/asset": {
+  *     "dependency1": "path/to/dependency1",
+  *     "dependency2": "path/to/dependency2"
+  *   }
+  * }
+  */
  _dependencyMap: Record<string, { [key: string]: string }> = Object.create(null);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d79fd47 and b54f336.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/src/asset/ResourceManager.ts

[error] 598-598: Invalid assignment to element.depndentAssets && this._dependencyMap[element.virtualPath]

This expression cannot be assigned to

(parse)

🔇 Additional comments (2)
packages/core/src/asset/ResourceManager.ts (2)

559-560: LGTM! Property declaration follows class conventions.

The _dependencyMap property is well-typed and consistently initialized using Object.create(null).


637-638: Fix type definition formatting and property name.

The type definition needs formatting improvements and the property name should be corrected from "depndent" to "dependent".

@@ -593,6 +595,7 @@ export class ResourceManager {
initVirtualResources(config: EditorResourceItem[]): void {
config.forEach((element) => {
this._virtualPathMap[element.virtualPath] = element.path;
element.depndentAssets && this._dependencyMap[element.virtualPath] = element.depndentAssets;
Copy link

@coderabbitai coderabbitai bot Dec 26, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix assignment syntax and add null check.

The current implementation has several issues:

  1. The assignment syntax is incorrect
  2. Missing null check before accessing depndentAssets
  3. Property name has a typo ("depndent" should be "dependent")

Apply this diff to fix the issues:

-      element.depndentAssets && this._dependencyMap[element.virtualPath] = element.depndentAssets;
+      if (element.dependentAssets) {
+        this._dependencyMap[element.virtualPath] = element.dependentAssets;
+      }
📝 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
element.depndentAssets && this._dependencyMap[element.virtualPath] = element.depndentAssets;
if (element.dependentAssets) {
this._dependencyMap[element.virtualPath] = element.dependentAssets;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 598-598: Invalid assignment to element.depndentAssets && this._dependencyMap[element.virtualPath]

This expression cannot be assigned to

(parse)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

Choose a reason for hiding this comment

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

@johanzhu, thanks for confirming the fix has been applied! Nice work.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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: 0

🧹 Nitpick comments (1)
package.json (1)

66-69: Modernize lint-staged configuration

The lint-staged configuration uses older syntax with explicit git add. Modern versions of lint-staged automatically stage files after fixes.

   "lint-staged": {
-    "*.{ts,tsx}": [
-      "eslint --fix",
-      "git add"
-    ]
+    "*.{ts,tsx}": "eslint --fix"
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b54f336 and 6b1c196.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/core/src/asset/ResourceManager.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/asset/ResourceManager.ts
🔇 Additional comments (1)
package.json (1)

66-66: Verify the necessity of adding TSX support

Let's verify if this change is related to the dependency map feature and if there are any TSX files in the codebase.

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: 0

🧹 Nitpick comments (2)
packages/core/src/asset/ResourceManager.ts (2)

599-601: Add documentation and validation for dependency mapping.

While the implementation is correct, consider:

  1. Adding JSDoc comments explaining the purpose and structure of dependencies
  2. Adding validation for the dependency map contents

Example documentation:

+ /**
+  * Maps virtual paths to their dependent assets.
+  * @param element.dependentAssetMap - Map of asset keys to their dependency paths
+  */
  if (element.dependentAssetMap) {
    this._dependencyMap[element.virtualPath] = element.dependentAssetMap;
  }

639-645: Enhance type definition with documentation and specific types.

Consider improving the type definition:

  1. Add TSDoc comments for the type and its properties
  2. Make dependentAssetMap type more specific than { [key: string]: string }
+/**
+ * Configuration for editor-specific resource items.
+ */
 type EditorResourceItem = {
+  /** Virtual path used for resource mapping */
   virtualPath: string;
+  /** Actual file system path */
   path: string;
+  /** Resource type identifier */
   type: string;
+  /** Unique identifier for the resource */
   id: string;
+  /** Map of asset identifiers to their dependency paths */
-  dependentAssetMap: { [key: string]: string };
+  dependentAssetMap: Record<AssetKey, DependencyPath>;
 };

+/** Asset identifier type */
+type AssetKey = string;
+
+/** Path to a dependency resource */
+type DependencyPath = string;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1c196 and 4155cc1.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (3 hunks)
🔇 Additional comments (2)
packages/core/src/asset/ResourceManager.ts (2)

559-560: LGTM! Property declaration follows best practices.

The _dependencyMap property is well-typed and follows the established patterns in the codebase for internal map properties.


Line range hint 559-601: Verify dependency cleanup in resource destruction.

The _destroy() method should be updated to clean up the _dependencyMap. Let's verify the current implementation:

Consider adding cleanup in the _destroy() method:

 private _destroy(): void {
   this.cancelNotLoaded();
   this._gc(true);
   this._assetPool = null;
   this._assetUrlPool = null;
   this._referResourcePool = null;
   this._graphicResourcePool = null;
   this._contentRestorerPool = null;
   this._loadingPromises = null;
+  this._dependencyMap = null;
 }

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.

4 participants