Skip to content

refactor(ccusage): remove private file prefixes#1007

Merged
ryoppippi merged 1 commit into
mainfrom
codex/remove-ccusage-src-underscores
May 16, 2026
Merged

refactor(ccusage): remove private file prefixes#1007
ryoppippi merged 1 commit into
mainfrom
codex/remove-ccusage-src-underscores

Conversation

@ryoppippi
Copy link
Copy Markdown
Owner

@ryoppippi ryoppippi commented May 16, 2026

Renames the remaining leading-underscore files under apps/ccusage/src now that src modules are not all exported as a public surface.

Updates all local imports, schema generation, and tsdown macro configuration to use the new filenames.

Validation:

  • pnpm run format
  • pnpm typecheck
  • pnpm run test

Summary by cubic

Remove leading-underscore prefixes from internal files in apps/ccusage/src and update all references and build tooling. This cleans up module names now that src modules aren’t exposed as a public API; no behavior changes.

  • Refactors
    • Renamed private modules to remove "_" prefixes (e.g., _types.ts -> types.ts, _session-blocks.ts -> session-blocks.ts).
    • Updated imports across commands, loaders, and utilities, plus schema generation script.
    • Adjusted tsdown.config.ts macro include paths to point to the new filenames.

Written for commit cda7a0d. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Chores
    • Reorganized internal module naming conventions throughout the ccusage application to improve overall code structure and maintainability. Removed underscore prefixes from internal module names and updated all corresponding import paths and references across the entire codebase to maintain consistency and clarity. No changes to user-facing functionality, public APIs, or application behavior.

Review Change Stack

Rename ccusage src files that still used leading underscore prefixes for internal modules. The package no longer exports every src module, so the prefix no longer communicates a meaningful public-private boundary.

Update all local imports, schema generation, and tsdown macro configuration to point at the new filenames while preserving the existing module structure.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2bca7c16-67c8-4545-86cb-4c5dceedd334

📥 Commits

Reviewing files that changed from the base of the PR and between 0078fcb and cda7a0d.

📒 Files selected for processing (28)
  • apps/ccusage/scripts/generate-json-schema.ts
  • apps/ccusage/src/calculate-cost.ts
  • apps/ccusage/src/cli.ts
  • apps/ccusage/src/commands/all.ts
  • apps/ccusage/src/commands/blocks.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/session_id.ts
  • apps/ccusage/src/commands/statusline.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/config-loader-tokens.ts
  • apps/ccusage/src/consts.ts
  • apps/ccusage/src/daily-grouping.ts
  • apps/ccusage/src/data-loader.ts
  • apps/ccusage/src/date-utils.ts
  • apps/ccusage/src/debug.ts
  • apps/ccusage/src/env.ts
  • apps/ccusage/src/json-output-types.ts
  • apps/ccusage/src/macro.ts
  • apps/ccusage/src/pricing-fetcher.ts
  • apps/ccusage/src/project-names.ts
  • apps/ccusage/src/session-blocks.ts
  • apps/ccusage/src/shared-args.ts
  • apps/ccusage/src/token-utils.ts
  • apps/ccusage/src/types.ts
  • apps/ccusage/src/utils.ts
  • apps/ccusage/tsdown.config.ts

📝 Walkthrough

Walkthrough

This pull request performs a systematic module path refactoring across the ccusage application: all internal modules using underscore-prefixed file names (e.g., _types.ts, _consts.ts, _env.ts) are renamed to non-underscore equivalents, with all dependent import statements updated accordingly. No functional behavior or exported APIs are changed.

Changes

Module path normalization

Layer / File(s) Summary
Shared types and configuration foundations
src/shared-args.ts, src/config-loader-tokens.ts
Imports switch from ./_types.ts to ./types.ts, and CONFIG_FILE_NAME moves from ./_consts.ts to ./consts.ts.
Utility and helper modules
src/cli.ts, src/date-utils.ts, src/session-blocks.ts, src/debug.ts
Environment constants, date utilities, session block helpers, and debug logging update internal imports to reference non-underscore module paths.
Data processing and model modules
src/calculate-cost.ts, src/daily-grouping.ts, src/json-output-types.ts, src/data-loader.ts
Token calculations, cost computation, daily grouping, JSON output types, and data loading update type/utility imports from underscore to non-underscore modules; deprecation comments are also updated.
Pricing and macro imports
src/pricing-fetcher.ts
prefetchClaudePricing macro import switches from ./_macro.ts to ./macro.ts.
Command modules import updates
src/commands/all.ts, src/commands/blocks.ts, src/commands/daily.ts, src/commands/monthly.ts, src/commands/session.ts, src/commands/session_id.ts, src/commands/statusline.ts, src/commands/weekly.ts
All command implementations update their imports to reference non-underscore versions of utility, configuration, and data-loading modules.
Build configuration and schema generation
scripts/generate-json-schema.ts, tsdown.config.ts
Schema generation and build tooling update imports to reference the renamed non-underscore modules; Rolldown macro plugin configuration targets the renamed pricing-fetcher path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • ryoppippi/ccusage#124: Prior refactor that moved modules in the opposite direction (from .internal.* to _*.ts), directly inverse to this PR's underscore-to-non-underscore renaming.
  • ryoppippi/ccusage#685: Modifies the same tsdown.config.ts macro plugin path for pricing-fetcher, overlapping the build configuration change.
  • ryoppippi/ccusage#605: Earlier PR that introduced date-utils refactoring and moved formatDateCompact into _date-utils.ts, directly opposite to this PR's import consolidation.

