CodeVetter · Repo Unpack · Data flow
chromaui/chromatic-cli
Inputs enter through argv, Action fields, Node options, configuration, and selected process environment variables. A shared Context accumulates normalized metadata and task outputs, while extract/apply adapters mediate most state changes. Artifact paths and hashes become upload descriptors, remote publication becomes build-result state, and result counts leave through the Node return object or Action outputs. Diagnostics and TurboSnap manifests form additional persistence and upload channels.
- getPartialOptions merges defaults, configurationOptions, optionsFromFlags, then extraOptions; it subsequently computes interactive mode from CI, debug, the CLI flag, stdout TTY, and NODE_ENV.
- getConfiguration reads JSON5-compatible content from the first existing explicit/default candidate, validates a strict partial Zod schema, and returns the selected configFile path; a missing default config yields an empty object.
- runAuth exchanges userToken plus projectId for a CLI token or projectToken for an app token, then installs that token as GraphQLClient's default Bearer authorization; publishBuild overrides it with reportToken.
- gatherGitInfo combines local Git/CI commit information, uncommitted hashes, root paths, and clone diagnostics; announceBuild transforms that state into API input, hashes gitUserEmail, converts committedAt to Date, and requests baselines when TurboSnap has not bailed.
- validateFiles recursively enumerates artifact sizes, excludes the root .chromatic directory, normalizes names to POSIX, separates preview stats from upload paths, and can replace sourceDir with an output directory found in the build log.
- prepareProject traces affected files before calculating artifact hashes; v2 separately rolls transitive story dependencies and Storybook-wide categories into hash maps, writes a JSON manifest, and sends only aggregate/config/story hashes through BuildUploadHashes.
- buildFileList maps validated relative paths into localPath/targetPath/contentLength/contentHash descriptors; uploadBuild negotiates batches and joins returned targets to local descriptors, then uploadFiles streams multipart POSTs with concurrency 10 and per-file retries.
- Completed build state supplies run's output counts and optional JUnit XML; after runBuild, diagnostics redact projectToken/reportToken/userToken, metadata is conditionally uploaded, and implicit log/diagnostic files are removed unless persistence was requested.