tryscript 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -51
- package/dist/bin.cjs +245 -17
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.mjs +243 -15
- package/dist/bin.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +1 -1
- package/dist/{src-CndHSuTT.mjs → src-BBeKy_V9.mjs} +16 -4
- package/dist/src-BBeKy_V9.mjs.map +1 -0
- package/dist/{src-CxUUK92Q.cjs → src-rTwoOhL4.cjs} +16 -4
- package/dist/src-rTwoOhL4.cjs.map +1 -0
- package/docs/tryscript-reference.md +203 -8
- package/package.json +8 -3
- package/dist/src-CndHSuTT.mjs.map +0 -1
- package/dist/src-CxUUK92Q.cjs.map +0 -1
package/dist/bin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.cjs","names":["pc","pc","status","parts: string[]","changes: string[]","lines: string[]","resolveCoverageConfig","loadConfig","coverageCtx: CoverageContext | undefined","coverageEnv: Record<string, string>","fileResults: TestFileResult[]","parseTestFile","mergeConfig","createExecutionContext","results: TestBlockResult[]","runBlock","matchOutput","runAfterHook","cleanupExecutionContext","fileResult: TestFileResult","statusIndicators","summary: TestRunSummary","formatMarkdown","formatted: string[]","pc","isInteractive","formatted: string[]","pc","Command","VERSION"],"sources":["../src/cli/lib/shared.ts","../src/lib/reporter.ts","../src/lib/updater.ts","../src/lib/coverage.ts","../src/cli/commands/run.ts","../src/cli/commands/readme.ts","../src/cli/commands/docs.ts","../src/cli/cli.ts","../src/bin.ts"],"sourcesContent":["/**\n * Shared CLI utilities for consistent output formatting and color usage.\n *\n * This module provides:\n * - Color utilities via picocolors\n * - Commander.js help text styling\n * - Logging helpers for consistent output\n */\n\nimport type { Command } from 'commander';\nimport pc from 'picocolors';\n\n/**\n * Shared color utilities for consistent terminal output.\n */\nexport const colors = {\n success: (s: string) => pc.green(s),\n error: (s: string) => pc.red(s),\n info: (s: string) => pc.cyan(s),\n warn: (s: string) => pc.yellow(s),\n muted: (s: string) => pc.gray(s),\n bold: (s: string) => pc.bold(s),\n};\n\n/**\n * Status indicators with emoji.\n */\nexport const status = {\n pass: pc.green('✓'),\n fail: pc.red('✗'),\n skip: pc.yellow('○'),\n update: pc.yellow('↻'),\n};\n\n/**\n * Configure Commander.js with colored help text.\n * Applies consistent styling: cyan titles, green commands, yellow options.\n */\nexport function withColoredHelp<T extends Command>(cmd: T): T {\n cmd.configureHelp({\n styleTitle: (str) => pc.bold(pc.cyan(str)),\n styleCommandText: (str) => pc.green(str),\n styleOptionText: (str) => pc.yellow(str),\n showGlobalOptions: true,\n });\n return cmd;\n}\n\n/**\n * Format a duration in milliseconds for display.\n */\nexport function formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n }\n return `${(ms / 1000).toFixed(2)}s`;\n}\n\n/**\n * Log an informational message to stderr.\n */\nexport function logInfo(message: string): void {\n console.error(colors.info(message));\n}\n\n/**\n * Log a success message to stderr.\n */\nexport function logSuccess(message: string): void {\n console.error(colors.success(message));\n}\n\n/**\n * Log a warning message to stderr.\n */\nexport function logWarn(message: string): void {\n console.error(colors.warn(message));\n}\n\n/**\n * Log an error message to stderr.\n */\nexport function logError(message: string): void {\n console.error(colors.error(message));\n}\n\n/**\n * Log timing information with emoji.\n */\nexport function logTiming(label: string, durationMs: number): void {\n console.error(colors.info(`⏰ ${label}: ${formatDuration(durationMs)}`));\n}\n","/**\n * Test result reporting utilities.\n *\n * Handles output formatting for test results, diffs, and summaries.\n */\n\nimport pc from 'picocolors';\nimport { createPatch } from 'diff';\nimport type { TestFileResult, TestRunSummary } from './types.js';\n\nexport interface ReporterOptions {\n diff: boolean;\n verbose: boolean;\n quiet: boolean;\n}\n\n// Status indicators for consistent output\nconst statusIcon = {\n pass: pc.green('✓'),\n fail: pc.red('✗'),\n};\n\n/**\n * Format a duration in milliseconds for display.\n */\nfunction formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n }\n return `${(ms / 1000).toFixed(2)}s`;\n}\n\n/**\n * Create a unified diff between expected and actual output.\n */\nexport function createDiff(expected: string, actual: string, filename: string): string {\n const patch = createPatch(filename, expected, actual, 'expected', 'actual');\n // Remove the header lines (first 4 lines)\n const lines = patch.split('\\n').slice(4);\n return lines\n .map((line) => {\n if (line.startsWith('+')) {\n return pc.green(line);\n }\n if (line.startsWith('-')) {\n return pc.red(line);\n }\n if (line.startsWith('@')) {\n return pc.cyan(line);\n }\n return line;\n })\n .join('\\n');\n}\n\n/**\n * Report results for a single file.\n */\nexport function reportFile(result: TestFileResult, options: ReporterOptions): void {\n const filename = result.file.path;\n const status = result.passed ? pc.green(pc.bold('PASS')) : pc.red(pc.bold('FAIL'));\n\n if (options.quiet && result.passed) {\n return;\n }\n\n // File header\n console.error(`${status} ${filename}`);\n\n // Individual block results\n for (const blockResult of result.results) {\n const name = blockResult.block.name ?? `Line ${blockResult.block.lineNumber}`;\n\n if (blockResult.passed) {\n if (!options.quiet) {\n console.error(` ${statusIcon.pass} ${name}`);\n }\n } else {\n console.error(` ${statusIcon.fail} ${name}`);\n\n // Show error details\n if (blockResult.error) {\n console.error(` ${pc.red(blockResult.error)}`);\n } else {\n // Exit code mismatch\n if (blockResult.actualExitCode !== blockResult.block.expectedExitCode) {\n console.error(\n ` Expected exit code ${blockResult.block.expectedExitCode}, got ${blockResult.actualExitCode}`,\n );\n }\n\n // Output mismatch with diff\n if (options.diff && blockResult.diff) {\n console.error('');\n console.error(blockResult.diff);\n }\n }\n }\n }\n\n console.error('');\n}\n\n/**\n * Report final summary.\n */\nexport function reportSummary(summary: TestRunSummary, _options: ReporterOptions): void {\n const parts: string[] = [];\n\n if (summary.totalPassed > 0) {\n parts.push(pc.green(`${summary.totalPassed} passed`));\n }\n if (summary.totalFailed > 0) {\n parts.push(pc.red(`${summary.totalFailed} failed`));\n }\n\n const duration = formatDuration(summary.duration);\n const line = `${parts.join(', ')} (${duration})`;\n\n // Summary goes to stdout (can be piped/parsed)\n console.log(line);\n}\n","import { writeFile } from 'atomically';\nimport type { TestFile, TestBlock, TestBlockResult } from './types.js';\n\n/**\n * Update a test file with actual output from test results.\n */\nexport async function updateTestFile(\n file: TestFile,\n results: TestBlockResult[],\n): Promise<{ updated: boolean; changes: string[] }> {\n let content = file.rawContent;\n const changes: string[] = [];\n\n // Process blocks in reverse order to maintain correct offsets\n const blocksWithResults = file.blocks\n .map((block, i) => ({ block, result: results[i] }))\n .reverse();\n\n for (const { block, result } of blocksWithResults) {\n if (!result) {\n continue;\n }\n\n if (result.passed) {\n continue; // Don't touch passing tests\n }\n\n if (result.error) {\n // Execution error, can't update\n continue;\n }\n\n // Build the new block content\n const newBlockContent = buildUpdatedBlock(block, result);\n\n // Find and replace the block in the file\n const blockStart = content.indexOf(block.rawContent);\n if (blockStart !== -1) {\n content =\n content.slice(0, blockStart) +\n newBlockContent +\n content.slice(blockStart + block.rawContent.length);\n\n changes.push(block.name ?? `Line ${block.lineNumber}`);\n }\n }\n\n if (changes.length > 0) {\n await writeFile(file.path, content);\n }\n\n return { updated: changes.length > 0, changes };\n}\n\n/**\n * Build an updated console block with new expected output.\n */\nfunction buildUpdatedBlock(block: TestBlock, result: TestBlockResult): string {\n // Reconstruct the command line(s)\n const commandLines = block.command.split('\\n').map((line, i) => {\n return i === 0 ? `$ ${line}` : `> ${line}`;\n });\n\n // Build the block\n const lines: string[] = ['```console', ...commandLines];\n\n // Add output if present\n const trimmedOutput = result.actualOutput.trimEnd();\n if (trimmedOutput) {\n lines.push(trimmedOutput);\n }\n\n // Add exit code\n lines.push(`? ${result.actualExitCode}`, '```');\n\n return lines.join('\\n');\n}\n","/**\n * Coverage collection for CLI subprocess testing.\n *\n * Uses c8 and NODE_V8_COVERAGE to collect coverage from spawned processes.\n */\n\nimport { spawn } from 'node:child_process';\nimport { mkdtemp, rm, access } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport type { CoverageContext, CoverageConfig } from './types.js';\nimport { resolveCoverageConfig } from './config.js';\n\n/**\n * Find the c8 executable path.\n * Checks local node_modules/.bin first, then falls back to npx.\n */\nfunction findC8Path(): string {\n // Check common locations for local c8\n const localPaths = [\n resolve(process.cwd(), 'node_modules', '.bin', 'c8'),\n resolve(process.cwd(), '..', '..', 'node_modules', '.bin', 'c8'), // monorepo root\n ];\n\n for (const localPath of localPaths) {\n if (existsSync(localPath)) {\n return localPath;\n }\n }\n\n // Fall back to npx which will find c8 in node_modules\n return 'npx c8';\n}\n\n/**\n * Check if c8 is available in the current environment.\n */\nexport async function isC8Available(): Promise<boolean> {\n const c8Path = findC8Path();\n\n return new Promise((resolve) => {\n // Use npx to run c8 if we fell back to npx\n const isNpx = c8Path === 'npx c8';\n const command = isNpx ? 'npx' : c8Path;\n const args = isNpx ? ['c8', '--version'] : ['--version'];\n\n const proc = spawn(command, args, {\n shell: false,\n stdio: 'ignore',\n });\n proc.on('close', (code) => {\n resolve(code === 0);\n });\n proc.on('error', () => {\n resolve(false);\n });\n });\n}\n\n/**\n * Create a coverage context for collecting V8 coverage data.\n */\nexport async function createCoverageContext(config?: CoverageConfig): Promise<CoverageContext> {\n const options = resolveCoverageConfig(config);\n const tempDir = await mkdtemp(join(tmpdir(), 'tryscript-coverage-'));\n\n return {\n tempDir,\n options,\n };\n}\n\n/**\n * Get environment variables for enabling V8 coverage in spawned processes.\n */\nexport function getCoverageEnv(ctx: CoverageContext): Record<string, string> {\n return {\n NODE_V8_COVERAGE: ctx.tempDir,\n };\n}\n\n/**\n * Generate coverage report from collected V8 coverage data using c8.\n * Throws an error if coverage report generation fails.\n */\nexport async function generateCoverageReport(ctx: CoverageContext): Promise<void> {\n const { options, tempDir } = ctx;\n const c8Path = findC8Path();\n\n // Base args for c8 report\n const reportArgs = [\n 'report',\n '--temp-directory',\n tempDir,\n '--reports-dir',\n options.reportsDir,\n '--src',\n options.src,\n '--all',\n ...options.include.flatMap((pattern) => ['--include', pattern]),\n ...options.reporters.flatMap((reporter) => ['--reporter', reporter]),\n ];\n\n // Handle 'npx c8' vs direct c8 path\n // Use shell: false to prevent glob expansion of patterns like dist/**\n const isNpx = c8Path === 'npx c8';\n const command = isNpx ? 'npx' : c8Path;\n const args = isNpx ? ['c8', ...reportArgs] : reportArgs;\n\n await new Promise<void>((resolvePromise, reject) => {\n const proc = spawn(command, args, {\n shell: false,\n stdio: 'inherit',\n });\n\n proc.on('close', (code) => {\n if (code === 0) {\n resolvePromise();\n } else {\n reject(new Error(`c8 report exited with code ${code}`));\n }\n });\n\n proc.on('error', (err) => {\n reject(new Error(`Failed to run c8 report: ${err.message}`));\n });\n });\n}\n\n/**\n * Clean up coverage context by removing the temporary directory.\n */\nexport async function cleanupCoverageContext(ctx: CoverageContext): Promise<void> {\n try {\n await access(ctx.tempDir);\n await rm(ctx.tempDir, { recursive: true, force: true });\n } catch {\n // Directory doesn't exist, nothing to clean up\n }\n}\n","/**\n * Run command - executes golden tests against CLI applications.\n *\n * Supports filtering, update mode, and detailed diff output for failures.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFile } from 'node:fs/promises';\nimport fg from 'fast-glob';\nimport { loadConfig, mergeConfig } from '../../lib/config.js';\nimport { logWarn, logError, colors, status as statusIndicators } from '../lib/shared.js';\nimport { parseTestFile } from '../../lib/parser.js';\nimport {\n runBlock,\n createExecutionContext,\n cleanupExecutionContext,\n runAfterHook,\n} from '../../lib/runner.js';\nimport { matchOutput } from '../../lib/matcher.js';\nimport { createDiff, reportFile, reportSummary } from '../../lib/reporter.js';\nimport { updateTestFile } from '../../lib/updater.js';\nimport {\n isC8Available,\n createCoverageContext,\n getCoverageEnv,\n generateCoverageReport,\n cleanupCoverageContext,\n} from '../../lib/coverage.js';\nimport type {\n TestBlockResult,\n TestFileResult,\n TestRunSummary,\n CoverageContext,\n} from '../../lib/types.js';\n\ninterface RunOptions {\n update?: boolean;\n diff?: boolean;\n failFast?: boolean;\n filter?: string;\n verbose?: boolean;\n quiet?: boolean;\n coverage?: boolean;\n coverageDir?: string;\n coverageReporter?: string[];\n}\n\n/**\n * Register the run command.\n */\nexport function registerRunCommand(program: Command): void {\n program\n .command('run')\n .description('Run golden tests')\n .argument('[files...]', 'Test files to run (default: **/*.tryscript.md)')\n .option('--update', 'Update golden files with actual output')\n .option('--diff', 'Show diff on failure (default: true)')\n .option('--no-diff', 'Hide diff on failure')\n .option('--fail-fast', 'Stop on first failure')\n .option('--filter <pattern>', 'Filter tests by name pattern')\n .option('--verbose', 'Show detailed output including passing test output')\n .option('--quiet', 'Suppress non-essential output (only show failures)')\n .option('--coverage', 'Enable code coverage collection (requires c8)')\n .option('--coverage-dir <dir>', 'Coverage output directory (default: coverage-tryscript)')\n .option(\n '--coverage-reporter <reporter...>',\n 'Coverage reporters (default: text, html). Can be specified multiple times.',\n )\n .action(runCommand);\n}\n\nasync function runCommand(files: string[], options: RunOptions): Promise<void> {\n const startTime = Date.now();\n\n // Default options\n const opts = {\n diff: options.diff !== false,\n verbose: options.verbose ?? false,\n quiet: options.quiet ?? false,\n update: options.update ?? false,\n failFast: options.failFast ?? false,\n filter: options.filter,\n };\n\n // Find test files (fast-glob respects .gitignore by default)\n const patterns = files.length > 0 ? files : ['**/*.tryscript.md'];\n const testFiles = await fg(patterns, {\n ignore: ['**/node_modules/**', '**/dist/**'],\n absolute: true,\n dot: false,\n });\n\n if (testFiles.length === 0) {\n logWarn('No test files found');\n process.exit(1);\n }\n\n // Load global config\n const globalConfig = await loadConfig(process.cwd());\n\n // Setup coverage if enabled\n let coverageCtx: CoverageContext | undefined;\n let coverageEnv: Record<string, string> = {};\n\n if (options.coverage) {\n // Check if c8 is available\n const c8Available = await isC8Available();\n if (!c8Available) {\n logError('Coverage requires c8. Install with: npm install -D c8');\n process.exit(1);\n }\n\n // Create coverage context with CLI options overriding config\n coverageCtx = await createCoverageContext({\n ...globalConfig.coverage,\n reportsDir: options.coverageDir ?? globalConfig.coverage?.reportsDir,\n reporters: options.coverageReporter ?? globalConfig.coverage?.reporters,\n });\n coverageEnv = getCoverageEnv(coverageCtx);\n }\n\n // Run tests\n const fileResults: TestFileResult[] = [];\n let shouldStop = false;\n\n for (const filePath of testFiles) {\n if (shouldStop) {\n break;\n }\n\n const content = await readFile(filePath, 'utf-8');\n const testFile = parseTestFile(content, filePath);\n const config = mergeConfig(globalConfig, testFile.config);\n\n // Filter blocks by name if specified\n let blocksToRun = testFile.blocks;\n if (opts.filter) {\n const filterPattern = new RegExp(opts.filter, 'i');\n blocksToRun = blocksToRun.filter((b) => (b.name ? filterPattern.test(b.name) : true));\n }\n\n // Handle \"only\" mode - if any block has only=true, run only those\n const onlyBlocks = blocksToRun.filter((b) => b.only);\n if (onlyBlocks.length > 0) {\n blocksToRun = onlyBlocks;\n }\n\n if (blocksToRun.length === 0) {\n continue;\n }\n\n const ctx = await createExecutionContext(config, filePath, coverageEnv);\n const results: TestBlockResult[] = [];\n\n try {\n for (const block of blocksToRun) {\n const result = await runBlock(block, ctx);\n\n // Skip checking for skipped tests\n if (result.skipped) {\n results.push(result);\n continue;\n }\n\n // Check if output matches expected\n // [ROOT] = test file directory, [CWD] = command working directory\n // If expectedStderr is set, compare stdout only (not combined output)\n const outputToCheck = block.expectedStderr\n ? (result.actualStdout ?? '')\n : result.actualOutput;\n const outputMatches = matchOutput(\n outputToCheck,\n block.expectedOutput,\n { root: ctx.testDir, cwd: ctx.cwd },\n config.patterns ?? {},\n );\n\n // Check stderr if expected (using actualStderr if available)\n let stderrMatches = true;\n if (block.expectedStderr) {\n stderrMatches = matchOutput(\n result.actualStderr ?? '',\n block.expectedStderr,\n { root: ctx.testDir, cwd: ctx.cwd },\n config.patterns ?? {},\n );\n }\n\n const exitCodeMatches = result.actualExitCode === block.expectedExitCode;\n result.passed = outputMatches && stderrMatches && exitCodeMatches && !result.error;\n\n if (!result.passed && opts.diff) {\n result.diff = createDiff(\n block.expectedOutput,\n result.actualOutput,\n `${filePath}:${block.lineNumber}`,\n );\n }\n\n results.push(result);\n\n if (!result.passed && opts.failFast) {\n shouldStop = true;\n break;\n }\n }\n\n // Run after hook if configured\n await runAfterHook(ctx);\n } finally {\n await cleanupExecutionContext(ctx);\n }\n\n const fileResult: TestFileResult = {\n file: testFile,\n results,\n passed: results.every((r) => r.passed),\n duration: results.reduce((sum, r) => sum + r.duration, 0),\n };\n\n fileResults.push(fileResult);\n reportFile(fileResult, opts);\n\n // Update mode\n if (opts.update && !fileResult.passed) {\n const { updated, changes } = await updateTestFile(testFile, results);\n if (updated) {\n console.error(colors.warn(` ${statusIndicators.update} Updated: ${changes.join(', ')}`));\n }\n }\n }\n\n // Summary\n const summary: TestRunSummary = {\n files: fileResults,\n totalPassed: fileResults.reduce((sum, f) => sum + f.results.filter((r) => r.passed).length, 0),\n totalFailed: fileResults.reduce((sum, f) => sum + f.results.filter((r) => !r.passed).length, 0),\n totalBlocks: fileResults.reduce((sum, f) => sum + f.results.length, 0),\n duration: Date.now() - startTime,\n };\n\n reportSummary(summary, opts);\n\n // Generate coverage report if enabled\n if (coverageCtx) {\n console.error('\\nGenerating coverage report...');\n try {\n await generateCoverageReport(coverageCtx);\n console.error(\n colors.success(`Coverage report written to ${coverageCtx.options.reportsDir}/`),\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logError(`Failed to generate coverage report: ${message}`);\n } finally {\n await cleanupCoverageContext(coverageCtx);\n }\n }\n\n // Exit code\n process.exit(summary.totalFailed > 0 ? 1 : 0);\n}\n","/**\n * Readme command - Display the README documentation.\n *\n * Shows the package README.md, formatted for the terminal when interactive,\n * or as plain text when piped.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport pc from 'picocolors';\n\n/**\n * Get the path to the README.md file.\n * Works both during development and when installed as a package.\n */\nfunction getReadmePath(): string {\n const thisDir = dirname(fileURLToPath(import.meta.url));\n const dirName = thisDir.split(/[/\\\\]/).pop();\n\n if (dirName === 'dist') {\n // Bundled: dist -> package root -> README.md\n return join(dirname(thisDir), 'README.md');\n }\n\n // Development: src/cli/commands -> src/cli -> src -> package root -> README.md\n return join(dirname(dirname(dirname(thisDir))), 'README.md');\n}\n\n/**\n * Load the README content.\n */\nfunction loadReadme(): string {\n const readmePath = getReadmePath();\n try {\n return readFileSync(readmePath, 'utf-8');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load README from ${readmePath}: ${message}`);\n }\n}\n\n/**\n * Apply basic terminal formatting to markdown content.\n * Colorizes headers, code blocks, and other elements for better readability.\n */\nfunction formatMarkdown(content: string, useColors: boolean): string {\n if (!useColors) {\n return content;\n }\n\n const lines = content.split('\\n');\n const formatted: string[] = [];\n let inCodeBlock = false;\n\n for (const line of lines) {\n // Track code blocks\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n formatted.push(pc.dim(line));\n continue;\n }\n\n if (inCodeBlock) {\n formatted.push(pc.dim(line));\n continue;\n }\n\n // Headers\n if (line.startsWith('# ')) {\n formatted.push(pc.bold(pc.cyan(line)));\n continue;\n }\n if (line.startsWith('## ')) {\n formatted.push(pc.bold(pc.blue(line)));\n continue;\n }\n if (line.startsWith('### ')) {\n formatted.push(pc.bold(line));\n continue;\n }\n\n // Inline code (backticks)\n let formattedLine = line.replace(/`([^`]+)`/g, (_match, code: string) => {\n return pc.yellow(code);\n });\n\n // Bold text\n formattedLine = formattedLine.replace(/\\*\\*([^*]+)\\*\\*/g, (_match, text: string) => {\n return pc.bold(text);\n });\n\n // Links - show text in cyan, URL dimmed\n formattedLine = formattedLine.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, text: string, url: string) => {\n return `${pc.cyan(text)} ${pc.dim(`(${url})`)}`;\n },\n );\n\n formatted.push(formattedLine);\n }\n\n return formatted.join('\\n');\n}\n\n/**\n * Check if stdout is an interactive terminal.\n */\nfunction isInteractive(): boolean {\n return process.stdout.isTTY === true;\n}\n\n/**\n * Display the README content.\n * Exported for use as the default command.\n */\nexport function showReadme(options?: { raw?: boolean }): void {\n try {\n const readme = loadReadme();\n\n // Determine if we should colorize\n const shouldColorize = !options?.raw && isInteractive();\n\n const formatted = formatMarkdown(readme, shouldColorize);\n console.log(formatted);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(pc.red(`Error: ${message}`));\n process.exit(1);\n }\n}\n\n/**\n * Register the readme command.\n */\nexport function registerReadmeCommand(program: Command): void {\n program\n .command('readme')\n .description('Display README documentation')\n .option('--raw', 'Output raw markdown without formatting')\n .action(showReadme);\n}\n","/**\n * Docs command - Display the tryscript quick reference.\n *\n * Shows the tryscript-reference.md file, formatted for the terminal when interactive,\n * or as plain text when piped.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport pc from 'picocolors';\n\n/**\n * Get the path to the tryscript-reference.md file.\n * Works both during development and when installed as a package.\n */\nfunction getDocsPath(): string {\n const thisDir = dirname(fileURLToPath(import.meta.url));\n const dirName = thisDir.split(/[/\\\\]/).pop();\n\n if (dirName === 'dist') {\n // Bundled: dist -> package root -> docs/tryscript-reference.md\n return join(dirname(thisDir), 'docs', 'tryscript-reference.md');\n }\n\n // Development: src/cli/commands -> src/cli -> src -> package root -> docs/tryscript-reference.md\n return join(dirname(dirname(dirname(thisDir))), 'docs', 'tryscript-reference.md');\n}\n\n/**\n * Load the docs content.\n */\nfunction loadDocs(): string {\n const docsPath = getDocsPath();\n try {\n return readFileSync(docsPath, 'utf-8');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load reference docs from ${docsPath}: ${message}`);\n }\n}\n\n/**\n * Apply basic terminal formatting to markdown content.\n * Colorizes headers, code blocks, and other elements for better readability.\n */\nfunction formatMarkdown(content: string, useColors: boolean): string {\n if (!useColors) {\n return content;\n }\n\n const lines = content.split('\\n');\n const formatted: string[] = [];\n let inCodeBlock = false;\n\n for (const line of lines) {\n // Track code blocks\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n formatted.push(pc.dim(line));\n continue;\n }\n\n if (inCodeBlock) {\n formatted.push(pc.dim(line));\n continue;\n }\n\n // Headers\n if (line.startsWith('# ')) {\n formatted.push(pc.bold(pc.cyan(line)));\n continue;\n }\n if (line.startsWith('## ')) {\n formatted.push(pc.bold(pc.blue(line)));\n continue;\n }\n if (line.startsWith('### ')) {\n formatted.push(pc.bold(line));\n continue;\n }\n\n // Inline code (backticks)\n let formattedLine = line.replace(/`([^`]+)`/g, (_match, code: string) => {\n return pc.yellow(code);\n });\n\n // Bold text\n formattedLine = formattedLine.replace(/\\*\\*([^*]+)\\*\\*/g, (_match, text: string) => {\n return pc.bold(text);\n });\n\n // Links - show text in cyan, URL dimmed\n formattedLine = formattedLine.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, text: string, url: string) => {\n return `${pc.cyan(text)} ${pc.dim(`(${url})`)}`;\n },\n );\n\n formatted.push(formattedLine);\n }\n\n return formatted.join('\\n');\n}\n\n/**\n * Check if stdout is an interactive terminal.\n */\nfunction isInteractive(): boolean {\n return process.stdout.isTTY === true;\n}\n\n/**\n * Register the docs command.\n */\nexport function registerDocsCommand(program: Command): void {\n program\n .command('docs')\n .description('Display concise syntax reference')\n .option('--raw', 'Output raw markdown without formatting')\n .action((options: { raw?: boolean }) => {\n try {\n const docs = loadDocs();\n\n // Determine if we should colorize\n const shouldColorize = !options.raw && isInteractive();\n\n const formatted = formatMarkdown(docs, shouldColorize);\n console.log(formatted);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(pc.red(`Error: ${message}`));\n process.exit(1);\n }\n });\n}\n","/**\n * CLI entry point for tryscript.\n *\n * Configures Commander.js with colored help and registers all subcommands.\n */\n\nimport { Command } from 'commander';\nimport { VERSION } from '../index.js';\nimport { registerRunCommand } from './commands/run.js';\nimport { registerReadmeCommand } from './commands/readme.js';\nimport { registerDocsCommand } from './commands/docs.js';\nimport { withColoredHelp, logError } from './lib/shared.js';\n\nexport function run(argv: string[]): void {\n const program = withColoredHelp(\n new Command()\n .name('tryscript')\n .version(VERSION, '--version', 'Show version number')\n .description('Golden testing for CLI applications')\n .showHelpAfterError('(use --help for usage)'),\n );\n\n // Register subcommands\n registerRunCommand(program);\n registerReadmeCommand(program);\n registerDocsCommand(program);\n\n // Default action: show help when no command given\n program.action(() => {\n program.help();\n });\n\n program.parseAsync(argv).catch((err: Error) => {\n logError(`Error: ${err.message}`);\n process.exit(2);\n });\n}\n","#!/usr/bin/env node\nimport { run } from './cli/cli.js';\n\nrun(process.argv);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,SAAS;CACpB,UAAU,MAAcA,mBAAG,MAAM,EAAE;CACnC,QAAQ,MAAcA,mBAAG,IAAI,EAAE;CAC/B,OAAO,MAAcA,mBAAG,KAAK,EAAE;CAC/B,OAAO,MAAcA,mBAAG,OAAO,EAAE;CACjC,QAAQ,MAAcA,mBAAG,KAAK,EAAE;CAChC,OAAO,MAAcA,mBAAG,KAAK,EAAE;CAChC;;;;AAKD,MAAa,SAAS;CACpB,MAAMA,mBAAG,MAAM,IAAI;CACnB,MAAMA,mBAAG,IAAI,IAAI;CACjB,MAAMA,mBAAG,OAAO,IAAI;CACpB,QAAQA,mBAAG,OAAO,IAAI;CACvB;;;;;AAMD,SAAgB,gBAAmC,KAAW;AAC5D,KAAI,cAAc;EAChB,aAAa,QAAQA,mBAAG,KAAKA,mBAAG,KAAK,IAAI,CAAC;EAC1C,mBAAmB,QAAQA,mBAAG,MAAM,IAAI;EACxC,kBAAkB,QAAQA,mBAAG,OAAO,IAAI;EACxC,mBAAmB;EACpB,CAAC;AACF,QAAO;;;;;AA8BT,SAAgB,QAAQ,SAAuB;AAC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AAmB,QAAQ;AAC3B,uBAAsB,QAAQ;AAC9B,qBAAoB,QAAQ;AAG5B,SAAQ,aAAa;AACnB,UAAQ,MAAM;GACd;AAEF,SAAQ,WAAW,KAAK,CAAC,OAAO,QAAe;AAC7C,WAAS,UAAU,IAAI,UAAU;AACjC,UAAQ,KAAK,EAAE;GACf;;;;;AChCJ,IAAI,QAAQ,KAAK"}
|
|
1
|
+
{"version":3,"file":"bin.cjs","names":["pc","pc","status","parts: string[]","changes: string[]","lines: string[]","findC8Path","resolveCoverageConfig","runCommand","loadConfig","coverageCtx: CoverageContext | undefined","coverageEnv: Record<string, string>","fileResults: TestFileResult[]","parseTestFile","mergeConfig","createExecutionContext","results: TestBlockResult[]","runBlock","matchOutput","runAfterHook","cleanupExecutionContext","fileResult: TestFileResult","statusIndicators","summary: TestRunSummary","parsedOptions: CoverageOptions","formatMarkdown","formatted: string[]","pc","isInteractive","formatted: string[]","pc","Command","VERSION"],"sources":["../src/cli/lib/shared.ts","../src/lib/reporter.ts","../src/lib/updater.ts","../src/lib/coverage.ts","../src/cli/commands/run.ts","../src/cli/commands/coverage.ts","../src/cli/commands/readme.ts","../src/cli/commands/docs.ts","../src/cli/cli.ts","../src/bin.ts"],"sourcesContent":["/**\n * Shared CLI utilities for consistent output formatting and color usage.\n *\n * This module provides:\n * - Color utilities via picocolors\n * - Commander.js help text styling\n * - Logging helpers for consistent output\n */\n\nimport type { Command } from 'commander';\nimport pc from 'picocolors';\n\n/**\n * Shared color utilities for consistent terminal output.\n */\nexport const colors = {\n success: (s: string) => pc.green(s),\n error: (s: string) => pc.red(s),\n warn: (s: string) => pc.yellow(s),\n info: (s: string) => pc.cyan(s),\n};\n\n/**\n * Status indicators with emoji.\n */\nexport const status = {\n pass: pc.green('✓'),\n fail: pc.red('✗'),\n skip: pc.yellow('○'),\n update: pc.yellow('↻'),\n};\n\n/**\n * Configure Commander.js with colored help text.\n * Applies consistent styling: cyan titles, green commands, yellow options.\n */\nexport function withColoredHelp<T extends Command>(cmd: T): T {\n cmd.configureHelp({\n styleTitle: (str) => pc.bold(pc.cyan(str)),\n styleCommandText: (str) => pc.green(str),\n styleOptionText: (str) => pc.yellow(str),\n showGlobalOptions: true,\n });\n return cmd;\n}\n\n/**\n * Format a duration in milliseconds for display.\n */\nexport function formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n }\n return `${(ms / 1000).toFixed(2)}s`;\n}\n\n/**\n * Log a warning message to stderr.\n */\nexport function logWarn(message: string): void {\n console.error(colors.warn(message));\n}\n\n/**\n * Log an error message to stderr.\n */\nexport function logError(message: string): void {\n console.error(colors.error(message));\n}\n","/**\n * Test result reporting utilities.\n *\n * Handles output formatting for test results, diffs, and summaries.\n */\n\nimport pc from 'picocolors';\nimport { createPatch } from 'diff';\nimport type { TestFileResult, TestRunSummary } from './types.js';\n\nexport interface ReporterOptions {\n diff: boolean;\n verbose: boolean;\n quiet: boolean;\n}\n\n// Status indicators for consistent output\nconst statusIcon = {\n pass: pc.green('✓'),\n fail: pc.red('✗'),\n};\n\n/**\n * Format a duration in milliseconds for display.\n */\nfunction formatDuration(ms: number): string {\n if (ms < 1000) {\n return `${ms}ms`;\n }\n return `${(ms / 1000).toFixed(2)}s`;\n}\n\n/**\n * Create a unified diff between expected and actual output.\n */\nexport function createDiff(expected: string, actual: string, filename: string): string {\n const patch = createPatch(filename, expected, actual, 'expected', 'actual');\n // Remove the header lines (first 4 lines)\n const lines = patch.split('\\n').slice(4);\n return lines\n .map((line) => {\n if (line.startsWith('+')) {\n return pc.green(line);\n }\n if (line.startsWith('-')) {\n return pc.red(line);\n }\n if (line.startsWith('@')) {\n return pc.cyan(line);\n }\n return line;\n })\n .join('\\n');\n}\n\n/**\n * Report results for a single file.\n */\nexport function reportFile(result: TestFileResult, options: ReporterOptions): void {\n const filename = result.file.path;\n const status = result.passed ? pc.green(pc.bold('PASS')) : pc.red(pc.bold('FAIL'));\n\n if (options.quiet && result.passed) {\n return;\n }\n\n // File header\n console.error(`${status} ${filename}`);\n\n // Individual block results\n for (const blockResult of result.results) {\n const name = blockResult.block.name ?? `Line ${blockResult.block.lineNumber}`;\n\n if (blockResult.passed) {\n if (!options.quiet) {\n console.error(` ${statusIcon.pass} ${name}`);\n }\n } else {\n console.error(` ${statusIcon.fail} ${name}`);\n\n // Show error details\n if (blockResult.error) {\n console.error(` ${pc.red(blockResult.error)}`);\n } else {\n // Exit code mismatch\n if (blockResult.actualExitCode !== blockResult.block.expectedExitCode) {\n console.error(\n ` Expected exit code ${blockResult.block.expectedExitCode}, got ${blockResult.actualExitCode}`,\n );\n }\n\n // Output mismatch with diff\n if (options.diff && blockResult.diff) {\n console.error('');\n console.error(blockResult.diff);\n }\n }\n }\n }\n\n console.error('');\n}\n\n/**\n * Report final summary.\n */\nexport function reportSummary(summary: TestRunSummary, _options: ReporterOptions): void {\n const parts: string[] = [];\n\n if (summary.totalPassed > 0) {\n parts.push(pc.green(`${summary.totalPassed} passed`));\n }\n if (summary.totalFailed > 0) {\n parts.push(pc.red(`${summary.totalFailed} failed`));\n }\n\n const duration = formatDuration(summary.duration);\n const line = `${parts.join(', ')} (${duration})`;\n\n // Summary goes to stdout (can be piped/parsed)\n console.log(line);\n}\n","import { writeFile } from 'atomically';\nimport type { TestFile, TestBlock, TestBlockResult } from './types.js';\n\n/**\n * Update a test file with actual output from test results.\n */\nexport async function updateTestFile(\n file: TestFile,\n results: TestBlockResult[],\n): Promise<{ updated: boolean; changes: string[] }> {\n let content = file.rawContent;\n const changes: string[] = [];\n\n // Process blocks in reverse order to maintain correct offsets\n const blocksWithResults = file.blocks\n .map((block, i) => ({ block, result: results[i] }))\n .reverse();\n\n for (const { block, result } of blocksWithResults) {\n if (!result) {\n continue;\n }\n\n if (result.passed) {\n continue; // Don't touch passing tests\n }\n\n if (result.error) {\n // Execution error, can't update\n continue;\n }\n\n // Build the new block content\n const newBlockContent = buildUpdatedBlock(block, result);\n\n // Find and replace the block in the file\n const blockStart = content.indexOf(block.rawContent);\n if (blockStart !== -1) {\n content =\n content.slice(0, blockStart) +\n newBlockContent +\n content.slice(blockStart + block.rawContent.length);\n\n changes.push(block.name ?? `Line ${block.lineNumber}`);\n }\n }\n\n if (changes.length > 0) {\n await writeFile(file.path, content);\n }\n\n return { updated: changes.length > 0, changes };\n}\n\n/**\n * Build an updated console block with new expected output.\n */\nfunction buildUpdatedBlock(block: TestBlock, result: TestBlockResult): string {\n // Reconstruct the command line(s)\n const commandLines = block.command.split('\\n').map((line, i) => {\n return i === 0 ? `$ ${line}` : `> ${line}`;\n });\n\n // Build the block\n const lines: string[] = ['```console', ...commandLines];\n\n // Add output if present\n const trimmedOutput = result.actualOutput.trimEnd();\n if (trimmedOutput) {\n lines.push(trimmedOutput);\n }\n\n // Add exit code\n lines.push(`? ${result.actualExitCode}`, '```');\n\n return lines.join('\\n');\n}\n","/**\n * Coverage collection for CLI subprocess testing.\n *\n * Uses c8 and NODE_V8_COVERAGE to collect coverage from spawned processes.\n */\n\nimport { spawn } from 'node:child_process';\nimport { mkdtemp, rm, access } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport type { CoverageContext, CoverageConfig } from './types.js';\nimport { resolveCoverageConfig } from './config.js';\n\n/**\n * Find the c8 executable path.\n * Checks local node_modules/.bin first, then falls back to npx.\n */\nfunction findC8Path(): string {\n // Check common locations for local c8\n const localPaths = [\n resolve(process.cwd(), 'node_modules', '.bin', 'c8'),\n resolve(process.cwd(), '..', '..', 'node_modules', '.bin', 'c8'), // monorepo root\n ];\n\n for (const localPath of localPaths) {\n if (existsSync(localPath)) {\n return localPath;\n }\n }\n\n // Fall back to npx which will find c8 in node_modules\n return 'npx c8';\n}\n\n/**\n * Check if c8 is available in the current environment.\n */\nexport async function isC8Available(): Promise<boolean> {\n const c8Path = findC8Path();\n\n return new Promise((resolve) => {\n // Use npx to run c8 if we fell back to npx\n const isNpx = c8Path === 'npx c8';\n const command = isNpx ? 'npx' : c8Path;\n const args = isNpx ? ['c8', '--version'] : ['--version'];\n\n const proc = spawn(command, args, {\n shell: false,\n stdio: 'ignore',\n });\n proc.on('close', (code) => {\n resolve(code === 0);\n });\n proc.on('error', () => {\n resolve(false);\n });\n });\n}\n\n/**\n * Create a coverage context for collecting V8 coverage data.\n */\nexport async function createCoverageContext(config?: CoverageConfig): Promise<CoverageContext> {\n const options = resolveCoverageConfig(config);\n const tempDir = await mkdtemp(join(tmpdir(), 'tryscript-coverage-'));\n\n return {\n tempDir,\n options,\n };\n}\n\n/**\n * Get environment variables for enabling V8 coverage in spawned processes.\n */\nexport function getCoverageEnv(ctx: CoverageContext): Record<string, string> {\n return {\n NODE_V8_COVERAGE: ctx.tempDir,\n };\n}\n\n/**\n * Generate coverage report from collected V8 coverage data using c8.\n * Throws an error if coverage report generation fails.\n */\nexport async function generateCoverageReport(ctx: CoverageContext): Promise<void> {\n const { options, tempDir } = ctx;\n const c8Path = findC8Path();\n\n // Base args for c8 report\n const reportArgs = [\n 'report',\n '--temp-directory',\n tempDir,\n '--reports-dir',\n options.reportsDir,\n '--src',\n options.src,\n '--all',\n // Include patterns\n ...options.include.flatMap((pattern) => ['--include', pattern]),\n // Exclude patterns\n ...options.exclude.flatMap((pattern) => ['--exclude', pattern]),\n // Boolean flags (only add if explicitly set)\n ...(options.excludeNodeModules ? ['--exclude-node-modules'] : ['--no-exclude-node-modules']),\n ...(options.excludeAfterRemap ? ['--exclude-after-remap'] : []),\n ...(options.skipFull ? ['--skip-full'] : []),\n ...(options.allowExternal ? ['--allowExternal'] : []),\n ...(options.monocart ? ['--experimental-monocart'] : []),\n // Reporters\n ...options.reporters.flatMap((reporter) => ['--reporter', reporter]),\n ];\n\n // Handle 'npx c8' vs direct c8 path\n // Use shell: false to prevent glob expansion of patterns like dist/**\n const isNpx = c8Path === 'npx c8';\n const command = isNpx ? 'npx' : c8Path;\n const args = isNpx ? ['c8', ...reportArgs] : reportArgs;\n\n await new Promise<void>((resolvePromise, reject) => {\n const proc = spawn(command, args, {\n shell: false,\n stdio: 'inherit',\n });\n\n proc.on('close', (code) => {\n if (code === 0) {\n resolvePromise();\n } else {\n reject(new Error(`c8 report exited with code ${code}`));\n }\n });\n\n proc.on('error', (err) => {\n reject(new Error(`Failed to run c8 report: ${err.message}`));\n });\n });\n}\n\n/**\n * Clean up coverage context by removing the temporary directory.\n */\nexport async function cleanupCoverageContext(ctx: CoverageContext): Promise<void> {\n try {\n await access(ctx.tempDir);\n await rm(ctx.tempDir, { recursive: true, force: true });\n } catch {\n // Directory doesn't exist, nothing to clean up\n }\n}\n","/**\n * Run command - executes golden tests against CLI applications.\n *\n * Supports filtering, update mode, and detailed diff output for failures.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFile } from 'node:fs/promises';\nimport fg from 'fast-glob';\nimport { loadConfig, mergeConfig } from '../../lib/config.js';\nimport { logWarn, logError, colors, status as statusIndicators } from '../lib/shared.js';\nimport { parseTestFile } from '../../lib/parser.js';\nimport {\n runBlock,\n createExecutionContext,\n cleanupExecutionContext,\n runAfterHook,\n} from '../../lib/runner.js';\nimport { matchOutput } from '../../lib/matcher.js';\nimport { createDiff, reportFile, reportSummary } from '../../lib/reporter.js';\nimport { updateTestFile } from '../../lib/updater.js';\nimport {\n isC8Available,\n createCoverageContext,\n getCoverageEnv,\n generateCoverageReport,\n cleanupCoverageContext,\n} from '../../lib/coverage.js';\nimport type {\n TestBlockResult,\n TestFileResult,\n TestRunSummary,\n CoverageContext,\n} from '../../lib/types.js';\n\ninterface RunOptions {\n update?: boolean;\n diff?: boolean;\n failFast?: boolean;\n filter?: string;\n verbose?: boolean;\n quiet?: boolean;\n coverage?: boolean;\n coverageDir?: string;\n coverageReporter?: string[];\n coverageExclude?: string[];\n coverageExcludeNodeModules?: boolean;\n coverageExcludeAfterRemap?: boolean;\n coverageSkipFull?: boolean;\n coverageAllowExternal?: boolean;\n coverageMonocart?: boolean;\n}\n\n/**\n * Register the run command.\n */\nexport function registerRunCommand(program: Command): void {\n program\n .command('run')\n .description('Run golden tests')\n .argument('[files...]', 'Test files to run (default: **/*.tryscript.md)')\n .option('--update', 'Update golden files with actual output')\n .option('--diff', 'Show diff on failure (default: true)')\n .option('--no-diff', 'Hide diff on failure')\n .option('--fail-fast', 'Stop on first failure')\n .option('--filter <pattern>', 'Filter tests by name pattern')\n .option('--verbose', 'Show detailed output including passing test output')\n .option('--quiet', 'Suppress non-essential output (only show failures)')\n .option('--coverage', 'Enable code coverage collection (requires c8)')\n .option('--coverage-dir <dir>', 'Coverage output directory (default: coverage-tryscript)')\n .option(\n '--coverage-reporter <reporter...>',\n 'Coverage reporters (default: text, html). Can be specified multiple times.',\n )\n .option(\n '--coverage-exclude <pattern...>',\n 'Patterns to exclude from coverage (c8 --exclude). Can be specified multiple times.',\n )\n .option(\n '--coverage-exclude-node-modules',\n 'Exclude node_modules from coverage (c8 --exclude-node-modules, default: true)',\n )\n .option(\n '--no-coverage-exclude-node-modules',\n 'Include node_modules in coverage (c8 --no-exclude-node-modules)',\n )\n .option(\n '--coverage-exclude-after-remap',\n 'Apply exclude logic after sourcemap remapping (c8 --exclude-after-remap)',\n )\n .option('--coverage-skip-full', 'Hide files with 100% coverage (c8 --skip-full)')\n .option('--coverage-allow-external', 'Allow files from outside cwd (c8 --allowExternal)')\n .option(\n '--coverage-monocart',\n 'Use monocart for accurate line counts, better for merging with vitest (c8 --experimental-monocart)',\n )\n .action(runCommand);\n}\n\nasync function runCommand(files: string[], options: RunOptions): Promise<void> {\n const startTime = Date.now();\n\n // Default options\n const opts = {\n diff: options.diff !== false,\n verbose: options.verbose ?? false,\n quiet: options.quiet ?? false,\n update: options.update ?? false,\n failFast: options.failFast ?? false,\n filter: options.filter,\n };\n\n // Find test files (fast-glob respects .gitignore by default)\n const patterns = files.length > 0 ? files : ['**/*.tryscript.md'];\n const testFiles = await fg(patterns, {\n ignore: ['**/node_modules/**', '**/dist/**'],\n absolute: true,\n dot: false,\n });\n\n if (testFiles.length === 0) {\n logWarn('No test files found');\n process.exit(1);\n }\n\n // Load global config\n const globalConfig = await loadConfig(process.cwd());\n\n // Setup coverage if enabled\n let coverageCtx: CoverageContext | undefined;\n let coverageEnv: Record<string, string> = {};\n\n if (options.coverage) {\n // Check if c8 is available\n const c8Available = await isC8Available();\n if (!c8Available) {\n logError('Coverage requires c8. Install with: npm install -D c8');\n process.exit(1);\n }\n\n // Create coverage context with CLI options overriding config\n coverageCtx = await createCoverageContext({\n ...globalConfig.coverage,\n reportsDir: options.coverageDir ?? globalConfig.coverage?.reportsDir,\n reporters: options.coverageReporter ?? globalConfig.coverage?.reporters,\n exclude: options.coverageExclude ?? globalConfig.coverage?.exclude,\n excludeNodeModules:\n options.coverageExcludeNodeModules ?? globalConfig.coverage?.excludeNodeModules,\n excludeAfterRemap:\n options.coverageExcludeAfterRemap ?? globalConfig.coverage?.excludeAfterRemap,\n skipFull: options.coverageSkipFull ?? globalConfig.coverage?.skipFull,\n allowExternal: options.coverageAllowExternal ?? globalConfig.coverage?.allowExternal,\n monocart: options.coverageMonocart ?? globalConfig.coverage?.monocart,\n });\n coverageEnv = getCoverageEnv(coverageCtx);\n }\n\n // Run tests\n const fileResults: TestFileResult[] = [];\n let shouldStop = false;\n\n for (const filePath of testFiles) {\n if (shouldStop) {\n break;\n }\n\n const content = await readFile(filePath, 'utf-8');\n const testFile = parseTestFile(content, filePath);\n const config = mergeConfig(globalConfig, testFile.config);\n\n // Filter blocks by name if specified\n let blocksToRun = testFile.blocks;\n if (opts.filter) {\n const filterPattern = new RegExp(opts.filter, 'i');\n blocksToRun = blocksToRun.filter((b) => (b.name ? filterPattern.test(b.name) : true));\n }\n\n // Handle \"only\" mode - if any block has only=true, run only those\n const onlyBlocks = blocksToRun.filter((b) => b.only);\n if (onlyBlocks.length > 0) {\n blocksToRun = onlyBlocks;\n }\n\n if (blocksToRun.length === 0) {\n continue;\n }\n\n const ctx = await createExecutionContext(config, filePath, coverageEnv);\n const results: TestBlockResult[] = [];\n\n try {\n for (const block of blocksToRun) {\n const result = await runBlock(block, ctx);\n\n // Skip checking for skipped tests\n if (result.skipped) {\n results.push(result);\n continue;\n }\n\n // Check if output matches expected\n // [ROOT] = test file directory, [CWD] = command working directory\n // If expectedStderr is set, compare stdout only (not combined output)\n const outputToCheck = block.expectedStderr\n ? (result.actualStdout ?? '')\n : result.actualOutput;\n const outputMatches = matchOutput(\n outputToCheck,\n block.expectedOutput,\n { root: ctx.testDir, cwd: ctx.cwd },\n config.patterns ?? {},\n );\n\n // Check stderr if expected (using actualStderr if available)\n let stderrMatches = true;\n if (block.expectedStderr) {\n stderrMatches = matchOutput(\n result.actualStderr ?? '',\n block.expectedStderr,\n { root: ctx.testDir, cwd: ctx.cwd },\n config.patterns ?? {},\n );\n }\n\n const exitCodeMatches = result.actualExitCode === block.expectedExitCode;\n result.passed = outputMatches && stderrMatches && exitCodeMatches && !result.error;\n\n if (!result.passed && opts.diff) {\n result.diff = createDiff(\n block.expectedOutput,\n result.actualOutput,\n `${filePath}:${block.lineNumber}`,\n );\n }\n\n results.push(result);\n\n if (!result.passed && opts.failFast) {\n shouldStop = true;\n break;\n }\n }\n\n // Run after hook if configured\n await runAfterHook(ctx);\n } finally {\n await cleanupExecutionContext(ctx);\n }\n\n const fileResult: TestFileResult = {\n file: testFile,\n results,\n passed: results.every((r) => r.passed),\n duration: results.reduce((sum, r) => sum + r.duration, 0),\n };\n\n fileResults.push(fileResult);\n reportFile(fileResult, opts);\n\n // Update mode\n if (opts.update && !fileResult.passed) {\n const { updated, changes } = await updateTestFile(testFile, results);\n if (updated) {\n console.error(colors.warn(` ${statusIndicators.update} Updated: ${changes.join(', ')}`));\n }\n }\n }\n\n // Summary\n const summary: TestRunSummary = {\n files: fileResults,\n totalPassed: fileResults.reduce((sum, f) => sum + f.results.filter((r) => r.passed).length, 0),\n totalFailed: fileResults.reduce((sum, f) => sum + f.results.filter((r) => !r.passed).length, 0),\n totalBlocks: fileResults.reduce((sum, f) => sum + f.results.length, 0),\n duration: Date.now() - startTime,\n };\n\n reportSummary(summary, opts);\n\n // Generate coverage report if enabled\n if (coverageCtx) {\n console.error('\\nGenerating coverage report...');\n try {\n await generateCoverageReport(coverageCtx);\n console.error(\n colors.success(`Coverage report written to ${coverageCtx.options.reportsDir}/`),\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logError(`Failed to generate coverage report: ${message}`);\n } finally {\n await cleanupCoverageContext(coverageCtx);\n }\n }\n\n // Exit code\n process.exit(summary.totalFailed > 0 ? 1 : 0);\n}\n","/**\n * Coverage command - runs multiple commands with merged V8 coverage.\n *\n * This command provides a simple way to collect coverage from multiple sources\n * (e.g., unit tests + CLI tests) and generate a merged coverage report.\n *\n * Example usage:\n * tryscript coverage \"vitest run\" \"tryscript run tests/\"\n * tryscript coverage --monocart --reporters text,html \"vitest run\" \"node dist/bin.mjs run tests/\"\n */\n\nimport type { Command } from 'commander';\nimport { spawn } from 'node:child_process';\nimport { mkdtemp, rm, readdir, stat } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { logError, logWarn, colors } from '../lib/shared.js';\n\ninterface CoverageOptions {\n reportsDir?: string;\n reporters?: string[];\n include?: string[];\n exclude?: string[];\n excludeNodeModules?: boolean;\n excludeAfterRemap?: boolean;\n skipFull?: boolean;\n allowExternal?: boolean;\n monocart?: boolean;\n src?: string;\n verbose?: boolean;\n}\n\n/**\n * Register the coverage command.\n */\nexport function registerCoverageCommand(program: Command): void {\n program\n .command('coverage')\n .description('Run commands with merged V8 coverage')\n .argument('<commands...>', 'Commands to run (each will inherit coverage environment)')\n .option('--reports-dir <dir>', 'Coverage output directory (default: coverage)')\n .option(\n '--reporters <reporters>',\n 'Comma-separated coverage reporters (default: text,json,json-summary,lcov,html)',\n )\n .option('--include <patterns>', 'Comma-separated patterns to include in coverage')\n .option('--exclude <patterns>', 'Comma-separated patterns to exclude from coverage')\n .option('--exclude-node-modules', 'Exclude node_modules from coverage (default: true)', true)\n .option('--no-exclude-node-modules', 'Include node_modules in coverage')\n .option('--exclude-after-remap', 'Apply exclude logic after sourcemap remapping')\n .option('--skip-full', 'Hide files with 100% coverage')\n .option('--allow-external', 'Allow files from outside cwd')\n .option('--monocart', 'Use monocart for accurate line counts (recommended for merging)')\n .option('--src <dir>', 'Source directory for sourcemap remapping (default: src)')\n .option('--verbose', 'Show coverage summary after each command for debugging')\n .action(coverageCommand);\n}\n\n/**\n * Run a command with inherited coverage environment.\n */\nasync function runCommand(\n command: string,\n env: Record<string, string>,\n): Promise<{ success: boolean; code: number }> {\n return new Promise((resolve) => {\n const proc = spawn(command, [], {\n stdio: 'inherit',\n env: { ...process.env, ...env },\n shell: true,\n });\n\n proc.on('close', (code) => {\n resolve({ success: code === 0, code: code ?? 1 });\n });\n\n proc.on('error', (err) => {\n logError(`Failed to run command: ${err.message}`);\n resolve({ success: false, code: 1 });\n });\n });\n}\n\n/**\n * Find the c8 executable path.\n * Can be overridden via TRYSCRIPT_C8_COMMAND env var for testing.\n */\nfunction findC8Path(): string | null {\n // Allow override for testing - when set, we trust it exists\n const override = process.env.TRYSCRIPT_C8_COMMAND;\n if (override) {\n return override;\n }\n\n const localPaths = [\n resolve(process.cwd(), 'node_modules', '.bin', 'c8'),\n resolve(process.cwd(), '..', '..', 'node_modules', '.bin', 'c8'),\n ];\n\n for (const localPath of localPaths) {\n if (existsSync(localPath)) {\n return localPath;\n }\n }\n\n return null;\n}\n\n/**\n * Get coverage file statistics from temp directory.\n */\nasync function getCoverageStats(\n tempDir: string,\n): Promise<{ fileCount: number; totalBytes: number; files: string[] }> {\n try {\n const files = await readdir(tempDir);\n const coverageFiles = files.filter((f) => f.startsWith('coverage-') && f.endsWith('.json'));\n let totalBytes = 0;\n\n for (const file of coverageFiles) {\n const fileStat = await stat(join(tempDir, file));\n totalBytes += fileStat.size;\n }\n\n return { fileCount: coverageFiles.length, totalBytes, files: coverageFiles };\n } catch {\n return { fileCount: 0, totalBytes: 0, files: [] };\n }\n}\n\n/**\n * Generate a text-only coverage report for debugging (doesn't write files).\n */\nasync function generateTextReport(\n tempDir: string,\n options: CoverageOptions,\n label: string,\n): Promise<void> {\n const c8Path = findC8Path();\n if (!c8Path) {\n return;\n }\n\n const include = options.include ?? ['dist/**'];\n const exclude = options.exclude ?? [];\n\n // Create a temporary reports dir that we'll discard\n const tempReportsDir = await mkdtemp(join(tmpdir(), 'tryscript-coverage-report-'));\n\n const reportArgs = [\n 'report',\n '--temp-directory',\n tempDir,\n '--reports-dir',\n tempReportsDir,\n '--src',\n options.src ?? 'src',\n '--all',\n ...include.flatMap((pattern) => ['--include', pattern]),\n ...exclude.flatMap((pattern) => ['--exclude', pattern]),\n ...(options.excludeNodeModules !== false\n ? ['--exclude-node-modules']\n : ['--no-exclude-node-modules']),\n ...(options.excludeAfterRemap ? ['--exclude-after-remap'] : []),\n ...(options.monocart ? ['--experimental-monocart'] : []),\n '--reporter',\n 'text',\n ];\n\n console.error(colors.info(`\\n--- Coverage after: ${label} ---`));\n\n await new Promise<void>((resolve) => {\n const proc = spawn(c8Path, reportArgs, {\n stdio: 'inherit',\n shell: false,\n });\n proc.on('close', () => {\n resolve();\n });\n proc.on('error', () => {\n resolve();\n });\n });\n\n // Cleanup temp reports dir\n await rm(tempReportsDir, { recursive: true, force: true });\n}\n\n/**\n * Generate c8 coverage report.\n */\nasync function generateReport(tempDir: string, options: CoverageOptions): Promise<boolean> {\n const c8Path = findC8Path();\n if (!c8Path) {\n logError('c8 not found. Install with: npm install -D c8');\n return false;\n }\n\n const reporters = options.reporters ?? ['text', 'json', 'json-summary', 'lcov', 'html'];\n const include = options.include ?? ['dist/**'];\n const exclude = options.exclude ?? [];\n\n const reportArgs = [\n 'report',\n '--temp-directory',\n tempDir,\n '--reports-dir',\n options.reportsDir ?? 'coverage',\n '--src',\n options.src ?? 'src',\n '--all',\n ...include.flatMap((pattern) => ['--include', pattern]),\n ...exclude.flatMap((pattern) => ['--exclude', pattern]),\n ...(options.excludeNodeModules !== false\n ? ['--exclude-node-modules']\n : ['--no-exclude-node-modules']),\n ...(options.excludeAfterRemap ? ['--exclude-after-remap'] : []),\n ...(options.skipFull ? ['--skip-full'] : []),\n ...(options.allowExternal ? ['--allowExternal'] : []),\n ...(options.monocart ? ['--experimental-monocart'] : []),\n ...reporters.flatMap((reporter) => ['--reporter', reporter]),\n ];\n\n return new Promise((resolve) => {\n const proc = spawn(c8Path, reportArgs, {\n stdio: 'inherit',\n shell: false,\n });\n\n proc.on('close', (code) => {\n resolve(code === 0);\n });\n\n proc.on('error', (err) => {\n logError(`Failed to generate coverage report: ${err.message}`);\n resolve(false);\n });\n });\n}\n\nasync function coverageCommand(commands: string[], options: CoverageOptions): Promise<void> {\n // Validate we have commands to run\n if (commands.length === 0) {\n logError('No commands specified. Usage: tryscript coverage \"cmd1\" \"cmd2\"');\n process.exit(1);\n }\n\n // Check for c8\n const c8Path = findC8Path();\n if (!c8Path) {\n logError('Coverage requires c8. Install with: npm install -D c8');\n process.exit(1);\n }\n\n // Parse comma-separated options early so we can use them for intermediate reports\n const parsedOptions: CoverageOptions = {\n ...options,\n reporters: options.reporters\n ? typeof options.reporters === 'string'\n ? (options.reporters as string).split(',')\n : options.reporters\n : undefined,\n include: options.include\n ? typeof options.include === 'string'\n ? (options.include as string).split(',')\n : options.include\n : undefined,\n exclude: options.exclude\n ? typeof options.exclude === 'string'\n ? (options.exclude as string).split(',')\n : options.exclude\n : undefined,\n };\n\n // Create temp directory for V8 coverage data\n const coverageTemp = await mkdtemp(join(tmpdir(), 'tryscript-coverage-'));\n const coverageEnv = { NODE_V8_COVERAGE: coverageTemp };\n\n console.error(colors.info(`Collecting V8 coverage to ${coverageTemp}`));\n\n let hasFailures = false;\n let previousFileCount = 0;\n\n try {\n // Run each command with shared coverage environment\n for (let i = 0; i < commands.length; i++) {\n const command = commands[i]!;\n console.error(\n colors.info(`\\n=== Running command ${i + 1}/${commands.length}: ${command} ===`),\n );\n\n const result = await runCommand(command, coverageEnv);\n if (!result.success) {\n logWarn(`Command exited with code ${result.code}: ${command}`);\n hasFailures = true;\n }\n\n // Show coverage stats after each command\n const stats = await getCoverageStats(coverageTemp);\n const newFiles = stats.fileCount - previousFileCount;\n const bytesKB = (stats.totalBytes / 1024).toFixed(1);\n\n console.error(\n colors.info(\n `\\nV8 coverage: ${stats.fileCount} files (${newFiles} new), ${bytesKB} KB total`,\n ),\n );\n\n if (newFiles === 0) {\n logWarn(\n `No new coverage files from this command. ` +\n `This may indicate the command doesn't write to NODE_V8_COVERAGE.`,\n );\n }\n\n // Show intermediate coverage report if verbose\n if (parsedOptions.verbose && stats.fileCount > 0) {\n await generateTextReport(coverageTemp, parsedOptions, command);\n }\n\n previousFileCount = stats.fileCount;\n }\n\n // Generate merged coverage report\n console.error(colors.info('\\n=== Generating merged coverage report ==='));\n\n const reportSuccess = await generateReport(coverageTemp, parsedOptions);\n if (!reportSuccess) {\n logError('Failed to generate coverage report');\n process.exit(1);\n }\n\n console.error(\n colors.success(`\\nCoverage report written to ${parsedOptions.reportsDir ?? 'coverage'}/`),\n );\n } finally {\n // Cleanup temp directory\n await rm(coverageTemp, { recursive: true, force: true });\n }\n\n // Exit with failure if any command failed\n if (hasFailures) {\n process.exit(1);\n }\n}\n","/**\n * Readme command - Display the README documentation.\n *\n * Shows the package README.md, formatted for the terminal when interactive,\n * or as plain text when piped.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport pc from 'picocolors';\n\n/**\n * Get the path to the README.md file.\n * Works both during development and when installed as a package.\n */\nfunction getReadmePath(): string {\n const thisDir = dirname(fileURLToPath(import.meta.url));\n const dirName = thisDir.split(/[/\\\\]/).pop();\n\n if (dirName === 'dist') {\n // Bundled: dist -> package root -> README.md\n return join(dirname(thisDir), 'README.md');\n }\n\n // Development: src/cli/commands -> src/cli -> src -> package root -> README.md\n return join(dirname(dirname(dirname(thisDir))), 'README.md');\n}\n\n/**\n * Load the README content.\n */\nfunction loadReadme(): string {\n const readmePath = getReadmePath();\n try {\n return readFileSync(readmePath, 'utf-8');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load README from ${readmePath}: ${message}`);\n }\n}\n\n/**\n * Apply basic terminal formatting to markdown content.\n * Colorizes headers, code blocks, and other elements for better readability.\n */\nfunction formatMarkdown(content: string, useColors: boolean): string {\n if (!useColors) {\n return content;\n }\n\n const lines = content.split('\\n');\n const formatted: string[] = [];\n let inCodeBlock = false;\n\n for (const line of lines) {\n // Track code blocks\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n formatted.push(pc.dim(line));\n continue;\n }\n\n if (inCodeBlock) {\n formatted.push(pc.dim(line));\n continue;\n }\n\n // Headers\n if (line.startsWith('# ')) {\n formatted.push(pc.bold(pc.cyan(line)));\n continue;\n }\n if (line.startsWith('## ')) {\n formatted.push(pc.bold(pc.blue(line)));\n continue;\n }\n if (line.startsWith('### ')) {\n formatted.push(pc.bold(line));\n continue;\n }\n\n // Inline code (backticks)\n let formattedLine = line.replace(/`([^`]+)`/g, (_match, code: string) => {\n return pc.yellow(code);\n });\n\n // Bold text\n formattedLine = formattedLine.replace(/\\*\\*([^*]+)\\*\\*/g, (_match, text: string) => {\n return pc.bold(text);\n });\n\n // Links - show text in cyan, URL dimmed\n formattedLine = formattedLine.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, text: string, url: string) => {\n return `${pc.cyan(text)} ${pc.dim(`(${url})`)}`;\n },\n );\n\n formatted.push(formattedLine);\n }\n\n return formatted.join('\\n');\n}\n\n/**\n * Check if stdout is an interactive terminal.\n */\nfunction isInteractive(): boolean {\n return process.stdout.isTTY === true;\n}\n\n/**\n * Display the README content.\n * Exported for use as the default command.\n */\nexport function showReadme(options?: { raw?: boolean; color?: boolean }): void {\n try {\n const readme = loadReadme();\n\n // Determine if we should colorize\n const shouldColorize = options?.color ?? (!options?.raw && isInteractive());\n\n const formatted = formatMarkdown(readme, shouldColorize);\n console.log(formatted);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(pc.red(`Error: ${message}`));\n process.exit(1);\n }\n}\n\n/**\n * Register the readme command.\n */\nexport function registerReadmeCommand(program: Command): void {\n program\n .command('readme')\n .description('Display README documentation')\n .option('--raw', 'Output raw markdown without formatting')\n .option('--color', 'Force colorized output (for testing)')\n .action(showReadme);\n}\n","/**\n * Docs command - Display the tryscript quick reference.\n *\n * Shows the tryscript-reference.md file, formatted for the terminal when interactive,\n * or as plain text when piped.\n */\n\nimport type { Command } from 'commander';\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport pc from 'picocolors';\n\n/**\n * Get the path to the tryscript-reference.md file.\n * Works both during development and when installed as a package.\n */\nfunction getDocsPath(): string {\n const thisDir = dirname(fileURLToPath(import.meta.url));\n const dirName = thisDir.split(/[/\\\\]/).pop();\n\n if (dirName === 'dist') {\n // Bundled: dist -> package root -> docs/tryscript-reference.md\n return join(dirname(thisDir), 'docs', 'tryscript-reference.md');\n }\n\n // Development: src/cli/commands -> src/cli -> src -> package root -> docs/tryscript-reference.md\n return join(dirname(dirname(dirname(thisDir))), 'docs', 'tryscript-reference.md');\n}\n\n/**\n * Load the docs content.\n */\nfunction loadDocs(): string {\n const docsPath = getDocsPath();\n try {\n return readFileSync(docsPath, 'utf-8');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load reference docs from ${docsPath}: ${message}`);\n }\n}\n\n/**\n * Apply basic terminal formatting to markdown content.\n * Colorizes headers, code blocks, and other elements for better readability.\n */\nfunction formatMarkdown(content: string, useColors: boolean): string {\n if (!useColors) {\n return content;\n }\n\n const lines = content.split('\\n');\n const formatted: string[] = [];\n let inCodeBlock = false;\n\n for (const line of lines) {\n // Track code blocks\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n formatted.push(pc.dim(line));\n continue;\n }\n\n if (inCodeBlock) {\n formatted.push(pc.dim(line));\n continue;\n }\n\n // Headers\n if (line.startsWith('# ')) {\n formatted.push(pc.bold(pc.cyan(line)));\n continue;\n }\n if (line.startsWith('## ')) {\n formatted.push(pc.bold(pc.blue(line)));\n continue;\n }\n if (line.startsWith('### ')) {\n formatted.push(pc.bold(line));\n continue;\n }\n\n // Inline code (backticks)\n let formattedLine = line.replace(/`([^`]+)`/g, (_match, code: string) => {\n return pc.yellow(code);\n });\n\n // Bold text\n formattedLine = formattedLine.replace(/\\*\\*([^*]+)\\*\\*/g, (_match, text: string) => {\n return pc.bold(text);\n });\n\n // Links - show text in cyan, URL dimmed\n formattedLine = formattedLine.replace(\n /\\[([^\\]]+)\\]\\(([^)]+)\\)/g,\n (_match, text: string, url: string) => {\n return `${pc.cyan(text)} ${pc.dim(`(${url})`)}`;\n },\n );\n\n formatted.push(formattedLine);\n }\n\n return formatted.join('\\n');\n}\n\n/**\n * Check if stdout is an interactive terminal.\n */\nfunction isInteractive(): boolean {\n return process.stdout.isTTY === true;\n}\n\n/**\n * Register the docs command.\n */\nexport function registerDocsCommand(program: Command): void {\n program\n .command('docs')\n .description('Display concise syntax reference')\n .option('--raw', 'Output raw markdown without formatting')\n .option('--color', 'Force colorized output (for testing)')\n .action((options: { raw?: boolean; color?: boolean }) => {\n try {\n const docs = loadDocs();\n\n // Determine if we should colorize\n const shouldColorize = options.color ?? (!options.raw && isInteractive());\n\n const formatted = formatMarkdown(docs, shouldColorize);\n console.log(formatted);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(pc.red(`Error: ${message}`));\n process.exit(1);\n }\n });\n}\n","/**\n * CLI entry point for tryscript.\n *\n * Configures Commander.js with colored help and registers all subcommands.\n */\n\nimport { Command } from 'commander';\nimport { VERSION } from '../index.js';\nimport { registerRunCommand } from './commands/run.js';\nimport { registerCoverageCommand } from './commands/coverage.js';\nimport { registerReadmeCommand } from './commands/readme.js';\nimport { registerDocsCommand } from './commands/docs.js';\nimport { withColoredHelp, logError } from './lib/shared.js';\n\nexport function run(argv: string[]): void {\n const program = withColoredHelp(\n new Command()\n .name('tryscript')\n .version(VERSION, '--version', 'Show version number')\n .description('Golden testing for CLI applications')\n .showHelpAfterError('(use --help for usage)'),\n );\n\n // Register subcommands\n registerRunCommand(program);\n registerCoverageCommand(program);\n registerReadmeCommand(program);\n registerDocsCommand(program);\n\n // Default action: show help when no command given\n program.action(() => {\n program.help();\n });\n\n program.parseAsync(argv).catch((err: Error) => {\n logError(`Error: ${err.message}`);\n process.exit(2);\n });\n}\n","#!/usr/bin/env node\nimport { run } from './cli/cli.js';\n\nrun(process.argv);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,SAAS;CACpB,UAAU,MAAcA,mBAAG,MAAM,EAAE;CACnC,QAAQ,MAAcA,mBAAG,IAAI,EAAE;CAC/B,OAAO,MAAcA,mBAAG,OAAO,EAAE;CACjC,OAAO,MAAcA,mBAAG,KAAK,EAAE;CAChC;;;;AAKD,MAAa,SAAS;CACpB,MAAMA,mBAAG,MAAM,IAAI;CACnB,MAAMA,mBAAG,IAAI,IAAI;CACjB,MAAMA,mBAAG,OAAO,IAAI;CACpB,QAAQA,mBAAG,OAAO,IAAI;CACvB;;;;;AAMD,SAAgB,gBAAmC,KAAW;AAC5D,KAAI,cAAc;EAChB,aAAa,QAAQA,mBAAG,KAAKA,mBAAG,KAAK,IAAI,CAAC;EAC1C,mBAAmB,QAAQA,mBAAG,MAAM,IAAI;EACxC,kBAAkB,QAAQA,mBAAG,OAAO,IAAI;EACxC,mBAAmB;EACpB,CAAC;AACF,QAAO;;;;;AAgBT,SAAgB,QAAQ,SAAuB;AAC7C,SAAQ,MAAM,OAAO,KAAK,QAAQ,CAAC;;;;;AAMrC,SAAgB,SAAS,SAAuB;AAC9C,SAAQ,MAAM,OAAO,MAAM,QAAQ,CAAC;;;;;;;;;;AClDtC,MAAM,aAAa;CACjB,MAAMC,mBAAG,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!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import { a as createExecutionContext, c as parseTestFile, d as mergeConfig, f as resolveCoverageConfig, i as cleanupExecutionContext, n as matchOutput, o as runAfterHook, s as runBlock, t as VERSION, u as loadConfig } from "./src-
|
|
4
|
+
import { a as createExecutionContext, c as parseTestFile, d as mergeConfig, f as resolveCoverageConfig, i as cleanupExecutionContext, n as matchOutput, o as runAfterHook, s as runBlock, t as VERSION, u as loadConfig } from "./src-BBeKy_V9.mjs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
8
|
import { spawn } from "node:child_process";
|
|
9
|
-
import { access, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
9
|
+
import { access, mkdtemp, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { Command } from "commander";
|
|
12
12
|
import fg from "fast-glob";
|
|
@@ -21,10 +21,8 @@ import { writeFile } from "atomically";
|
|
|
21
21
|
const colors = {
|
|
22
22
|
success: (s) => pc.green(s),
|
|
23
23
|
error: (s) => pc.red(s),
|
|
24
|
-
info: (s) => pc.cyan(s),
|
|
25
24
|
warn: (s) => pc.yellow(s),
|
|
26
|
-
|
|
27
|
-
bold: (s) => pc.bold(s)
|
|
25
|
+
info: (s) => pc.cyan(s)
|
|
28
26
|
};
|
|
29
27
|
/**
|
|
30
28
|
* Status indicators with emoji.
|
|
@@ -181,7 +179,7 @@ function buildUpdatedBlock(block, result) {
|
|
|
181
179
|
* Find the c8 executable path.
|
|
182
180
|
* Checks local node_modules/.bin first, then falls back to npx.
|
|
183
181
|
*/
|
|
184
|
-
function findC8Path() {
|
|
182
|
+
function findC8Path$1() {
|
|
185
183
|
const localPaths = [resolve(process.cwd(), "node_modules", ".bin", "c8"), resolve(process.cwd(), "..", "..", "node_modules", ".bin", "c8")];
|
|
186
184
|
for (const localPath of localPaths) if (existsSync(localPath)) return localPath;
|
|
187
185
|
return "npx c8";
|
|
@@ -190,7 +188,7 @@ function findC8Path() {
|
|
|
190
188
|
* Check if c8 is available in the current environment.
|
|
191
189
|
*/
|
|
192
190
|
async function isC8Available() {
|
|
193
|
-
const c8Path = findC8Path();
|
|
191
|
+
const c8Path = findC8Path$1();
|
|
194
192
|
return new Promise((resolve$1) => {
|
|
195
193
|
const isNpx = c8Path === "npx c8";
|
|
196
194
|
const proc = spawn(isNpx ? "npx" : c8Path, isNpx ? ["c8", "--version"] : ["--version"], {
|
|
@@ -227,7 +225,7 @@ function getCoverageEnv(ctx) {
|
|
|
227
225
|
*/
|
|
228
226
|
async function generateCoverageReport(ctx) {
|
|
229
227
|
const { options, tempDir } = ctx;
|
|
230
|
-
const c8Path = findC8Path();
|
|
228
|
+
const c8Path = findC8Path$1();
|
|
231
229
|
const reportArgs = [
|
|
232
230
|
"report",
|
|
233
231
|
"--temp-directory",
|
|
@@ -238,6 +236,12 @@ async function generateCoverageReport(ctx) {
|
|
|
238
236
|
options.src,
|
|
239
237
|
"--all",
|
|
240
238
|
...options.include.flatMap((pattern) => ["--include", pattern]),
|
|
239
|
+
...options.exclude.flatMap((pattern) => ["--exclude", pattern]),
|
|
240
|
+
...options.excludeNodeModules ? ["--exclude-node-modules"] : ["--no-exclude-node-modules"],
|
|
241
|
+
...options.excludeAfterRemap ? ["--exclude-after-remap"] : [],
|
|
242
|
+
...options.skipFull ? ["--skip-full"] : [],
|
|
243
|
+
...options.allowExternal ? ["--allowExternal"] : [],
|
|
244
|
+
...options.monocart ? ["--experimental-monocart"] : [],
|
|
241
245
|
...options.reporters.flatMap((reporter) => ["--reporter", reporter])
|
|
242
246
|
];
|
|
243
247
|
const isNpx = c8Path === "npx c8";
|
|
@@ -276,9 +280,9 @@ async function cleanupCoverageContext(ctx) {
|
|
|
276
280
|
* Register the run command.
|
|
277
281
|
*/
|
|
278
282
|
function registerRunCommand(program) {
|
|
279
|
-
program.command("run").description("Run golden tests").argument("[files...]", "Test files to run (default: **/*.tryscript.md)").option("--update", "Update golden files with actual output").option("--diff", "Show diff on failure (default: true)").option("--no-diff", "Hide diff on failure").option("--fail-fast", "Stop on first failure").option("--filter <pattern>", "Filter tests by name pattern").option("--verbose", "Show detailed output including passing test output").option("--quiet", "Suppress non-essential output (only show failures)").option("--coverage", "Enable code coverage collection (requires c8)").option("--coverage-dir <dir>", "Coverage output directory (default: coverage-tryscript)").option("--coverage-reporter <reporter...>", "Coverage reporters (default: text, html). Can be specified multiple times.").action(runCommand);
|
|
283
|
+
program.command("run").description("Run golden tests").argument("[files...]", "Test files to run (default: **/*.tryscript.md)").option("--update", "Update golden files with actual output").option("--diff", "Show diff on failure (default: true)").option("--no-diff", "Hide diff on failure").option("--fail-fast", "Stop on first failure").option("--filter <pattern>", "Filter tests by name pattern").option("--verbose", "Show detailed output including passing test output").option("--quiet", "Suppress non-essential output (only show failures)").option("--coverage", "Enable code coverage collection (requires c8)").option("--coverage-dir <dir>", "Coverage output directory (default: coverage-tryscript)").option("--coverage-reporter <reporter...>", "Coverage reporters (default: text, html). Can be specified multiple times.").option("--coverage-exclude <pattern...>", "Patterns to exclude from coverage (c8 --exclude). Can be specified multiple times.").option("--coverage-exclude-node-modules", "Exclude node_modules from coverage (c8 --exclude-node-modules, default: true)").option("--no-coverage-exclude-node-modules", "Include node_modules in coverage (c8 --no-exclude-node-modules)").option("--coverage-exclude-after-remap", "Apply exclude logic after sourcemap remapping (c8 --exclude-after-remap)").option("--coverage-skip-full", "Hide files with 100% coverage (c8 --skip-full)").option("--coverage-allow-external", "Allow files from outside cwd (c8 --allowExternal)").option("--coverage-monocart", "Use monocart for accurate line counts, better for merging with vitest (c8 --experimental-monocart)").action(runCommand$1);
|
|
280
284
|
}
|
|
281
|
-
async function runCommand(files, options) {
|
|
285
|
+
async function runCommand$1(files, options) {
|
|
282
286
|
const startTime = Date.now();
|
|
283
287
|
const opts = {
|
|
284
288
|
diff: options.diff !== false,
|
|
@@ -308,7 +312,13 @@ async function runCommand(files, options) {
|
|
|
308
312
|
coverageCtx = await createCoverageContext({
|
|
309
313
|
...globalConfig.coverage,
|
|
310
314
|
reportsDir: options.coverageDir ?? globalConfig.coverage?.reportsDir,
|
|
311
|
-
reporters: options.coverageReporter ?? globalConfig.coverage?.reporters
|
|
315
|
+
reporters: options.coverageReporter ?? globalConfig.coverage?.reporters,
|
|
316
|
+
exclude: options.coverageExclude ?? globalConfig.coverage?.exclude,
|
|
317
|
+
excludeNodeModules: options.coverageExcludeNodeModules ?? globalConfig.coverage?.excludeNodeModules,
|
|
318
|
+
excludeAfterRemap: options.coverageExcludeAfterRemap ?? globalConfig.coverage?.excludeAfterRemap,
|
|
319
|
+
skipFull: options.coverageSkipFull ?? globalConfig.coverage?.skipFull,
|
|
320
|
+
allowExternal: options.coverageAllowExternal ?? globalConfig.coverage?.allowExternal,
|
|
321
|
+
monocart: options.coverageMonocart ?? globalConfig.coverage?.monocart
|
|
312
322
|
});
|
|
313
323
|
coverageEnv = getCoverageEnv(coverageCtx);
|
|
314
324
|
}
|
|
@@ -392,6 +402,223 @@ async function runCommand(files, options) {
|
|
|
392
402
|
process.exit(summary.totalFailed > 0 ? 1 : 0);
|
|
393
403
|
}
|
|
394
404
|
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/cli/commands/coverage.ts
|
|
407
|
+
/**
|
|
408
|
+
* Register the coverage command.
|
|
409
|
+
*/
|
|
410
|
+
function registerCoverageCommand(program) {
|
|
411
|
+
program.command("coverage").description("Run commands with merged V8 coverage").argument("<commands...>", "Commands to run (each will inherit coverage environment)").option("--reports-dir <dir>", "Coverage output directory (default: coverage)").option("--reporters <reporters>", "Comma-separated coverage reporters (default: text,json,json-summary,lcov,html)").option("--include <patterns>", "Comma-separated patterns to include in coverage").option("--exclude <patterns>", "Comma-separated patterns to exclude from coverage").option("--exclude-node-modules", "Exclude node_modules from coverage (default: true)", true).option("--no-exclude-node-modules", "Include node_modules in coverage").option("--exclude-after-remap", "Apply exclude logic after sourcemap remapping").option("--skip-full", "Hide files with 100% coverage").option("--allow-external", "Allow files from outside cwd").option("--monocart", "Use monocart for accurate line counts (recommended for merging)").option("--src <dir>", "Source directory for sourcemap remapping (default: src)").option("--verbose", "Show coverage summary after each command for debugging").action(coverageCommand);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Run a command with inherited coverage environment.
|
|
415
|
+
*/
|
|
416
|
+
async function runCommand(command, env) {
|
|
417
|
+
return new Promise((resolve$1) => {
|
|
418
|
+
const proc = spawn(command, [], {
|
|
419
|
+
stdio: "inherit",
|
|
420
|
+
env: {
|
|
421
|
+
...process.env,
|
|
422
|
+
...env
|
|
423
|
+
},
|
|
424
|
+
shell: true
|
|
425
|
+
});
|
|
426
|
+
proc.on("close", (code) => {
|
|
427
|
+
resolve$1({
|
|
428
|
+
success: code === 0,
|
|
429
|
+
code: code ?? 1
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
proc.on("error", (err) => {
|
|
433
|
+
logError(`Failed to run command: ${err.message}`);
|
|
434
|
+
resolve$1({
|
|
435
|
+
success: false,
|
|
436
|
+
code: 1
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Find the c8 executable path.
|
|
443
|
+
* Can be overridden via TRYSCRIPT_C8_COMMAND env var for testing.
|
|
444
|
+
*/
|
|
445
|
+
function findC8Path() {
|
|
446
|
+
const override = process.env.TRYSCRIPT_C8_COMMAND;
|
|
447
|
+
if (override) return override;
|
|
448
|
+
const localPaths = [resolve(process.cwd(), "node_modules", ".bin", "c8"), resolve(process.cwd(), "..", "..", "node_modules", ".bin", "c8")];
|
|
449
|
+
for (const localPath of localPaths) if (existsSync(localPath)) return localPath;
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Get coverage file statistics from temp directory.
|
|
454
|
+
*/
|
|
455
|
+
async function getCoverageStats(tempDir) {
|
|
456
|
+
try {
|
|
457
|
+
const coverageFiles = (await readdir(tempDir)).filter((f) => f.startsWith("coverage-") && f.endsWith(".json"));
|
|
458
|
+
let totalBytes = 0;
|
|
459
|
+
for (const file of coverageFiles) {
|
|
460
|
+
const fileStat = await stat(join(tempDir, file));
|
|
461
|
+
totalBytes += fileStat.size;
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
fileCount: coverageFiles.length,
|
|
465
|
+
totalBytes,
|
|
466
|
+
files: coverageFiles
|
|
467
|
+
};
|
|
468
|
+
} catch {
|
|
469
|
+
return {
|
|
470
|
+
fileCount: 0,
|
|
471
|
+
totalBytes: 0,
|
|
472
|
+
files: []
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Generate a text-only coverage report for debugging (doesn't write files).
|
|
478
|
+
*/
|
|
479
|
+
async function generateTextReport(tempDir, options, label) {
|
|
480
|
+
const c8Path = findC8Path();
|
|
481
|
+
if (!c8Path) return;
|
|
482
|
+
const include = options.include ?? ["dist/**"];
|
|
483
|
+
const exclude = options.exclude ?? [];
|
|
484
|
+
const tempReportsDir = await mkdtemp(join(tmpdir(), "tryscript-coverage-report-"));
|
|
485
|
+
const reportArgs = [
|
|
486
|
+
"report",
|
|
487
|
+
"--temp-directory",
|
|
488
|
+
tempDir,
|
|
489
|
+
"--reports-dir",
|
|
490
|
+
tempReportsDir,
|
|
491
|
+
"--src",
|
|
492
|
+
options.src ?? "src",
|
|
493
|
+
"--all",
|
|
494
|
+
...include.flatMap((pattern) => ["--include", pattern]),
|
|
495
|
+
...exclude.flatMap((pattern) => ["--exclude", pattern]),
|
|
496
|
+
...options.excludeNodeModules !== false ? ["--exclude-node-modules"] : ["--no-exclude-node-modules"],
|
|
497
|
+
...options.excludeAfterRemap ? ["--exclude-after-remap"] : [],
|
|
498
|
+
...options.monocart ? ["--experimental-monocart"] : [],
|
|
499
|
+
"--reporter",
|
|
500
|
+
"text"
|
|
501
|
+
];
|
|
502
|
+
console.error(colors.info(`\n--- Coverage after: ${label} ---`));
|
|
503
|
+
await new Promise((resolve$1) => {
|
|
504
|
+
const proc = spawn(c8Path, reportArgs, {
|
|
505
|
+
stdio: "inherit",
|
|
506
|
+
shell: false
|
|
507
|
+
});
|
|
508
|
+
proc.on("close", () => {
|
|
509
|
+
resolve$1();
|
|
510
|
+
});
|
|
511
|
+
proc.on("error", () => {
|
|
512
|
+
resolve$1();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
await rm(tempReportsDir, {
|
|
516
|
+
recursive: true,
|
|
517
|
+
force: true
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Generate c8 coverage report.
|
|
522
|
+
*/
|
|
523
|
+
async function generateReport(tempDir, options) {
|
|
524
|
+
const c8Path = findC8Path();
|
|
525
|
+
if (!c8Path) {
|
|
526
|
+
logError("c8 not found. Install with: npm install -D c8");
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
const reporters = options.reporters ?? [
|
|
530
|
+
"text",
|
|
531
|
+
"json",
|
|
532
|
+
"json-summary",
|
|
533
|
+
"lcov",
|
|
534
|
+
"html"
|
|
535
|
+
];
|
|
536
|
+
const include = options.include ?? ["dist/**"];
|
|
537
|
+
const exclude = options.exclude ?? [];
|
|
538
|
+
const reportArgs = [
|
|
539
|
+
"report",
|
|
540
|
+
"--temp-directory",
|
|
541
|
+
tempDir,
|
|
542
|
+
"--reports-dir",
|
|
543
|
+
options.reportsDir ?? "coverage",
|
|
544
|
+
"--src",
|
|
545
|
+
options.src ?? "src",
|
|
546
|
+
"--all",
|
|
547
|
+
...include.flatMap((pattern) => ["--include", pattern]),
|
|
548
|
+
...exclude.flatMap((pattern) => ["--exclude", pattern]),
|
|
549
|
+
...options.excludeNodeModules !== false ? ["--exclude-node-modules"] : ["--no-exclude-node-modules"],
|
|
550
|
+
...options.excludeAfterRemap ? ["--exclude-after-remap"] : [],
|
|
551
|
+
...options.skipFull ? ["--skip-full"] : [],
|
|
552
|
+
...options.allowExternal ? ["--allowExternal"] : [],
|
|
553
|
+
...options.monocart ? ["--experimental-monocart"] : [],
|
|
554
|
+
...reporters.flatMap((reporter) => ["--reporter", reporter])
|
|
555
|
+
];
|
|
556
|
+
return new Promise((resolve$1) => {
|
|
557
|
+
const proc = spawn(c8Path, reportArgs, {
|
|
558
|
+
stdio: "inherit",
|
|
559
|
+
shell: false
|
|
560
|
+
});
|
|
561
|
+
proc.on("close", (code) => {
|
|
562
|
+
resolve$1(code === 0);
|
|
563
|
+
});
|
|
564
|
+
proc.on("error", (err) => {
|
|
565
|
+
logError(`Failed to generate coverage report: ${err.message}`);
|
|
566
|
+
resolve$1(false);
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
async function coverageCommand(commands, options) {
|
|
571
|
+
if (commands.length === 0) {
|
|
572
|
+
logError("No commands specified. Usage: tryscript coverage \"cmd1\" \"cmd2\"");
|
|
573
|
+
process.exit(1);
|
|
574
|
+
}
|
|
575
|
+
if (!findC8Path()) {
|
|
576
|
+
logError("Coverage requires c8. Install with: npm install -D c8");
|
|
577
|
+
process.exit(1);
|
|
578
|
+
}
|
|
579
|
+
const parsedOptions = {
|
|
580
|
+
...options,
|
|
581
|
+
reporters: options.reporters ? typeof options.reporters === "string" ? options.reporters.split(",") : options.reporters : void 0,
|
|
582
|
+
include: options.include ? typeof options.include === "string" ? options.include.split(",") : options.include : void 0,
|
|
583
|
+
exclude: options.exclude ? typeof options.exclude === "string" ? options.exclude.split(",") : options.exclude : void 0
|
|
584
|
+
};
|
|
585
|
+
const coverageTemp = await mkdtemp(join(tmpdir(), "tryscript-coverage-"));
|
|
586
|
+
const coverageEnv = { NODE_V8_COVERAGE: coverageTemp };
|
|
587
|
+
console.error(colors.info(`Collecting V8 coverage to ${coverageTemp}`));
|
|
588
|
+
let hasFailures = false;
|
|
589
|
+
let previousFileCount = 0;
|
|
590
|
+
try {
|
|
591
|
+
for (let i = 0; i < commands.length; i++) {
|
|
592
|
+
const command = commands[i];
|
|
593
|
+
console.error(colors.info(`\n=== Running command ${i + 1}/${commands.length}: ${command} ===`));
|
|
594
|
+
const result = await runCommand(command, coverageEnv);
|
|
595
|
+
if (!result.success) {
|
|
596
|
+
logWarn(`Command exited with code ${result.code}: ${command}`);
|
|
597
|
+
hasFailures = true;
|
|
598
|
+
}
|
|
599
|
+
const stats = await getCoverageStats(coverageTemp);
|
|
600
|
+
const newFiles = stats.fileCount - previousFileCount;
|
|
601
|
+
const bytesKB = (stats.totalBytes / 1024).toFixed(1);
|
|
602
|
+
console.error(colors.info(`\nV8 coverage: ${stats.fileCount} files (${newFiles} new), ${bytesKB} KB total`));
|
|
603
|
+
if (newFiles === 0) logWarn("No new coverage files from this command. This may indicate the command doesn't write to NODE_V8_COVERAGE.");
|
|
604
|
+
if (parsedOptions.verbose && stats.fileCount > 0) await generateTextReport(coverageTemp, parsedOptions, command);
|
|
605
|
+
previousFileCount = stats.fileCount;
|
|
606
|
+
}
|
|
607
|
+
console.error(colors.info("\n=== Generating merged coverage report ==="));
|
|
608
|
+
if (!await generateReport(coverageTemp, parsedOptions)) {
|
|
609
|
+
logError("Failed to generate coverage report");
|
|
610
|
+
process.exit(1);
|
|
611
|
+
}
|
|
612
|
+
console.error(colors.success(`\nCoverage report written to ${parsedOptions.reportsDir ?? "coverage"}/`));
|
|
613
|
+
} finally {
|
|
614
|
+
await rm(coverageTemp, {
|
|
615
|
+
recursive: true,
|
|
616
|
+
force: true
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (hasFailures) process.exit(1);
|
|
620
|
+
}
|
|
621
|
+
|
|
395
622
|
//#endregion
|
|
396
623
|
//#region src/cli/commands/readme.ts
|
|
397
624
|
/**
|
|
@@ -471,7 +698,7 @@ function isInteractive$1() {
|
|
|
471
698
|
*/
|
|
472
699
|
function showReadme(options) {
|
|
473
700
|
try {
|
|
474
|
-
const formatted = formatMarkdown$1(loadReadme(), !options?.raw && isInteractive$1());
|
|
701
|
+
const formatted = formatMarkdown$1(loadReadme(), options?.color ?? (!options?.raw && isInteractive$1()));
|
|
475
702
|
console.log(formatted);
|
|
476
703
|
} catch (error) {
|
|
477
704
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -483,7 +710,7 @@ function showReadme(options) {
|
|
|
483
710
|
* Register the readme command.
|
|
484
711
|
*/
|
|
485
712
|
function registerReadmeCommand(program) {
|
|
486
|
-
program.command("readme").description("Display README documentation").option("--raw", "Output raw markdown without formatting").action(showReadme);
|
|
713
|
+
program.command("readme").description("Display README documentation").option("--raw", "Output raw markdown without formatting").option("--color", "Force colorized output (for testing)").action(showReadme);
|
|
487
714
|
}
|
|
488
715
|
|
|
489
716
|
//#endregion
|
|
@@ -563,9 +790,9 @@ function isInteractive() {
|
|
|
563
790
|
* Register the docs command.
|
|
564
791
|
*/
|
|
565
792
|
function registerDocsCommand(program) {
|
|
566
|
-
program.command("docs").description("Display concise syntax reference").option("--raw", "Output raw markdown without formatting").action((options) => {
|
|
793
|
+
program.command("docs").description("Display concise syntax reference").option("--raw", "Output raw markdown without formatting").option("--color", "Force colorized output (for testing)").action((options) => {
|
|
567
794
|
try {
|
|
568
|
-
const formatted = formatMarkdown(loadDocs(), !options.raw && isInteractive());
|
|
795
|
+
const formatted = formatMarkdown(loadDocs(), options.color ?? (!options.raw && isInteractive()));
|
|
569
796
|
console.log(formatted);
|
|
570
797
|
} catch (error) {
|
|
571
798
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -585,6 +812,7 @@ function registerDocsCommand(program) {
|
|
|
585
812
|
function run(argv) {
|
|
586
813
|
const program = withColoredHelp(new Command().name("tryscript").version(VERSION, "--version", "Show version number").description("Golden testing for CLI applications").showHelpAfterError("(use --help for usage)"));
|
|
587
814
|
registerRunCommand(program);
|
|
815
|
+
registerCoverageCommand(program);
|
|
588
816
|
registerReadmeCommand(program);
|
|
589
817
|
registerDocsCommand(program);
|
|
590
818
|
program.action(() => {
|