Skip to content

breaking! feat: add CLI interface for format-css package#170

Open
bartveneman wants to merge 7 commits intomainfrom
claude/css-formatter-cli-uwnFp
Open

breaking! feat: add CLI interface for format-css package#170
bartveneman wants to merge 7 commits intomainfrom
claude/css-formatter-cli-uwnFp

Conversation

@bartveneman
Copy link
Member

@bartveneman bartveneman commented Mar 18, 2026

Summary

This PR adds a command-line interface (CLI) to the format-css package, allowing users to format CSS files directly from the terminal.

Key Changes

  • New CLI module (src/cli/cli.ts): Implements a complete command-line interface with support for:

    • Formatting CSS files passed as arguments
    • Reading CSS from stdin for pipe operations
    • --minify flag to minify CSS output
    • --tab-size=<n> option to customize indentation
    • --help / -h flag with formatted usage documentation
    • Proper error handling and exit codes
  • Build configuration (tsdown.config.ts): Updated to build both the library and CLI:

    • Converted from single entry point to multi-entry configuration
    • Added separate build target for CLI with Node.js platform
    • Configured CLI to reference the main package as external to avoid duplication
  • Package metadata (package.json): Added bin field to register the format-css command, making it available as an executable when installed globally or locally

Implementation Details

  • The CLI intelligently detects input source: file arguments, stdin pipe, or displays help if neither is provided
  • Uses Node.js built-in utilities (parseArgs, styleText) for argument parsing and formatted output
  • Validates --tab-size parameter to ensure it's a positive integer
  • Properly handles async stdin reading for piped input
  • Includes comprehensive help text with usage examples

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh

Breaking because the supported node version went from >=18.0.0 to >=20.12.0

Implements a CLI entrypoint that formats CSS files via stdin or file
arguments, supporting --minify and --tab-size options with built-in
help. Follows the lib/cli split pattern from css-code-coverage: separate
tsdown entries, CLI platform set to node, lib marked as external to
avoid duplication.

Closes #123

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 75.55556% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.98%. Comparing base (9be1afb) to head (4f2bdc9).

Files with missing lines Patch % Lines
src/cli/cli.ts 75.55% 10 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #170      +/-   ##
===========================================
- Coverage   100.00%   96.98%   -3.02%     
===========================================
  Files            1        2       +1     
  Lines          320      365      +45     
  Branches       112      124      +12     
===========================================
+ Hits           320      354      +34     
- Misses           0       10      +10     
- Partials         0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Bundle Report

Changes will increase total bundle size by 2.77kB (11.2%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
formatCssCli-esm 2.77kB 2.77kB (100%) ⬆️⚠️

claude added 6 commits March 18, 2026 15:35
Reject any file path that resolves outside the current working
directory, matching the same guard used in css-code-coverage.

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
Refactors cli.ts to export parse_arguments() and run() with a CliIO
dependency injection interface, making both independently testable.
Guards top-level execution behind import.meta.url so importing the
module in tests does not trigger stdin reads.

Adds 23 tests covering argument validation (tab-size, minify, path
traversal), help output, stdin/file/TTY routing, and formatting options.
Aliases @projectwallace/format-css to the source entry in vitest config
so tests run without a prior build step.

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
tsdown outputs dist/cli.mjs for node platform builds, but package.json
was pointing to dist/cli.js, causing publint to fail.

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
styleText (node:util) was introduced in Node 20.12.0, making that the
actual minimum supported version. The previous >=18.0.0 was too low.

https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
@bartveneman bartveneman changed the title Add CLI interface for format-css package breaking! feat: add CLI interface for format-css package Mar 18, 2026
@bartveneman bartveneman marked this pull request as ready for review March 18, 2026 16:08
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