Skip to content

refactor: make cli use ucd-store to download files#35

Merged
luxass merged 7 commits intomainfrom
refactor_make_cli_use_ucd-store_to_download_files
Jun 8, 2025
Merged

refactor: make cli use ucd-store to download files#35
luxass merged 7 commits intomainfrom
refactor_make_cli_use_ucd-store_to_download_files

Conversation

@luxass
Copy link
Copy Markdown
Member

@luxass luxass commented Jun 8, 2025

This PR resolves #22

This is done to remove duplicate code.

Summary by CodeRabbit

  • Refactor
    • Simplified the CLI download process by switching to a new download mechanism, resulting in a streamlined user experience and updated CLI flags.
  • Chores
    • Updated dependencies by adding a new package and removing unused ones.
  • Tests
    • Marked certain test suites as pending and adjusted test setup for file filtering and error handling.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 8, 2025

🦋 Changeset detected

Latest commit: 33a23e4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@ucdjs/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 8, 2025

Walkthrough

The CLI download command was refactored to delegate all Unicode data downloading and filtering logic to the external @ucdjs/ucd-store package. Related dependencies and manual implementations were removed, and CLI flags were updated. Associated tests were marked as pending or updated to reflect the new logic.

Changes

File(s) Change Summary
packages/cli/src/cmd/download.ts Refactored: replaced internal download/filtering logic with a call to @ucdjs/ucd-store's download function; updated CLI flags.
packages/cli/package.json, pnpm-workspace.yaml Removed micromatch and its types from dependencies; added @ucdjs/ucd-store as a dependency.
packages/cli/test/cmd/download.test.ts Marked several test suites as pending (describe.todo); updated flags and testdir cleanup options.
.changeset/wise-dodos-fall.md Added a changelog entry describing the migration to ucd-store for downloads.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (runDownload)
    participant ucd-store

    User->>CLI (runDownload): Invoke download command with flags/versions
    CLI (runDownload)->>ucd-store: download({ versions, outDir, exclude patterns, etc. })
    ucd-store-->>CLI (runDownload): Download results (files downloaded, errors)
    CLI (runDownload)-->>User: Output summary (files downloaded, errors)
Loading

Assessment against linked issues

