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: import sibling packages without building #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Nesopie
Copy link
Collaborator

@Nesopie Nesopie commented Jul 23, 2024

  • Fixes the issue where you have to build packages before being able to import them
  • Updated exports in package.json
  • Updated vite config to use package aliases in tests

Summary by CodeRabbit

  • New Features

    • Introduced new entry points for the gardening and order book modules, enhancing accessibility to key functionalities.
    • Added utility functions for secure blockchain interactions and improved order management features.
  • Improvements

    • Streamlined type definition paths for easier access and clarity.
    • Modified configuration to support improved module resolution and compilation processes.
  • Bug Fixes

    • Enhanced error handling for wallet checks, improving compatibility with different wallet implementations.
  • Documentation

    • Updated TypeScript configurations to reflect changes in module structure and paths for better organization.

Copy link

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent changes enhance the modularity and organization of a gardening and order book application. Key updates include streamlined TypeScript configurations, a new entry point for the order book module, and the introduction of utility functions for blockchain interactions. These adjustments simplify import paths, improve error handling, and consolidate functionalities, ensuring a clearer structure for developers while enabling better integration of components.

Changes

File Path Change Summary
packages/core/index.ts New entry point for exporting modules related to gardening, including GardenJS, SwapperActions, and catalogWalletActions.
packages/core/package.json Updated typings and types paths to ./dist/index.d.ts, simplifying type definition access.
packages/core/src/garden.ts Removed reference to AbstractBitcoinWallet, simplifying error handling for Bitcoin wallet logic.
packages/core/src/utils.ts Introduced computeSecret and isFromChainBitcoin functions for blockchain interactions.
packages/core/tsconfig.json Removed include and exclude properties, affecting TypeScript compilation of files.
packages/core/tsconfig.lib.json Added index.ts to include, ensuring it's part of the compilation; expanded exclude for better file management.
packages/core/tsconfig.spec.json Expanded include section to include all TypeScript files in src and index.ts.
packages/core/vite.config.ts Updated cacheDir, entry point, and added tsconfigPath for better build configuration and module resolution.
packages/orderbook/index.ts New entry point exporting core functionalities such as Orderbook, and associated types and utilities.
packages/orderbook/package.json Updated typings and types paths for type definitions to ./dist/index.d.ts.
packages/orderbook/tsconfig.json Cleaned up configuration by removing include, retaining files and exclude, maintaining build clarity.
packages/orderbook/tsconfig.lib.json Added index.ts to include for the orderbook package, ensuring comprehensive compilation.
packages/orderbook/vite.config.ts Modified library build settings with new tsconfigPath and changed entry point to index.ts, improving module resolution.
tsconfig.json Updated paths from gardenfi/* to @gardenfi/* and added baseUrl for improved module resolution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ViteConfig
    participant TypeScript
    participant GardenJS

    User->>ViteConfig: Initiate build
    ViteConfig->>TypeScript: Compile files
    TypeScript->>GardenJS: Resolve imports
    GardenJS-->>TypeScript: Return compiled output
    ViteConfig-->>User: Provide build artifacts
Loading

🐰 In the garden, where flowers bloom,
A new path emerged, dispelling the gloom.
With modules restructured, oh what a delight,
The code hops freely, taking flight!
In unity's dance, let us rejoice,
For clearer imports, we all have a voice! 🌼✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 44529a6 and 96a337a.

Files selected for processing (14)
  • packages/core/index.ts (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/garden.ts (3 hunks)
  • packages/core/src/utils.ts (1 hunks)
  • packages/core/tsconfig.json (1 hunks)
  • packages/core/tsconfig.lib.json (1 hunks)
  • packages/core/tsconfig.spec.json (1 hunks)
  • packages/core/vite.config.ts (2 hunks)
  • packages/orderbook/index.ts (1 hunks)
  • packages/orderbook/package.json (1 hunks)
  • packages/orderbook/tsconfig.json (1 hunks)
  • packages/orderbook/tsconfig.lib.json (1 hunks)
  • packages/orderbook/vite.config.ts (2 hunks)
  • tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (4)
  • packages/core/package.json
  • packages/orderbook/package.json
  • packages/orderbook/tsconfig.json
  • packages/orderbook/tsconfig.lib.json
Additional comments not posted (26)
packages/core/index.ts (1)

1-3: Ensure the correctness of export paths.

Verify that the paths ./src/garden, ./src/swapper, and ./src/catalogActions are correct and that the exported entities GardenJS, SwapperActions, SwapperRole, and catalogWalletActions exist in these modules.

Verification successful

Export paths and entities verified successfully.

The paths and entities exported in packages/core/index.ts are correct and exist in their respective source files:

  • GardenJS is defined in packages/core/src/garden.ts.
  • SwapperActions and SwapperRole are defined in packages/core/src/swapper.ts.
  • catalogWalletActions is defined in packages/core/src/catalogActions.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the exported entities in the specified modules.

# Test: Check if the modules and exported entities exist.
rg --type ts 'export\s+\{[^}]*\b(GardenJS|SwapperActions|SwapperRole|catalogWalletActions)\b[^}]*\}' src/garden.ts src/swapper.ts src/catalogActions.ts

Length of output: 324


Script:

#!/bin/bash
# Description: Search for the export statements of the entities across the entire codebase.

# Search for the export statement of GardenJS
rg --type ts 'export\s+\{[^}]*\bGardenJS\b[^}]*\}' -A 5

# Search for the export statement of SwapperActions
rg --type ts 'export\s+\{[^}]*\bSwapperActions\b[^}]*\}' -A 5

# Search for the export statement of SwapperRole
rg --type ts 'export\s+\{[^}]*\bSwapperRole\b[^}]*\}' -A 5

# Search for the export statement of catalogWalletActions
rg --type ts 'export\s+\{[^}]*\bcatalogWalletActions\b[^}]*\}' -A 5

Length of output: 904


Script:

#!/bin/bash
# Description: Verify the existence of the entities in their respective source files.

# Search for the definition of GardenJS in the garden module
rg --type ts 'GardenJS' packages/core/src/garden.ts

# Search for the definition of SwapperActions in the swapper module
rg --type ts 'SwapperActions' packages/core/src/swapper.ts

# Search for the definition of SwapperRole in the swapper module
rg --type ts 'SwapperRole' packages/core/src/swapper.ts

# Search for the definition of catalogWalletActions in the catalogActions module
rg --type ts 'catalogWalletActions' packages/core/src/catalogActions.ts

Length of output: 1913

packages/core/tsconfig.spec.json (1)

9-10: Ensure the correctness of the include paths.

Verify that the paths src/**/*.ts and index.ts are correctly included and necessary for the testing setup.

