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

Import AML in CLI #337

Closed
wants to merge 2 commits into from
Closed

Import AML in CLI #337

wants to merge 2 commits into from

Conversation

loicknuchel
Copy link
Contributor

@loicknuchel loicknuchel commented Nov 29, 2024

Closed, started again on #339

Parser SQL

Rollup don't like CommonJS but still generate the bundle.

`npm run build` logs:
> @azimutt/[email protected] build
> rm -rf ./out && tsc && npm run build:browser


> @azimutt/[email protected] build:browser
> rollup --config rollup.config.ts --configPlugin typescript

loaded rollup.config.ts with warnings
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
(!) [plugin typescript] src/index.ts (10:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-sql/src/index.ts:10:1

10 export * from "@azimutt/models"
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] src/sql.ts (2:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-sql/src/sql.ts:2:1

2 import * as chevrotain from "./chevrotain";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] @rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.

src/index.ts → out/bundle.min.js...
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
(!) [plugin typescript] src/index.ts (10:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-sql/src/index.ts:10:1

10 export * from "@azimutt/models"
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] src/sql.ts (2:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-sql/src/sql.ts:2:1

2 import * as chevrotain from "./chevrotain";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

created out/bundle.min.js in 2.6s

Parser DBML

Rollup don't like CommonJS but still generate the bundle.

`npm run build` logs:
> @azimutt/[email protected] build
> rm -rf ./out && tsc && npm run build:browser


> @azimutt/[email protected] build:browser
> rollup --config rollup.config.ts --configPlugin typescript

loaded rollup.config.ts with warnings
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
(!) [plugin typescript] src/dbml.ts (1:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-dbml/src/dbml.ts:1:1

1 import * as dbml from "@dbml/core";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] src/index.ts (10:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-dbml/src/index.ts:10:1

10 export * from "@azimutt/models"
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] @rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.

src/index.ts → out/bundle.min.js...
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
(!) [plugin typescript] src/dbml.ts (1:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-dbml/src/dbml.ts:1:1

1 import * as dbml from "@dbml/core";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(!) [plugin typescript] src/index.ts (10:1): @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
libs/parser-dbml/src/index.ts:10:1

10 export * from "@azimutt/models"
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

created out/bundle.min.js in 1.3s

Parser Prisma

Rollup don't like CommonJS but still generate the bundle.

`npm run build` logs
> @azimutt/[email protected] build
> rm -rf ./out && tsc && npm run build:browser


> @azimutt/[email protected] build:browser
> rollup --config rollup.config.ts --configPlugin typescript

loaded rollup.config.ts with warnings
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
(!) [plugin typescript] @rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.

src/index.ts → out/bundle.min.js...
(!) [plugin typescript] @rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
created out/bundle.min.js in 1s

CLI project

  • can't use commonjs because of cli/src/utils/file.ts:21 (fileURLToPath(import.meta.url))
  • also chalk is an ESM lib :/

Summary by CodeRabbit

  • New Features

    • Added support for the 'aml' dialect in conversion processes, with future implementation plans noted.
  • Documentation

    • Enhanced comments in the code to clarify the handling and future plans for the 'aml' dialect.
  • Chores

    • Updated project dependencies to include @azimutt/aml.

Copy link

coderabbitai bot commented Nov 29, 2024

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 changes involve updates to the package.json and convert.ts files in the azimutt project. A new dependency, "@azimutt/aml": "workspace:^", has been added to the package.json, indicating a reliance on the @azimutt/aml package. In convert.ts, modifications include the addition of handling for the 'aml' dialect within the parseDialect and generateDialect functions, along with comments indicating future implementation plans. Error handling remains unchanged.

Changes

File Change Summary
cli/package.json Added new dependency "@azimutt/aml": "workspace:^" in the dependencies section.
cli/src/convert.ts Updated parseDialect and generateDialect functions to handle 'aml' dialect with comments.

Poem

In the meadow where code does play,
A new dependency hops in today.
With 'aml' dialect, we take a chance,
Future plans in comments dance.
Let's code and create, come what may,
Together we'll build, hip-hip-hooray! 🐇✨


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

🧹 Outside diff range and nitpick comments (3)
cli/src/convert.ts (3)

45-49: Consider improving error handling and implementation strategy

The current implementation returns a generic "not available" error. Consider:

  1. Adding more specific error information from the detailed comment in the error message
  2. Implementing feature detection to provide better feedback about why AML parsing isn't available
 if (dialect === 'aml') {
-    return ParserResult.failure([{message: 'AML parser not available', kind: 'NotImplemented', level: 'error', offset: {start: 0, end: 0}, position: {start: {line: 0, column: 0}, end: {line: 0, column: 0}}}])
+    return ParserResult.failure([{
+        message: 'AML parser module not found. Please ensure @azimutt/aml is properly installed.',
+        kind: 'ModuleNotFound',
+        level: 'error',
+        offset: {start: 0, end: 0},
+        position: {start: {line: 0, column: 0}, end: {line: 0, column: 0}}
+    }])
 }

55-58: Maintain consistent error handling between parse and generate functions

The error handling approach differs between parseDialect and generateDialect. Consider:

  1. Using the same error structure for consistency
  2. Providing more detailed error information
 if (dialect === 'aml') {
-    return Result.failure('AML generator not available')
+    return Result.failure('AML generator module not found. Please ensure @azimutt/aml is properly installed.')
 }

AML module is implemented but not properly imported

The AML module is fully implemented in libs/aml/src/ with all necessary components:

  • The module exports parseAml and generateAml functions in index.ts
  • Implementation files exist: amlAst.ts, amlParser.ts, amlGenerator.ts
  • Tests are present: amlGenerator.test.ts, amlParser.test.ts

The issue in cli/src/convert.ts is just an import problem. The commented import should be uncommented and the TODOs in the implementation should be removed since the functionality is available.

🔗 Analysis chain

Line range hint 11-58: Verify complete AML implementation path

Let's verify the implementation status of the AML module and related dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for AML module implementation files
echo "Checking for AML implementation files..."
fd -t f "aml" libs/aml/src

# Check for any existing AML-related tests
echo -e "\nChecking for AML-related tests..."
fd -t f "aml" -e test.ts -e spec.ts

# Check for any existing AML documentation
echo -e "\nChecking for AML documentation..."
fd -t f "aml" -e md docs

Length of output: 698


Script:

#!/bin/bash
# Let's check the content of the AML implementation files to verify their status
echo "Checking AML implementation status..."
for file in libs/aml/src/amlAst.ts libs/aml/src/amlParser.ts libs/aml/src/amlGenerator.ts; do
    echo -e "\n=== Content of $file ==="
    head -n 20 "$file"
done

# Check if the AML module is properly exported
echo -e "\n=== Checking AML exports ==="
cat libs/aml/src/index.ts

# Check package.json for AML module configuration
echo -e "\n=== Checking package.json for AML configuration ==="
cat libs/aml/package.json

Length of output: 7329

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 38624ba and 1ce7e35.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • cli/package.json (1 hunks)
  • cli/src/convert.ts (2 hunks)
🔇 Additional comments (3)
cli/package.json (2)

44-44: LGTM! Dependency addition follows workspace patterns

The new @azimutt/aml dependency follows the same workspace pattern as other internal packages.


44-44: Verify workspace dependency resolution

Let's ensure the workspace is properly configured and the new dependency can be resolved.

✅ Verification successful

Workspace dependency resolution is properly configured

The workspace setup is valid and all required dependencies are present:

  • Found pnpm-workspace.yaml confirming workspace configuration
  • @azimutt/aml package exists with version 0.1.10
  • Required workspace dependencies are available:
    • @azimutt/models (v0.1.16)
    • @azimutt/utils (v0.1.7)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify workspace setup and dependency resolution

# Check if package exists in workspace
fd -t f "package.json" | xargs cat | jq 'select(.name=="@azimutt/aml")'

# Check for potential workspace configuration
fd -t f "pnpm-workspace.yaml" -t f "rush.json" -t f "lerna.json"

Length of output: 1768


Script:

#!/bin/bash
# Let's check for workspace configuration and verify the dependency structure

# Check for pnpm workspace configuration
fd -t f "pnpm-workspace.yaml"

# Look for package.json files in the root and potential workspace packages
fd -t f "package.json" -d 1

# Check if @azimutt/models and @azimutt/utils (dependencies of aml) exist
fd -t f "package.json" | xargs cat | jq 'select(.name | contains("@azimutt/models") or contains("@azimutt/utils"))'

Length of output: 2119

cli/src/convert.ts (1)

11-11: Verify AML module implementation status

The TODO comment suggests that the AML module implementation is pending. Since this PR's objective is to import AML in CLI, we should clarify if this is intentionally left as a TODO or if it needs to be implemented as part of this PR.

Would you like help implementing the AML parser and generator functions? I can assist in creating the implementation or open a GitHub issue to track this task.

@loicknuchel loicknuchel marked this pull request as draft November 29, 2024 22:24
@loicknuchel loicknuchel closed this Dec 1, 2024
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