Objective Addressed Explanation
Migrate CLI download command to use ucd-store for Unicode data downloads (#22)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected related to the objectives from the linked issues.

Possibly related PRs

Suggested labels

pkg: ucd-store

Poem

🐇
The CLI once fetched with toil and care,
Now calls on ucd-store, light as air!
Flags are trimmed, tests take a break,
Simpler code, for all our sake.
Unicode flows with a single command—
Progress hops on, just as planned!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/cli/src/cmd/download.ts

Oops! Something went wrong! :(

ESLint: 9.27.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

packages/cli/test/cmd/download.test.ts

Oops! Something went wrong! :(

ESLint: 9.27.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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
Copy Markdown
Member Author

luxass commented Jun 8, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@luxass luxass mentioned this pull request Jun 8, 2025
@luxass luxass force-pushed the refactor_make_cli_use_ucd-store_to_download_files branch 2 times, most recently from e65496b to 917e6fd Compare June 8, 2025 04:44
@luxass luxass marked this pull request as ready for review June 8, 2025 04:54
@luxass luxass changed the base branch from feat_switch_to_picomatch to graphite-base/35 June 8, 2025 04:55
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/cmd/download.ts 50.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@luxass luxass force-pushed the refactor_make_cli_use_ucd-store_to_download_files branch 2 times, most recently from 834f64c to ce43550 Compare June 8, 2025 04:55
@luxass luxass changed the base branch from graphite-base/35 to main June 8, 2025 04:55
@luxass luxass force-pushed the refactor_make_cli_use_ucd-store_to_download_files branch 2 times, most recently from 617b860 to ce43550 Compare June 8, 2025 05:14
Copy link
Copy Markdown
Contributor

@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 (2)
packages/cli/test/cmd/download.test.ts (1)

135-135: Follow up on pending test suites.

The "file filtering" and "error handling" test suites have been marked as todo. These tests should be updated to work with the new ucd-store implementation.

Would you like me to help update these test suites to work with the new implementation or create an issue to track this work?

Also applies to: 233-233

packages/cli/src/cmd/download.ts (1)

86-93: Test coverage needed for the new implementation.

Static analysis indicates these lines lack test coverage. This is expected since the related tests are marked as todo, but should be addressed.

Also applies to: 96-96

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 86-93: packages/cli/src/cmd/download.ts#L86-L93
Added lines #L86 - L93 were not covered by tests

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93020cf and ce43550.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/wise-dodos-fall.md (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/cmd/download.ts (4 hunks)
  • packages/cli/test/cmd/download.test.ts (2 hunks)
  • pnpm-workspace.yaml (0 hunks)
💤 Files with no reviewable changes (1)
  • pnpm-workspace.yaml
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/cli/src/cmd/download.ts

[warning] 86-93: packages/cli/src/cmd/download.ts#L86-L93
Added lines #L86 - L93 were not covered by tests


[warning] 96-96: packages/cli/src/cmd/download.ts#L96
Added line #L96 was not covered by tests

🔇 Additional comments (3)
.changeset/wise-dodos-fall.md (1)

1-6: Changeset correctly documents the refactor.

The changeset entry properly marks this as a minor version update and clearly describes the migration to ucd-store.

packages/cli/package.json (1)

45-45: Dependency addition looks good.

The addition of @ucdjs/ucd-store as a workspace dependency aligns with the refactor objective.

packages/cli/src/cmd/download.ts (1)

86-93: Clean implementation delegating to ucd-store.

The refactored download logic properly delegates all functionality to the @ucdjs/ucd-store package, successfully eliminating code duplication as intended.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 86-93: packages/cli/src/cmd/download.ts#L86-L93
Added lines #L86 - L93 were not covered by tests

Comment thread packages/cli/test/cmd/download.test.ts Outdated
Comment thread packages/cli/src/cmd/download.ts Outdated
@luxass luxass merged commit d623935 into main Jun 8, 2025
5 of 6 checks passed
@luxass luxass deleted the refactor_make_cli_use_ucd-store_to_download_files branch June 8, 2025 05:44
Copy link
Copy Markdown
Contributor

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce43550 and 33a23e4.

📒 Files selected for processing (2)
  • packages/cli/src/cmd/download.ts (4 hunks)
  • packages/cli/test/cmd/download.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/test/cmd/download.test.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/cli/src/cmd/download.ts

[warning] 85-92: packages/cli/src/cmd/download.ts#L85-L92
Added lines #L85 - L92 were not covered by tests


[warning] 95-95: packages/cli/src/cmd/download.ts#L95
Added line #L95 was not covered by tests

🔇 Additional comments (3)
packages/cli/src/cmd/download.ts (3)

3-7: LGTM! Import updates support the refactor well.

The new imports appropriately support the transition to using @ucdjs/ucd-store for download functionality and the simplified output formatting.


16-17: LGTM! New flags provide appropriate granular control.

The excludeHTMLFiles and excludeReadmes flags align well with the new download function interface and maintain user control over file filtering.


35-37: LGTM! Help text properly documents new flags.

The help text clearly documents the new exclude flags. The duplicate --force flag issue from the previous review appears to have been resolved.

Comment on lines +95 to +96
const totalFiles = result.downloadedFiles.length;
const totalErrors = result.errors?.length ?? 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

LGTM! Simplified summary aligns with the refactor goals.

The streamlined output appropriately reflects that detailed download work is now handled by the external package.

However, the static analysis indicates missing test coverage for the new download logic. Consider adding integration tests to ensure the flag-to-parameter mapping and error handling work correctly with the new @ucdjs/ucd-store dependency.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 95-95: packages/cli/src/cmd/download.ts#L95
Added line #L95 was not covered by tests

🤖 Prompt for AI Agents
In packages/cli/src/cmd/download.ts around lines 95 to 96, add integration tests
to cover the new download logic involving the flag-to-parameter mapping and
error handling with the @ucdjs/ucd-store dependency. Create tests that simulate
different flag inputs and verify the correct parameters are passed to the
download function, as well as tests that trigger and assert proper handling of
errors returned by the download process.

Comment on lines +85 to +92
const result = await download({
versions: versions.map(({ version }) => version),
basePath: outputDir,
exclude: flags.exclude,
includeHTMLFiles: !flags.excludeHTMLFiles,
includeReadmes: !flags.excludeReadmes,
includeTests: !flags.excludeTest,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the missing force flag parameter.

The refactor successfully simplifies the download logic by delegating to @ucdjs/ucd-store. However, the force flag is defined in the CLI options but not passed to the download function.

Please verify if the download function supports a force parameter:


🏁 Script executed:

#!/bin/bash
# Description: Check if the download function from @ucdjs/ucd-store supports a force parameter
# Expected: Find the function signature and parameter interface

# Search for the download function interface or implementation
ast-grep --pattern $'export function download($$$) {
  $$$
}'

# Also search for download function type definitions
rg -A 10 "function download|export.*download" --type ts

Length of output: 2161


🏁 Script executed:

#!/bin/bash
# Search for the DownloadOptions definition to see if it includes a `force` field
grep -R "interface DownloadOptions" -n packages/ucd-store/src
grep -R "type DownloadOptions" -n packages/ucd-store/src

Length of output: 187


🏁 Script executed:

#!/bin/bash
# Display the DownloadOptions interface to verify if it includes a `force` field
rg -n -A 15 "interface DownloadOptions" packages/ucd-store/src/download.ts

Length of output: 411


Implement or remove the unused force flag

The DownloadOptions interface in @ucdjs/ucd-store does not include a force field, so the CLI’s flags.force is currently ignored. You should either wire up force support end-to-end or remove the flag.

• In packages/cli/src/cmd/download.ts (around lines 85–92):

  • Add force: flags.force to the call site if you intend to support it.
    • In packages/ucd-store/src/download.ts (and its DownloadOptions interface on line 7):
  • Extend DownloadOptions to include force?: boolean
  • Implement the intended “force” behavior (e.g. overwrite existing files).

Example CLI diff:

 const result = await download({
   versions: versions.map(({ version }) => version),
   basePath: outputDir,
   exclude: flags.exclude,
   includeHTMLFiles: !flags.excludeHTMLFiles,
   includeReadmes: !flags.excludeReadmes,
   includeTests: !flags.excludeTest,
+  force: flags.force,
 });

And in ucd-store/src/download.ts:

 interface DownloadOptions {
   versions: string[];
   exclude?: string;
   includeTests?: boolean;
   includeReadmes?: boolean;
   includeHTMLFiles?: boolean;
   basePath?: string;
+  force?: boolean;
 }
📝 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 result = await download({
versions: versions.map(({ version }) => version),
basePath: outputDir,
exclude: flags.exclude,
includeHTMLFiles: !flags.excludeHTMLFiles,
includeReadmes: !flags.excludeReadmes,
includeTests: !flags.excludeTest,
});
const result = await download({
versions: versions.map(({ version }) => version),
basePath: outputDir,
exclude: flags.exclude,
includeHTMLFiles: !flags.excludeHTMLFiles,
includeReadmes: !flags.excludeReadmes,
includeTests: !flags.excludeTest,
force: flags.force,
});
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 85-92: packages/cli/src/cmd/download.ts#L85-L92
Added lines #L85 - L92 were not covered by tests

🤖 Prompt for AI Agents
In packages/cli/src/cmd/download.ts around lines 85 to 92, the download function
call is missing the force flag parameter, which is defined in the CLI options
but not passed through. To fix this, add force: flags.force to the download
function call arguments. Additionally, in packages/ucd-store/src/download.ts,
extend the DownloadOptions interface to include an optional force boolean field
and implement the logic to handle the force behavior, such as overwriting
existing files when force is true.

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.

migrate cli download cmd to ucd-store

1 participant