fix\!: remove all deprecated functions by ryoppippi · Pull Request #150 · ccusage/ccusage · GitHub
Skip to content

fix\!: remove all deprecated functions#150

Merged
ryoppippi merged 5 commits into
mainfrom
deprecated-functions
Jun 22, 2025
Merged

fix\!: remove all deprecated functions#150
ryoppippi merged 5 commits into
mainfrom
deprecated-functions

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Jun 22, 2025

Copy link
Copy Markdown
Member

Summary

  • Removed deprecated dateSchema in favor of filterDateSchema
  • Replaced deprecated getDefaultClaudePath() with getClaudePaths()
  • Removed all deprecated functions and their test cases

Breaking Changes

This PR contains breaking changes that require users to update their code:

  1. dateSchema removed: Use filterDateSchema instead for date validation
  2. getDefaultClaudePath() removed: Use getClaudePaths() which returns an array of paths

Migration Guide

dateSchema → filterDateSchema

// Before
import { dateSchema } from "./types";
const date = dateSchema.parse("20240101");

// After
import { filterDateSchema } from "./types";
const date = filterDateSchema.parse("20240101");

getDefaultClaudePath → getClaudePaths

// Before
import { getDefaultClaudePath } from "./data-loader";
const claudePath = getDefaultClaudePath();

// After
import { getClaudePaths } from "./data-loader";
const paths = getClaudePaths();
if (paths.length === 0) {
  throw new Error("No valid Claude data directory found");
}
const claudePath = paths[0];

Test Plan

  • All existing tests pass
  • TypeScript compilation succeeds
  • ESLint checks pass
  • Verified that all deprecated function usages have been replaced
  • Confirmed no references to deprecated functions remain in the codebase

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for date input fields to ensure stricter format checking.
    • Enhanced error handling when no valid Claude data directories are found.
  • Refactor

    • Updated logic to support multiple Claude data directories instead of relying on a single default path.
    • Removed deprecated date validation and legacy path selection functions for cleaner configuration.
  • Chores

    • Cleaned up unused imports and deprecated code.

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 22, 2025

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Summary of Changes

Hello @ryoppippi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on cleaning up the codebase by removing deprecated functions and their associated test cases. I've systematically replaced all usages of dateSchema with filterDateSchema and getDefaultClaudePath() with getClaudePaths(), ensuring the system uses the most current and robust APIs. This change, while introducing breaking changes, improves maintainability and prepares the project for future enhancements by eliminating legacy code paths.

Highlights

  • Deprecated Schema Removal: I've removed the deprecated dateSchema from src/_types.ts and updated all its usages to filterDateSchema in src/_shared-args.ts and src/mcp.ts.
  • Deprecated Path Function Removal: I've removed the deprecated getDefaultClaudePath() function and its associated test cases from src/data-loader.ts. All calls to this function have been replaced with getClaudePaths().
  • Migration to getClaudePaths(): The codebase has been updated to use getClaudePaths() instead of getDefaultClaudePath(). This includes changes in src/commands/blocks.ts, src/commands/mcp.ts, src/debug.ts, and src/mcp.ts. Error handling has been added where getClaudePaths() might return an empty array, ensuring that a valid Claude data directory is found.
  • Breaking Changes: This PR introduces breaking changes by removing dateSchema and getDefaultClaudePath(). Consumers must update their code to use filterDateSchema and getClaudePaths() respectively, as detailed in the PR description's migration guide.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@150

commit: a6edcbe

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 22, 2025

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide a6edcbe Commit Preview URL Jun 22 2025, 09:40 AM

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request removes deprecated functions and updates the codebase to use the new filterDateSchema and getClaudePaths functions. The changes include updates to shared arguments, commands, data loading, debugging, and MCP server functionalities. The removal of the deprecated functions and their associated tests ensures a cleaner and more maintainable codebase.

Comment thread src/_shared-args.ts Outdated

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.

medium

Consider destructuring the imports to improve readability.

Suggested change
import { CostModes, filterDateSchema, SortOrders } from './_types.ts';
import type { CostMode, SortOrder } from './_types.ts';
import { CostModes, SortOrders, filterDateSchema } from './_types.ts';

Comment thread src/commands/blocks.ts Outdated
Comment on lines 235 to 239

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.

medium

It's good that you're throwing an error when no Claude data directory is found, but consider if it would be better to handle this case more gracefully, perhaps by logging a warning and exiting the function instead of throwing an error. This might prevent the application from crashing in certain situations.

      logger.error('No valid Claude data directory found');
      return;
    }

Comment thread src/commands/mcp.ts Outdated
Comment on lines 39 to 42

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.