Verification successful

The include paths in tsconfig.spec.json are correct and necessary for the testing setup.

  • The src/**/*.ts path correctly includes TypeScript files in the src/ directory and its subdirectories.
  • The index.ts file exists in the root directory of the packages/core package, confirming its necessity.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the included paths for the testing setup.

# Test: Check if the paths exist and are necessary for the testing setup.
fd --type f --extension ts src/ | grep -E 'src/.*\.ts|index\.ts'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify the existence of the included paths for the testing setup.

# Check if there are any TypeScript files in the src directory and its subdirectories
echo "Checking for TypeScript files in src directory..."
fd --type f --extension ts src/

# Check if index.ts exists in the root directory
echo "Checking for index.ts in the root directory..."
fd --type f --extension ts index.ts

Length of output: 406

packages/core/tsconfig.lib.json (2)

8-8: Ensure the correctness of the include paths.

Verify that the paths src/**/*.ts and index.ts are correctly included and necessary for the library setup.

Verification successful

The include paths in tsconfig.lib.json are correctly specified and necessary for the library setup. The paths src/**/*.ts and index.ts exist within the repository and are valid.

  • src/**/*.ts: There are TypeScript files in the src directories.
  • index.ts: The file exists in multiple locations, including packages/core/index.ts, which is relevant for the packages/core directory.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the included paths for the library setup.

# Test: Check if the paths exist and are necessary for the library setup.
fd --type f --extension ts src/ | grep -E 'src/.*\.ts|index\.ts'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify the existence of the included paths for the library setup.

# Check if there are any TypeScript files in the src directory and its subdirectories
fd --type f --extension ts src/

# Check if index.ts exists in the root directory
fd --type f --extension ts index.ts

Length of output: 194


10-14: Ensure the correctness of the exclude paths.

Verify that the paths jest.config.ts, src/**/*.spec.ts, src/**/*.test.ts, and src/lib/testUtils.ts are correctly excluded and unnecessary for the library setup.

Verification successful

The exclude paths are correct and do not include any unnecessary files for the library setup.

  • The paths jest.config.ts, src/**/*.spec.ts, src/**/*.test.ts, and src/lib/testUtils.ts are correctly excluded.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the excluded paths for the library setup.

# Test: Check if the paths exist and are unnecessary for the library setup.
fd --type f --extension ts | grep -E 'jest\.config\.ts|src/.*\.spec\.ts|src/.*\.test\.ts|src/lib/testUtils\.ts'

Length of output: 390


Script:

#!/bin/bash
# Check if jest.config.ts exists
fd --type f --name 'jest.config.ts'

# Check if any .test.ts files exist
fd --type f --extension ts | grep -E 'src/.*\.test\.ts'

# Check if src/lib/testUtils.ts exists
fd --type f --name 'testUtils.ts' | grep -E 'src/lib/testUtils\.ts'

