Validate and document programmatic Node.js API (Phase 1)#53
Merged
Conversation
- Change duration assertion from > 0 to >= 0 - Prevents test failures when execution is extremely fast - Duration of 0ms is valid for small test fixtures
…ation - Add eslint-disable comment for intentional control characters in regex - Regex pattern removes invalid XML 1.0 control characters as designed - Addresses ESLint compatibility with stricter control character checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validates and documents the existing programmatic API implementation for CopyTree, exposing
scan(),format(), andcopy()functions for Node.js developers to integrate file discovery and transformation into their applications.Key Discovery: The programmatic API was already partially implemented but never publicly announced or validated. This PR validates the implementation, identifies gaps through comprehensive Codex review, and documents current state transparently.
Closes #32
Changes Made
Implementation Notes
Context & Rationale
CopyTree previously had NO programmatic API - users had to spawn CLI processes or import undocumented internal modules. This PR exposes a complete, stable, typed API enabling developers to integrate CopyTree into build tools, CI/CD pipelines, documentation generators, and custom applications.
API Surface (src/index.js)
scan(),format(),copy()- Complete workflow from discovery to outputPipeline,Stage,ProfileLoader,TransformerRegistry,BaseTransformer- Advanced usageconfig()- Access to config systemcopyfor conveniencescan() API
AsyncIterable<FileResult>for memory-efficient streamingonEventcallback for pipeline eventsformat() API
Array,Iterable, orAsyncIterable<FileResult>copy() API
CopyResultwith output string, files array, and detailed statsTest Results
Critical Issues Found (Codex Review)
API Implementation Issues
1. AbortSignal doesn't actually cancel work
FileDiscoveryStageor walkerssignal.abortedand throws2. scan() is NOT actually streaming
FileDiscoveryStagecaches whole result in memory3. Documented options don't work
maxDepthoption advertised but never wired to FileDiscoveryStage/walkerssecretsReport,info,verbose,charLimitoptions in copy() typedef but never readSecretsGuardStage,CharLimitStage, but programmatic API doesn't wire themTypeScript Definition Issues
1. FileResult type incomplete
stats,binaryCategory,binaryName,excluded,excludedReason,errorcontentas alwaysstring(can beBuffer)isBinaryas mandatory (doesn't exist whenincludeContent: false)2. ScanOptions.transformers wrong type
string[]but implementation expects object keyed by transformer name3. CopyOptions includes non-functional CLI options
secretsReport,info,verbose,charLimitdocumented but not implementedTest Quality Issues
1. Tests don't verify claims
2. Missing test coverage for key features
withGitStatus,max*limiters,transformoption in scan()stream,clipboardside effects in copy()Recommendation
This API implementation is Phase 1 - functional for basic use cases but has significant gaps:
Suggested path forward:
Breaking Changes & Migration Hints
No breaking changes - This is a purely additive change. All new exports from
src/index.jsare additions, no existing APIs modified.Migration guidance for users importing internal modules:
copytree/src/commands/copy.jswithimport { copy } from 'copytree'exec('copytree --format json')→await copy('.', { format: 'json' })Follow-up Tasks
docs/api/programmatic-usage.mdwith comprehensive examplesexamples/directory (basic-scan.js, vite-plugin.js, github-action.js, custom-pipeline.js)