Poem

🐰 Files march in order, paths made clean,
Underscores fade—a tidy scene!
From _types to types, each import flows,
One simple refactor, how the garden grows. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(ccusage): remove private file prefixes' accurately describes the main change: renaming files in apps/ccusage/src by removing leading-underscore prefixes from internal module files throughout the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/remove-ccusage-src-underscores

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.

apps/ccusage/src/calculate-cost.ts

[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: npm i baseline-browser-mapping@latest -D
tsconfig.json is not found. we cannot use type-aware rules.

Oops! Something went wrong! :(

ESLint: 9.35.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-format' imported from /node_modules/.pnpm/@antfu+eslint-config@4.19.0_@vue+compiler-sfc@3.5.30_eslint@9.35.0_typescript@5.9.2_vit_670a2c5c75d4275eabd7bc195a173ee6/node_modules/@antfu/eslint-config/dist/index.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)
at packageResolve (node:internal/modules/esm/resolve:764:81)
at moduleResolve (node:internal/modules/esm/resolve:855:18)
at defaultResolve (node:internal/modules/esm/resolve:988:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:746:52)
at #resolve (node:internal/modules/esm/loader:679:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:599:35)
at node:internal/modules/esm/loader:628:32

apps/ccusage/src/commands/blocks.ts

[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: npm i baseline-browser-mapping@latest -D
tsconfig.json is not found. we cannot use type-aware rules.

Oops! Something went wrong! :(

ESLint: 9.35.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-format' imported from /node_modules/.pnpm/@antfu+eslint-config@4.19.0_@vue+compiler-sfc@3.5.30_eslint@9.35.0_typescript@5.9.2_vit_670a2c5c75d4275eabd7bc195a173ee6/node_modules/@antfu/eslint-config/dist/index.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)
at packageResolve (node:internal/modules/esm/resolve:764:81)
at moduleResolve (node:internal/modules/esm/resolve:855:18)
at defaultResolve (node:internal/modules/esm/resolve:988:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:746:52)
at #resolve (node:internal/modules/esm/loader:679:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:599:35)
at node:internal/modules/esm/loader:628:32

apps/ccusage/src/commands/daily.ts

[baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: npm i baseline-browser-mapping@latest -D
tsconfig.json is not found. we cannot use type-aware rules.

Oops! Something went wrong! :(

ESLint: 9.35.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-format' imported from /node_modules/.pnpm/@antfu+eslint-config@4.19.0_@vue+compiler-sfc@3.5.30_eslint@9.35.0_typescript@5.9.2_vit_670a2c5c75d4275eabd7bc195a173ee6/node_modules/@antfu/eslint-config/dist/index.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)
at packageResolve (node:internal/modules/esm/resolve:764:81)
at moduleResolve (node:internal/modules/esm/resolve:855:18)
at defaultResolve (node:internal/modules/esm/resolve:988:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:746:52)
at #resolve (node:internal/modules/esm/loader:679:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:599:35)
at node:internal/modules/esm/loader:628:32

  • 18 others

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2026

Open in StackBlitz

@ccusage/amp

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/amp@1007

ccusage

npx https://pkg.pr.new/ryoppippi/ccusage@1007

@ccusage/codex

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/codex@1007

@ccusage/opencode

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/opencode@1007

@ccusage/pi

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/pi@1007

commit: cda7a0d

@github-actions
Copy link
Copy Markdown

ccusage performance comparison

This compares the PR build against the base branch build on the same CI runner.

Committed fixture performance

Committed small fixture for stable PR-to-PR feedback and output-shape regressions.

Fixture: apps/ccusage/test/fixtures/claude
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Base median PR median PR vs base
daily --offline --json 93.3ms 92.9ms 1.00x
session --offline --json 92.8ms 93.0ms 1.00x
blocks --offline --json 92.6ms 91.8ms 1.01x

Large real-world-shaped fixture performance

Generated fixture around 1 GiB shaped from aggregate local Claude-log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixture.

Fixture: /home/runner/work/_temp/ccusage-large-fixture
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Base median PR median PR vs base
daily --offline --json 1.360s 1.362s 1.00x

Package size

Package artifact Base PR Delta Ratio
packed ccusage-*.tgz 64.06 KiB 64.05 KiB -0.01 KiB 1.00x

Lower medians and smaller packed package sizes are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@cloudflare-workers-and-pages
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 Updated (UTC)
⛔ Deployment terminated
View logs
ccusage-guide cda7a0d May 16 2026, 07:12 PM

@ryoppippi ryoppippi merged commit 83722ca into main May 16, 2026
23 of 24 checks passed
@ryoppippi ryoppippi deleted the codex/remove-ccusage-src-underscores branch May 16, 2026 19:16
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