Length of output: 663


Script:

#!/bin/bash
# Check if jest.config.ts exists
fd --type f 'jest.config.ts'

# Check if any .test.ts files exist
fd --type f --extension ts | grep -E 'src/.*\.test\.ts'

# Check if src/lib/testUtils.ts exists
fd --type f 'src/lib/testUtils.ts'

Length of output: 121

tsconfig.json (2)

8-8: LGTM! The baseUrl property addition enhances module resolution.

The baseUrl property is correctly set to ".", improving the flexibility of imports throughout the project.


10-10: LGTM! The paths modification improves module organization.

The change to scoped package names (@gardenfi/*) enhances the clarity and organization of module imports.

packages/orderbook/index.ts (1)

1-12: LGTM! The export statements are well-organized.

The file follows best practices for module exports, enhancing the modularity and usability of the orderbook package.

packages/core/tsconfig.json (1)

Line range hint 1-16:
Verify the impact of removing include and exclude properties.

The removal of these properties may lead to a broader set of files being compiled. Ensure that this change does not negatively impact the build process.

packages/orderbook/vite.config.ts (3)

16-16: LGTM! The tsconfigPath property improves TypeScript integration.

Specifying the tsconfigPath helps in generating declaration files with the correct TypeScript settings.


20-22: LGTM! Preserving symbolic links can improve module resolution behavior.

Setting preserveSymlinks to true ensures that symbolic links are preserved when resolving modules, which can be important in certain development environments.


36-36: LGTM! The entry point modification simplifies the project structure.

Changing the lib.entry point from 'src/index.ts' to 'index.ts' simplifies the project structure and entry point reference.

packages/core/src/utils.ts (2)

6-38: LGTM! The function is well-structured and handles async operations correctly.

The function performs operations to compute a secret based on blockchain interactions and includes necessary error handling and conditional logic.


41-47: LGTM! The function correctly identifies Bitcoin chains.

The function is straightforward and performs the intended checks correctly.

packages/core/vite.config.ts (5)

10-10: LGTM! The cache directory update aligns with the new project structure.

Updating the cacheDir to ../node_modules/.vite/core reflects the new project structure and organization.


16-21: LGTM! The tsconfigPath property improves TypeScript integration.

Specifying the tsconfigPath helps in generating declaration files with the correct TypeScript settings.


25-27: LGTM! Preserving symbolic links can improve module resolution behavior.

Setting preserveSymlinks to true ensures that symbolic links are preserved when resolving modules, which can be important in certain development environments.


29-33: LGTM! The alias improves test organization and import paths.

Adding an alias for @gardenfi/orderbook facilitates easier imports and improves test organization.


44-44: LGTM! The entry point modification simplifies the project structure.

Changing the lib.entry point from src/index.ts to index.ts simplifies the project structure and entry point reference.

packages/core/src/garden.ts (8)

Line range hint 19-23:
Constructor implementation looks good.

The constructor correctly initializes orderbook and wallets.


Line range hint 25-27:
subscribeOrders method implementation looks good.

The method correctly subscribes to order updates.


Line range hint 29-31:
unsubscribeOrders method implementation looks good.

The method correctly unsubscribes from order updates.


91-92: Simplified error handling for Bitcoin wallet.

The type check for AbstractBitcoinWallet has been removed, and the method now only verifies the existence of bitcoinWallet.


Line range hint 134-136:
getSwap method implementation looks good.

The method correctly returns a Swapper instance.


Line range hint 139-143:
calculateReceiveAmt method implementation looks good.

The method correctly calculates the receive amount.


Line range hint 145-151:
getBitcoinWallet method implementation looks good.

The method correctly returns a Bitcoin wallet.


Line range hint 154-157:
validateChain function implementation looks good.

The function correctly validates the chain.

Comment on lines +14 to +15
if (!followerWallet) throw new Error(`No ${fromChain} wallet found`);
if (!initiatorWallet) throw new Error(`No ${toChain} wallet found`);
Copy link

Choose a reason for hiding this comment

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

Improve error messages for clarity.

The error messages should specify the chain for which the wallet is missing.

-  if (!followerWallet) throw new Error(`No ${fromChain} wallet found`);
-  if (!initiatorWallet) throw new Error(`No ${toChain} wallet found`);
+  if (!followerWallet) throw new Error(`No wallet found for chain: ${fromChain}`);
+  if (!initiatorWallet) throw new Error(`No wallet found for chain: ${toChain}`);
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 (!followerWallet) throw new Error(`No ${fromChain} wallet found`);
if (!initiatorWallet) throw new Error(`No ${toChain} wallet found`);
if (!followerWallet) throw new Error(`No wallet found for chain: ${fromChain}`);
if (!initiatorWallet) throw new Error(`No wallet found for chain: ${toChain}`);

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