medium

It's good that you're throwing an error when no Claude data directory is found, but consider if it would be better to handle this case more gracefully, perhaps by logging a warning and exiting the function instead of throwing an error. This might prevent the application from crashing in certain situations.

      logger.error('No valid Claude data directory found');
      return;
    }

Comment thread src/debug.ts Outdated
Comment on lines 81 to 85

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.

medium

It's good that you're throwing an error when no Claude data directory is found, but consider if it would be better to handle this case more gracefully, perhaps by logging a warning and exiting the function instead of throwing an error. This might prevent the application from crashing in certain situations.

      logger.error('No valid Claude data directory found');
      return;
    }

Comment thread src/mcp.ts Outdated
Comment on lines 33 to 40

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.

medium

Consider adding a check to ensure that getClaudePaths() returns at least one path before accessing the first element. This will prevent potential errors if no paths are found.

  claudePath: getClaudePaths().length > 0 ? getClaudePaths()[0] : ''

Copilot AI left a comment

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.

Pull Request Overview

This PR removes deprecated functions and updates the codebase to use their modern equivalents. Key changes include replacing dateSchema with filterDateSchema, replacing getDefaultClaudePath() with getClaudePaths(), and updating associated tests and command logic accordingly.

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mcp.ts Updated imports and usage of deprecated functions, but error handling may be inconsistent.
src/debug.ts Updated usage of getClaudePaths with proper null checks.
src/data-loader.ts Removed deprecated getDefaultClaudePath and its tests.
src/commands/mcp.ts Updated to use getClaudePaths with error handling when no paths exist.
src/commands/blocks.ts Updated to use getClaudePaths with error handling when no paths exist.
src/_types.ts Removed inline deprecated dateSchema definition.
src/_shared-args.ts Updated parseDateArg to use filterDateSchema.
docs/package.json Updated dependency version for typedoc.

Comment thread src/mcp.ts Outdated

Copilot AI Jun 22, 2025

Copy link

Choose a reason for hiding this comment

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

Consider handling the case where getClaudePaths() might return an empty array. Using an empty string as a fallback can lead to inconsistent behavior compared to other modules that throw an error if no valid path is found. A uniform error handling strategy would improve code maintainability.

Suggested change
claudePath: getClaudePaths()[0] ?? '',
claudePath: (() => {
const paths = getClaudePaths();
if (paths.length === 0) {
throw new Error('No valid Claude path found. Ensure getClaudePaths() returns at least one valid path.');
}
return paths[0];
})(),

Copilot uses AI. Check for mistakes.
@socket-security

socket-security Bot commented Jun 22, 2025

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedxdg-basedir@​5.1.01001008976100
Addedvitest@​3.2.4971007799100
Addedstring-width@​7.2.01001008777100
Addedunplugin-macros@​0.17.08010010090100
Addedunplugin-unused@​0.5.18110010090100
Addedtsdown@​0.12.8981008796100
Addedtinyglobby@​0.2.141001009189100
Addedtype-fest@​4.41.010010010089100
Addedzod@​3.25.6710010010096100

View full report

BREAKING CHANGE: dateSchema has been removed. Use filterDateSchema
instead for date validation.

- Replace dateSchema with filterDateSchema in _shared-args.ts

- Replace dateSchema with filterDateSchema in mcp.ts

- Remove deprecated dateSchema export from _types.ts
BREAKING CHANGE: getDefaultClaudePath() has been replaced with
getClaudePaths() which returns an array of paths.

- Replace getDefaultClaudePath with getClaudePaths in mcp.ts

- Replace getDefaultClaudePath with getClaudePaths in commands/mcp.ts

- Replace getDefaultClaudePath with getClaudePaths in blocks.ts

- Replace getDefaultClaudePath with getClaudePaths in debug.ts

- Add proper error handling for empty path arrays
BREAKING CHANGE: getDefaultClaudePath() has been completely removed. Use
getClaudePaths() instead.

- Remove getDefaultClaudePath function definition

- Remove all test cases for getDefaultClaudePath

- Remove unused imports (homedir, join)
… defaultOptions

Replace fallback empty string with proper error throwing to match behavior in other modules. This prevents inconsistent behavior when no valid Claude data directory is found.

Addresses feedback from Copilot PR review comment.
@ryoppippi ryoppippi force-pushed the deprecated-functions branch from a74d8ee to a6edcbe Compare June 22, 2025 09:39
@ryoppippi ryoppippi merged commit 7483b59 into main Jun 22, 2025
8 of 9 checks passed
@ryoppippi ryoppippi deleted the deprecated-functions branch June 22, 2025 09:40
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.

2 participants