chore: move files under src directory by ryoppippi · Pull Request #7 · ccusage/ccusage · GitHub
Skip to content

chore: move files under src directory#7

Merged
ryoppippi merged 3 commits into
mainfrom
src-dirr
Jun 3, 2025
Merged

chore: move files under src directory#7
ryoppippi merged 3 commits into
mainfrom
src-dirr

Conversation

@ryoppippi

Copy link
Copy Markdown
Member

fixes: #2
This pull request introduces several updates to the project structure, including changes to file paths, package scripts, and configuration settings. The most significant updates involve reorganizing the codebase to use a src directory for source files, modifying import paths, and adjusting package scripts to reflect the new structure.

Updates to project structure:

  • Reorganization of source files:
    • Renamed index.ts to src/commands/index.ts and adjusted imports to reflect the new directory structure. ([src/commands/index.tsL1-R5](https://github.com/ccusage/ccusage/pull/7/files#diff-a6a1db61476382a80351bf0b40126b3cfca87878293a3fca70dfe04367f4a11fL1-R5))
    • Added a new src/index.ts file as the entry point, including a shebang for CLI execution and importing src/commands/index.ts. ([src/index.tsR1-R3](https://github.com/ccusage/ccusage/pull/7/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R1-R3))
    • Renamed logger.ts to src/logger.ts and updated the import path for package.json. ([src/logger.tsL3-R3](https://github.com/ccusage/ccusage/pull/7/files#diff-7bc1140e724e284ae22084e1172568baa8d151063d02c75ed1d8805fa7796acaL3-R3))

Updates to package.json:

  • Exports additions:
    • Added new entries for ./debug, ./logger, ./pricing-fetcher, ./shared-args, ./types, and ./utils in the exports field. ([package.jsonR21-R26](https://github.com/ccusage/ccusage/pull/7/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R21-R26))
  • Script modifications:
    • Replaced the report script with a start script that runs ./src/index.ts. ([package.jsonL35-R41](https://github.com/ccusage/ccusage/pull/7/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L35-R41))

Updates to configuration:

  • Build entry points:
    • Updated the tsdown.config.ts file to use ./src/*.ts as entry points, excluding test files (!./src/**/*.test.ts). ([tsdown.config.tsL5-R5](https://github.com/ccusage/ccusage/pull/7/files#diff-c105f99c241d6d60e41561e663ee096629894e9b2a773c82283655b323f59485L5-R5))

@ryoppippi ryoppippi requested a review from Copilot June 3, 2025 16:19

@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.

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!

Summary of Changes

Hello team, Gemini here with a summary of this pull request. This PR, authored by @ryoppippi, addresses issue #2 by undertaking a significant refactoring of the project's structure. The core change involves moving the main source files into a dedicated src directory. This required updating various import paths throughout the codebase, modifying the package.json file to reflect the new file locations and entry points, and adjusting the build configuration (tsdown.config.ts) to correctly process files within the new src structure. Additionally, the main execution script name in package.json and documentation has been changed from report to start to better reflect its purpose.

Highlights

  • Project Structure Reorganization: The primary change is the migration of source files (like index.ts, logger.ts, and command files) into a new src/ directory for better organization.
  • Import Path Updates: All internal import paths have been updated to correctly reference files within the new src/ directory structure.
  • Package Configuration Updates: The package.json file has been updated to include new exports entries pointing to modules within the dist/ directory (compiled from src/) and the main script name has been changed from report to start.
  • Build Configuration Adjustment: The tsdown.config.ts build configuration has been updated to use a glob pattern (./src/*.ts) to include all source files in the src directory for compilation, while explicitly excluding test files.
  • Documentation Updates: The CLAUDE.md file has been updated to reflect the change in the main script name from report to start.

Changelog

Click here to see the changelog
  • CLAUDE.md
    • Updated development usage commands to use bun run start instead of bun run report.
    • Updated the direct execution command from bun run index.ts to bun run ./src/index.ts.
  • package.json
    • Added new entries to the exports field for modules now located under src (debug, logger, pricing-fetcher, shared-args, types, utils).
    • Renamed the report script to start and updated the command to bun run ./src/index.ts.
  • src/commands/index.ts
    • Removed the shebang line, as it is now in the new src/index.ts.
    • Updated import paths for package.json (relative path changed).
    • Updated import paths for dailyCommand and sessionCommand (relative path changed from ./commands/... to ./...).
  • src/index.ts
    • Added a new file src/index.ts.
    • Added the shebang line (#!/usr/bin/env node).
    • Imports src/commands/index.ts to serve as the new main entry point.
  • src/logger.ts
    • Updated the import path for package.json (relative path changed).
  • tsdown.config.ts
    • Updated the entry configuration to use a glob pattern ./src/*.ts and exclude test files !./src/**/*.test.ts.
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.


Files find a new home,
In src they now roam,
Imports change their way,
Builds know where to play,
Order helps code grow.

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 3, 2025

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 4986501

@ryoppippi ryoppippi merged commit bd53366 into main Jun 3, 2025
9 checks passed
@ryoppippi ryoppippi deleted the src-dirr branch June 3, 2025 16:20

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 reorganizes the project under a new src directory, updates import paths and package scripts, and adjusts build/configuration settings to match the new structure.

  • Moved source files (index.ts, commands/, logger.ts, etc.) into src/
  • Updated import paths in logger.ts and commands/index.ts
  • Adjusted package.json exports and scripts; updated tsdown.config.ts entry globs

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsdown.config.ts Changed entry points to use ./src/*.ts and exclude test files
src/logger.ts Updated JSON import path to reach package root
src/index.ts Added CLI shebang and bootstrapped commands entry
src/commands/index.ts Fixed import paths for commands and package metadata
package.json Added new exports entries and replaced report script with start
CLAUDE.md Updated usage instructions to reflect new start script

Comment thread tsdown.config.ts

export default defineConfig({
entry: ["./index.ts", "./data-loader.ts", "./calculate-cost.ts"],
entry: ["./src/*.ts", "!./src/**/*.test.ts"],

Copilot AI Jun 3, 2025

Copy link

Choose a reason for hiding this comment

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

The tsdown entry glob only includes top‐level files under src/ and omits subdirectories like src/commands. Consider using "./src/**/*.ts" to include all source modules.

Suggested change
entry: ["./src/*.ts", "!./src/**/*.test.ts"],
entry: ["./src/**/*.ts", "!./src/**/*.test.ts"],

Copilot uses AI. Check for mistakes.
Comment thread src/index.ts
@@ -0,0 +1,3 @@
#!/usr/bin/env node

import "./commands/index.ts";

Copilot AI Jun 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] You can simplify this to import "./commands"; and rely on the index.ts fallback, which is more idiomatic and avoids hardcoding the file extension.

Suggested change
import "./commands/index.ts";
import "./commands";

Copilot uses AI. Check for mistakes.
Comment thread src/commands/index.ts
import { dailyCommand } from "./commands/daily.ts";
import { sessionCommand } from "./commands/session.ts";
import { description, name, version } from "./package.json";
import { description, name, version } from "../../package.json";

Copilot AI Jun 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Deep relative imports (../../package.json) can be brittle. Consider configuring a path alias (e.g., @root/package.json) or moving metadata access into a shared module to improve maintainability.

Copilot uses AI. Check for mistakes.

@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 effectively reorganizes the project by moving source files into an src directory. The changes are well-documented in the PR description and appear consistent across configuration files, package scripts, and documentation. This is a positive step for project structure and maintainability.

My review considers general TypeScript best practices and information from CLAUDE.md, as no formal style guide was provided. For instance, CLAUDE.md provides guidance on console.log usage.

Two points for consideration outside the direct diff review but relevant to the codebase:

  1. The CLAUDE.md file's "Architecture Overview" (line 39) still refers to index.ts as the CLI entry point. This might need updating to reflect the new src/index.ts and src/commands/index.ts structure in a follow-up.
  2. I also noticed an existing line export const log = console.log; in src/logger.ts (line 7 of the full file). This seems to conflict with the guidance in CLAUDE.md (lines 59, 89) about avoiding console.log and using the logger instead. While this line wasn't changed in this PR, it might be worth addressing in a follow-up to align with project guidelines.

Summary of Findings

  • Potential conflict/redundancy in package.json#exports and tsdown configuration: Manual additions to package.json#exports might be redundant or conflict with tsdown's exports: true feature, which aims to auto-generate these. This could impact maintainability and the correctness of the published package's API. (Commented)
  • Documentation updates in CLAUDE.md: The CLAUDE.md file's development usage commands were correctly updated. (Low severity, not commented due to settings)
  • Build configuration update in tsdown.config.ts: The change to use a glob pattern "./src/*.ts" for entry points in tsdown.config.ts is a good improvement for maintainability and aligns with the new exports structure. (Low severity, not commented due to settings)
  • Path adjustments: Import paths in moved files (src/commands/index.ts, src/logger.ts) have been correctly updated. (Low severity, not commented due to settings)

Merge Readiness

The pull request makes sensible structural improvements. However, before merging, I recommend clarifying the interaction between the manual package.json#exports additions and tsdown's exports: true feature to ensure the build process is robust and maintainable. Addressing this point will help guarantee the package's API is correctly defined upon publishing. I am unable to approve the pull request myself; please ensure further review and approval as per your team's policy after addressing the feedback.

Comment thread package.json
Comment on lines +21 to +26

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.

high

These new export entries correctly map to the expected JavaScript files in the dist/ directory, corresponding to the newly organized TypeScript source files in src/.

However, I notice that tsdown.config.ts includes the exports: true option (line 15 in the full tsdown.config.ts file). According to tsdown documentation, this option should automatically generate the exports field in package.json based on the entry points defined (now "./src/*.ts").

Could you clarify if these manual additions to package.json#exports are necessary?

  • If tsdown can auto-generate these, relying on that might simplify package.json maintenance and ensure consistency between defined entry points and exported paths.
  • If tsdown's auto-generation overwrites these manual entries, there's a risk of the final package.json not matching what's committed if the generation logic differs slightly.

Understanding how exports: true interacts with these manual entries, especially during the prepack script which involves tsdown and other package.json manipulation tools, is important for ensuring the package's public API is correctly and reliably defined.

ryoppippi added a commit that referenced this pull request Jun 22, 2025
chore: move files under src directory
qianhaoq pushed a commit to qianhaoq/ccusage that referenced this pull request Mar 29, 2026
- Compute codexTotals from unsorted codexRowsRaw so sort order never
  affects aggregation (ccusage#1)
- Add comments documenting the since/until normalization asymmetry
  between Claude and Codex sides (ccusage#2)
- Remove codexDisplayTotals accumulator; derive table totals row from
  codexTotals via splitUsageTokens (single source of truth) (ccusage#3)
- Remove redundant `?? undefined` in locale cast (ccusage#7)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jay-tau added a commit to jay-tau/ccusage that referenced this pull request Jun 7, 2026
…e comments

External PR ccusage#1209 code review identified the single recommended
maintainer gate before merge: strip references to ephemeral, private
development artifacts ("plan finding #N", "GPT-5.5 R12/R14",
"Piece B/C", "round-1/2 finding", "plan round-3 finding",
"seq-7 round-1B") from shipped code. These were meaningful to the
author during the iterative development + multi-model review process,
but read as noise (or confusion) to a future maintainer six months out.

Preserve the substance of every comment — what the code does and why
— while dropping the development-internal identifiers:
- `plan finding ccusage#10` → "Aggregate-only credits path:"
- `plan finding from PR ccusage#957 + GPT-5.5 R12` → "Skip rule for per-model
  metrics rows:" (PR ccusage#957 citation kept — external + persistent)
- `plan finding ccusage#7` → "in real session-state data"
- `plan finding #2` → (dropped — comment is self-explanatory)
- `plan finding for GPT-5.5 R14` → "Dedup key selection:"
- `plan finding ccusage#3 / Piece C carry-over from PR ccusage#957` →
  "carried over from PR ccusage#957's TypeScript implementation"
- `round-1/2 finding` → "documented invariant"
- `// ----- Piece B (credits) -----` → "AI Credits tests (totalNanoAiu)"
- `plan finding #1` → (dropped)
- `plan finding ccusage#8` → (dropped — paraphrased into the comment)
- `plan round-3 finding` → (dropped — paraphrased into the comment)
- `mirrors the seq-7 round-1B parser fixture fix` → (dropped — the
  preceding sentences already explain the genuinely-absent-vs-Some(0)
  reasoning standalone)

PR ccusage#957 references stay (external, persistent, useful for context).
External symbol/test/file references all resolve. No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jay-tau added a commit to jay-tau/ccusage that referenced this pull request Jun 9, 2026
…e comments

External PR ccusage#1209 code review identified the single recommended
maintainer gate before merge: strip references to ephemeral, private
development artifacts ("plan finding #N", "GPT-5.5 R12/R14",
"Piece B/C", "round-1/2 finding", "plan round-3 finding",
"seq-7 round-1B") from shipped code. These were meaningful to the
author during the iterative development + multi-model review process,
but read as noise (or confusion) to a future maintainer six months out.

Preserve the substance of every comment — what the code does and why
— while dropping the development-internal identifiers:
- `plan finding ccusage#10` → "Aggregate-only credits path:"
- `plan finding from PR ccusage#957 + GPT-5.5 R12` → "Skip rule for per-model
  metrics rows:" (PR ccusage#957 citation kept — external + persistent)
- `plan finding ccusage#7` → "in real session-state data"
- `plan finding #2` → (dropped — comment is self-explanatory)
- `plan finding for GPT-5.5 R14` → "Dedup key selection:"
- `plan finding ccusage#3 / Piece C carry-over from PR ccusage#957` →
  "carried over from PR ccusage#957's TypeScript implementation"
- `round-1/2 finding` → "documented invariant"
- `// ----- Piece B (credits) -----` → "AI Credits tests (totalNanoAiu)"
- `plan finding #1` → (dropped)
- `plan finding ccusage#8` → (dropped — paraphrased into the comment)
- `plan round-3 finding` → (dropped — paraphrased into the comment)
- `mirrors the seq-7 round-1B parser fixture fix` → (dropped — the
  preceding sentences already explain the genuinely-absent-vs-Some(0)
  reasoning standalone)

PR ccusage#957 references stay (external, persistent, useful for context).
External symbol/test/file references all resolve. No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jay-tau added a commit to jay-tau/ccusage that referenced this pull request Jun 10, 2026
…e comments

External PR ccusage#1209 code review identified the single recommended
maintainer gate before merge: strip references to ephemeral, private
development artifacts ("plan finding #N", "GPT-5.5 R12/R14",
"Piece B/C", "round-1/2 finding", "plan round-3 finding",
"seq-7 round-1B") from shipped code. These were meaningful to the
author during the iterative development + multi-model review process,
but read as noise (or confusion) to a future maintainer six months out.

Preserve the substance of every comment — what the code does and why
— while dropping the development-internal identifiers:
- `plan finding ccusage#10` → "Aggregate-only credits path:"
- `plan finding from PR ccusage#957 + GPT-5.5 R12` → "Skip rule for per-model
  metrics rows:" (PR ccusage#957 citation kept — external + persistent)
- `plan finding ccusage#7` → "in real session-state data"
- `plan finding #2` → (dropped — comment is self-explanatory)
- `plan finding for GPT-5.5 R14` → "Dedup key selection:"
- `plan finding ccusage#3 / Piece C carry-over from PR ccusage#957` →
  "carried over from PR ccusage#957's TypeScript implementation"
- `round-1/2 finding` → "documented invariant"
- `// ----- Piece B (credits) -----` → "AI Credits tests (totalNanoAiu)"
- `plan finding #1` → (dropped)
- `plan finding ccusage#8` → (dropped — paraphrased into the comment)
- `plan round-3 finding` → (dropped — paraphrased into the comment)
- `mirrors the seq-7 round-1B parser fixture fix` → (dropped — the
  preceding sentences already explain the genuinely-absent-vs-Some(0)
  reasoning standalone)

PR ccusage#957 references stay (external, persistent, useful for context).
External symbol/test/file references all resolve. No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jay-tau added a commit to jay-tau/ccusage that referenced this pull request Jun 11, 2026
…e comments

External PR ccusage#1209 code review identified the single recommended
maintainer gate before merge: strip references to ephemeral, private
development artifacts ("plan finding #N", "GPT-5.5 R12/R14",
"Piece B/C", "round-1/2 finding", "plan round-3 finding",
"seq-7 round-1B") from shipped code. These were meaningful to the
author during the iterative development + multi-model review process,
but read as noise (or confusion) to a future maintainer six months out.

Preserve the substance of every comment — what the code does and why
— while dropping the development-internal identifiers:
- `plan finding ccusage#10` → "Aggregate-only credits path:"
- `plan finding from PR ccusage#957 + GPT-5.5 R12` → "Skip rule for per-model
  metrics rows:" (PR ccusage#957 citation kept — external + persistent)
- `plan finding ccusage#7` → "in real session-state data"
- `plan finding #2` → (dropped — comment is self-explanatory)
- `plan finding for GPT-5.5 R14` → "Dedup key selection:"
- `plan finding ccusage#3 / Piece C carry-over from PR ccusage#957` →
  "carried over from PR ccusage#957's TypeScript implementation"
- `round-1/2 finding` → "documented invariant"
- `// ----- Piece B (credits) -----` → "AI Credits tests (totalNanoAiu)"
- `plan finding #1` → (dropped)
- `plan finding ccusage#8` → (dropped — paraphrased into the comment)
- `plan round-3 finding` → (dropped — paraphrased into the comment)
- `mirrors the seq-7 round-1B parser fixture fix` → (dropped — the
  preceding sentences already explain the genuinely-absent-vs-Some(0)
  reasoning standalone)

PR ccusage#957 references stay (external, persistent, useful for context).
External symbol/test/file references all resolve. No behavioral change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Refactor: Migrate to src/ directory structure for better project organization

2 participants