Skip to content

refactor: apply context+options function signature pattern#69

Merged
YusukeHirao merged 12 commits intomainfrom
feat/improve-function-params
Jan 31, 2026
Merged

refactor: apply context+options function signature pattern#69
YusukeHirao merged 12 commits intomainfrom
feat/improve-function-params

Conversation

@YusukeHirao
Copy link
Copy Markdown
Member

Summary

This PR applies the context+options function signature pattern to internal APIs and improves code maintainability. The pattern standardizes function signatures for better readability and extensibility.

Key Changes

3 Breaking Changes (Public APIs):

  1. computeOutputPath (kamado/path) - 4 params → context object
  2. getAssetGroup (kamado/data) - multiple params → context+options

Internal API Improvements:

  • domSerialize: (html, hook, url?) → (html, options)
  • getTitle: (page, optimizeTitle?, safe?) → (page, options?)
  • filePathColorizer: removed empty context wrapper
  • imageSizes: removed empty context wrapper
  • titleList: removed empty context wrapper
  • Server and page-compiler internal functions

Documentation:

  • Added function signature pattern rules to ARCHITECTURE.md
  • Updated monorepo-architect skill with exception cases
  • All JSDoc comments updated with examples

Test Plan

  • ✅ All 155 tests passing
  • ✅ Build successful for all packages
  • ✅ Lint checks passing (ESLint, Prettier, cspell)
  • ✅ Documentation consistency verified

Breaking Changes

computeOutputPath (kamado/path)

// Before
computeOutputPath(inputPath, inputDir, outputDir, outputExtension)

// After
computeOutputPath({
  inputPath,
  inputDir,
  outputDir,
  outputExtension,
})

getAssetGroup (kamado/data)

// Before
getAssetGroup({ inputDir, outputDir, compilerEntry, glob? })

// After
getAssetGroup(
  { inputDir, outputDir, compilerEntry },
  { glob? }
)

Migration Guide

Update function calls to use the new signatures. All changes are type-safe and will be caught by TypeScript.

🤖 Generated with Claude Code

YusukeHirao and others added 12 commits January 31, 2026 02:18
…nternal functions

Apply monorepo-architect function signature rule to 8 internal functions:
- transpile: split into TranspileContext + TranspileOptions
- transpileMainContent: add TranspileMainContext + TranspileMainOptions
- transpileLayout: add TranspileLayoutContext + TranspileLayoutOptions
- formatHtml: split FormatHtmlContext + FormatHtmlOptions
- imageSizes: add ImageSizesContext
- titleList: add TitleListContext
- getBreadcrumbs: add GetBreadcrumbsContext
- getNavTree: add GetNavTreeContext

Public API unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…unctions

Apply monorepo-architect function signature rule to 2 internal functions:
- applyTransforms: split into ApplyTransformsContext + ApplyTransformsOptions
- setRoute: split into SetRouteContext + SetRouteOptions

Updated all call sites and tests. Public API unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…Colorizer

Apply monorepo-architect function signature rule to filePathColorizer:
- Split into FilePathColorizerContext (rootDir) + FilePathColorizerOptions (cwd, enable, colors)

Updated all call sites in:
- server/route.ts
- builder/build.ts
- stdout/color.spec.ts

Public API unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…hitect skill

Add exception cases for context+options pattern:
- Do not apply when all parameters are optional
- Do not apply to public API functions (builder/factory functions)
- Do not apply to simple functions with 1-2 required params

This clarifies that the pattern is for internal APIs only and prevents
forcing empty context objects.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
BREAKING CHANGE: getAssetGroup function signature changed from
getAssetGroup(options) to getAssetGroup(context, options?).

Before:
  getAssetGroup({
    inputDir: '/path',
    outputDir: '/path',
    compilerEntry: {...},
    glob: '**/*.html'
  })

After:
  getAssetGroup(
    { inputDir: '/path', outputDir: '/path', compilerEntry: {...} },
    { glob: '**/*.html' }
  )

- Split GetAssetsOptions into GetAssetGroupContext + GetAssetGroupOptions
- Update internal call sites in build.ts and assets.spec.ts
- All 155 tests passing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…orizer

Apply exception rule: functions with only 1 required parameter should not
use context+options pattern.

Before:
  filePathColorizer({ rootDir: './src' }, options)

After:
  filePathColorizer('./src', options)

- Remove FilePathColorizerContext interface
- Update function signature to take rootDir directly
- Update all call sites in build.ts, route.ts, and tests

All tests passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…eSizes

Apply exception rule: functions with only 1 required parameter should not
use context+options pattern.

Before:
  imageSizes({ elements: [...] }, options)

After:
  imageSizes([...], options)

- Remove ImageSizesContext interface
- Update function signature to take elements directly
- Update call site in format.ts

All tests passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…eList

Apply exception rule: functions with only 1 required parameter should not
use context+options pattern.

Before:
  titleList({ breadcrumbs: [...] }, options)

After:
  titleList([...], options)

- Remove TitleListContext interface
- Update function signature to take breadcrumbs directly
- Update call site in page-compiler.ts

All tests passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive documentation for the context+options function signature
pattern and its exception cases.

Changes:
- Add section 5 "Function Signature Pattern" to ARCHITECTURE.md
- Add section 5 "関数シグネチャパターン" to ARCHITECTURE.ja.md
- Document when to apply and when NOT to apply the pattern
- Include judgment criteria and code examples

Context+options pattern rules:
- Apply: 2+ required parameters and already receives object
- Don't apply: 1 required parameter, all optional, public API, or primitives

This documents the architectural decisions from recent refactoring commits:
- a602d92 (getAssetGroup)
- 85c3309 (filePathColorizer)
- 694c0d7 (imageSizes)
- cb3adc4 (titleList)

All 155 tests passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
BREAKING CHANGE: computeOutputPath now takes a single context object
instead of 4 separate parameters

- Add ComputeOutputPathContext interface to types.ts
- Update computeOutputPath signature (4 params → context object)
- Update call site in get-file.ts
- Update JSDoc example code
- Update 9 test cases in output-path.spec.ts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add DomSerializeOptions interface to utils/dom.ts
- Update domSerialize signature (html + options)
- Update call site in page-compiler/format.ts
- Update JSDoc with example

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add GetTitleOptions interface to types.ts
- Update getTitle signature (page + options)
- Update call sites in get-global-data.ts and breadcrumbs.ts
- Update deprecated/title.ts for consistency
- Update JSDoc with examples

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@YusukeHirao YusukeHirao merged commit 6572750 into main Jan 31, 2026
1 check passed
@YusukeHirao YusukeHirao deleted the feat/improve-function-params branch January 31, 2026 07:46
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