Skip to content

chore: move files under src directory#7

Merged
ryoppippi merged 3 commits intomainfrom
src-dirr
Jun 3, 2025
Merged

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

Conversation

@ryoppippi
Copy link
Owner

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/ryoppippi/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/ryoppippi/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/ryoppippi/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/ryoppippi/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/ryoppippi/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/ryoppippi/ccusage/pull/7/files#diff-c105f99c241d6d60e41561e663ee096629894e9b2a773c82283655b323f59485L5-R5))

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

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

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
Copy link

pkg-pr-new bot commented Jun 3, 2025

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
Copy link
Contributor

Copilot AI left a comment

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


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

Copilot AI Jun 3, 2025

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.
@@ -0,0 +1,3 @@
#!/usr/bin/env node

import "./commands/index.ts";
Copy link

Copilot AI Jun 3, 2025

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.
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";
Copy link

Copilot AI Jun 3, 2025

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.
Copy link
Contributor

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

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 on lines +21 to +26
"./debug": "./dist/debug.js",
"./logger": "./dist/logger.js",
"./pricing-fetcher": "./dist/pricing-fetcher.js",
"./shared-args": "./dist/shared-args.js",
"./types": "./dist/types.js",
"./utils": "./dist/utils.js",
Copy link
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
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