Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5a4e8fc
fix: enhance ShellOptions and RunOptions to support generic error han…
mildronize Nov 8, 2025
dffd8aa
feat: add basic example for Shell usage
mildronize Nov 8, 2025
c1ff5d4
feat: enhance Shell class with configurable output modes and improved…
mildronize Nov 8, 2025
748597d
feat: refactor Shell class to use createShell factory function and im…
mildronize Nov 8, 2025
6149c5a
fix: update RunOptions to extend ShellExecaOptions for better compati…
mildronize Nov 8, 2025
9184411
refactor: simplify ShellOptions and RunOptions interfaces for improve…
mildronize Nov 8, 2025
9c60fcf
fix: update example to use 'capture' output mode for consistency
mildronize Nov 8, 2025
9941c38
refactor: enhance documentation and examples in Shell class for clari…
mildronize Nov 8, 2025
d02e5ef
fix: update SafeResult and Shell class to remove isError flag for imp…
mildronize Nov 8, 2025
70c6765
fix: update RunResult and SafeResult to replace isSuccess with succes…
mildronize Nov 8, 2025
ad7bff2
docs: enhance CLAUDE.md and README.md with detailed Shell class metho…
mildronize Nov 8, 2025
648dca4
fix: update Shell test cases to replace isSuccess and isError with su…
mildronize Nov 8, 2025
56f5866
feat: add standard schema validation support in Shell class and new s…
mildronize Nov 8, 2025
981abca
feat: add example scripts for shell command execution and parsing wit…
mildronize Nov 8, 2025
38091dc
feat: add safeRunParse method to Shell class for enhanced command out…
mildronize Nov 8, 2025
e8406f7
feat: add example script for safeRunParse method demonstrating comman…
mildronize Nov 8, 2025
aac5f09
feat: add example script demonstrating safeRun method usage with comm…
mildronize Nov 8, 2025
13f8172
feat: enhance README with schema validation examples for JSON output …
mildronize Nov 8, 2025
24827c5
feat: update Shell class documentation to emphasize createShell facto…
mildronize Nov 8, 2025
ac3c678
feat: update README to recommend createShell factory function for imp…
mildronize Nov 8, 2025
3c234b1
feat: enhance verbose logging in Shell class for command execution an…
mildronize Nov 8, 2025
c247329
feat: remove outdated documentation comments from Shell class
mildronize Nov 8, 2025
fd628ee
feat: standardize shell options formatting and update test cases for …
mildronize Nov 8, 2025
9c5630f
feat: implement custom logging interface for Shell class and update t…
mildronize Nov 8, 2025
edfa957
feat: rename defaultOutputMode to outputMode in Shell class for clarity
mildronize Nov 8, 2025
c3a6d89
feat: add deepmerge for execaOptions in Shell class and enhance tests…
mildronize Nov 8, 2025
f5d9a6e
feat: enhance documentation for execaOptions and logger in Shell clas…
mildronize Nov 8, 2025
2a943b1
feat: add comprehensive tests for Shell class including schema valida…
mildronize Nov 8, 2025
1365d86
feat: enhance README with detailed descriptions for logger and execaO…
mildronize Nov 8, 2025
ed49ae2
docs(changeset): Refactor Shell Option, More Type Safety, Meaningful …
mildronize Nov 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chubby-cups-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@thaitype/shell': major
---

Refactor Shell Option, More Type Safety, Meaningful Option, Support Run with Standard Schema which provide type-safety command line
33 changes: 27 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,25 @@ src/

### Shell Class Design

The `Shell` class (`src/shell.ts`) is the only export and implements:
The `Shell` class (`src/shell.ts`) provides three public methods:

1. **`run()`** - Recommended for most use cases. Throws on error.
- Returns `StrictResult` with stdout and stderr only
- Command either succeeds or throws an exception

2. **`safeRun()`** - Never throws. Returns error result instead.
- Returns `SafeResult` with stdout, stderr, exitCode, and success flag
- Always succeeds, check `result.success` to determine outcome

3. **`execute()`** - Low-level method with explicit throwOnError control
- Pass `{ throwOnError: true }` for run() behavior
- Pass `{ throwOnError: false }` for safeRun() behavior

**Implementation Details:**

1. **Output Modes** - Three strategies for handling stdout/stderr:
- `capture`: Pipes output for programmatic access (default)
- `live`: Inherits stdio, streams to console in real-time
- `live`: Inherits stdio, streams to console in real-time (returns null for stdout/stderr)
- `all`: Combines both - captures AND streams simultaneously

Implementation detail: Maps output modes to execa stdio configuration using a `stdioMap` object
Expand All @@ -50,9 +64,10 @@ The `Shell` class (`src/shell.ts`) is the only export and implements:

### Key Interfaces

- `ShellOptions`: Constructor configuration (defaultOutputMode, dryRun, verbose, throwOnError, throwMode, logger)
- `ShellOptions`: Constructor configuration (defaultOutputMode, dryRun, verbose, throwMode, logger)
- `RunOptions`: Per-command overrides, extends `ExecaOptions` from execa
- `RunResult`: Structured return value (stdout, stderr, exitCode, isError, isSuccess)
- `StrictResult`: Return type for `run()` (stdout, stderr)
- `SafeResult`: Return type for `safeRun()` (stdout, stderr, exitCode, success)

## Development Commands

Expand All @@ -73,9 +88,10 @@ The build uses Babel's `annotate-pure-calls` plugin for better tree-shaking.
pnpm test # Run tests in watch mode (Vitest)
pnpm test:ci # Run tests once (for CI)
pnpm test:coverage # Generate coverage report
pnpm test:coverage:feedback # Run coverage with detailed feedback on uncovered lines
```

Note: Currently no test files exist in the repository. Tests should be added as `*.test.ts` or `*.spec.ts` files (they're excluded from builds).
Tests are located in `test/shell.test.ts` and focus on Shell class logic (not execa features).

### Linting & Type Checking
```bash
Expand Down Expand Up @@ -115,7 +131,12 @@ this.logger?.(`$ ${args.join(' ')}`);
```

### Error Handling Strategy
When catching `ExecaError`, the class checks `throwOnError` before re-throwing. If disabled, it returns a `RunResult` with `isError: true` instead of throwing.
Three approaches to error handling:
- `run()`: Always throws on error (uses `reject: true` in execa)
- `safeRun()`: Never throws, returns result with `success: false` (uses `reject: false` in execa)
- `execute({ throwOnError })`: Explicit control over throw behavior

When using `safeRun()` or `execute({ throwOnError: false })`, check `result.success` to determine if the command succeeded.

### Stdio Configuration
Output modes are implemented by mapping to execa's stdio arrays:
Expand Down
Loading