operations.ts

Declarations
#

Operations interfaces for dependency injection.

This is the core pattern enabling testability without mocks. All side effects (git, npm, fs, process) are abstracted into interfaces.

Design principles: - All operations accept a single options object parameter - All fallible operations return Result from @ryanatkn/belt - Never throw Error in operations - return Result with ok: false - Use null for expected "not found" cases (not errors) - Include log?: Logger in options where logging is useful

Production usage: ```typescript import {default_gitops_operations} from './operations_defaults.js'; const result = await ops.git.current_branch_name({cwd: '/path'}); if (!result.ok) { throw new TaskError(result.message); } const branch = result.value; ```

Test usage: ```typescript const mock_ops = create_mock_operations(); const result = await publish_repos(repos, {...options, ops: mock_ops}); // Assert on result without any real git/npm calls ```

See operations_defaults.ts for real implementations. See test files (*.test.ts) for mock implementations.

8 declarations

view source

BuildOperations
#

operations.ts view source

BuildOperations

Build operations for validating packages compile before publishing.

build_package

Builds a package using gro build.

type (options: { repo: LocalRepo; log?: Logger; }) => Promise<Result<object, {message: string; output?: string}>>

ChangesetOperations
#

operations.ts view source

ChangesetOperations

Changeset operations for reading and predicting versions from .changeset/*.md files.

has_changesets

Checks if a repo has any changeset files. Returns true if changesets exist, false if none found.

type (options: { repo: LocalRepo; }) => Promise<Result<{value: boolean}, {message: string}>>

read_changesets

Reads all changeset files from a repo. Returns array of changeset info, or error if reading fails.

type (options: { repo: LocalRepo; log?: Logger; }) => Promise<Result<{value: Array<ChangesetInfo>}, {message: string}>>

predict_next_version

Predicts the next version based on changesets. Returns null if no changesets found (expected, not an error). Returns error Result if changesets exist but can't be read/parsed.

type (options: { repo: LocalRepo; log?: Logger; }) => Promise<Result<{version: string; bump_type: BumpType}, {message: string}> | null>

FsOperations
#

operations.ts view source

FsOperations

File system operations for reading and writing files.

readFile

Reads a file from the file system.

type (options: { path: string; encoding: BufferEncoding; }) => Promise<Result<{value: string}, {message: string}>>

writeFile

Writes a file to the file system.

type (options: { path: string; content: string; }) => Promise<Result<object, {message: string}>>

GitOperations
#

operations.ts view source

GitOperations

Git operations for branch management, commits, tags, and workspace state. All operations return Result instead of throwing errors.

current_branch_name

Gets the current branch name.

type (options?: { cwd?: string; }) => Promise<Result<{value: string}, {message: string}>>

current_commit_hash

Gets the current commit hash.

type (options?: { branch?: string; cwd?: string; }) => Promise<Result<{value: string}, {message: string}>>

check_clean_workspace

Checks if the workspace is clean (no uncommitted changes).

type (options?: { cwd?: string; }) => Promise<Result<{value: boolean}, {message: string}>>

checkout

Checks out a branch.

type (options: {branch: string; cwd?: string}) => Promise<Result<object, {message: string}>>

pull

Pulls changes from remote.

type (options?: { origin?: string; branch?: string; cwd?: string; }) => Promise<Result<object, {message: string}>>

switch_branch

Switches to a branch, optionally pulling.

type (options: { branch: string; pull?: boolean; cwd?: string; }) => Promise<Result<object, {message: string}>>

has_remote

Checks if a remote exists.

type (options?: { remote?: string; cwd?: string; }) => Promise<Result<{value: boolean}, {message: string}>>

add

Stages files for commit.

type (options: { files: string | Array<string>; cwd?: string; }) => Promise<Result<object, {message: string}>>

commit

Creates a commit.

type (options: {message: string; cwd?: string}) => Promise<Result<object, {message: string}>>

add_and_commit

Stages files and creates a commit.

type (options: { files: string | Array<string>; message: string; cwd?: string; }) => Promise<Result<object, {message: string}>>

has_changes

Checks if there are any uncommitted changes.

type (options?: {cwd?: string}) => Promise<Result<{value: boolean}, {message: string}>>

get_changed_files

Gets a list of changed files.

type (options?: { cwd?: string; }) => Promise<Result<{value: Array<string>}, {message: string}>>

tag

Creates a git tag.

type (options: { tag_name: string; message?: string; cwd?: string; }) => Promise<Result<object, {message: string}>>

push_tag

Pushes a tag to remote.

type (options: { tag_name: string; origin?: string; cwd?: string; }) => Promise<Result<object, {message: string}>>

stash

Stashes uncommitted changes.

type (options?: {message?: string; cwd?: string}) => Promise<Result<object, {message: string}>>

stash_pop

Pops the most recent stash.

type (options?: {cwd?: string}) => Promise<Result<object, {message: string}>>

has_file_changed

Checks if a specific file changed between two commits.

type (options: { from_commit: string; to_commit: string; file_path: string; cwd?: string; }) => Promise<Result<{value: boolean}, {message: string}>>

GitopsOperations
#

NpmOperations
#

operations.ts view source

NpmOperations

NPM registry operations for package availability checks and authentication. Includes exponential backoff for waiting on package propagation.

wait_for_package

Waits for a package version to be available on NPM. Uses exponential backoff with configurable timeout.

type (options: { pkg: string; version: string; wait_options?: WaitOptions; log?: Logger; }) => Promise<Result<object, {message: string; timeout?: boolean}>>

check_package_available

Checks if a package version is available on NPM.

type (options: { pkg: string; version: string; log?: Logger; }) => Promise<Result<{value: boolean}, {message: string}>>

check_auth

Checks npm authentication status.

type () => Promise<Result<{username: string}, {message: string}>>

check_registry

Checks if npm registry is reachable.

type () => Promise<Result<object, {message: string}>>

install

Installs npm dependencies.

type (options?: { cwd?: string; }) => Promise<Result<object, {message: string; stderr?: string}>>

cache_clean

Cleans the npm cache. Uses npm cache clean --force to clear stale cache entries.

type () => Promise<Result<object, {message: string}>>

PreflightOperations
#

operations.ts view source

PreflightOperations

Preflight validation operations to ensure repos are ready for publishing. Validates workspace state, branches, builds, and npm authentication.

run_preflight_checks

Runs preflight validation checks before publishing.

type (options: { repos: Array<LocalRepo>; preflight_options: PreflightOptions; git_ops?: GitOperations; npm_ops?: NpmOperations; build_ops?: BuildOperations; changeset_ops?: ChangesetOperations; }) => Promise<PreflightResult>

ProcessOperations
#

operations.ts view source

ProcessOperations

Process spawning operations for running shell commands.

spawn

Spawns a child process and waits for completion.

type (options: { cmd: string; args: Array<string>; spawn_options?: SpawnOptions; }) => Promise<Result<{stdout?: string; stderr?: string}, {message: string; stderr?: string}>>