Skip to content

Commit 0215a5d

Browse files
committed
chore: rework some interfaces
1 parent 3b29e8e commit 0215a5d

13 files changed

Lines changed: 96 additions & 93 deletions

.changeset/shy-views-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fuzdev/fuz_gitops': minor
3+
---
4+
5+
chore: rework some interfaces

src/lib/changeset_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const create_changeset_for_dependency_updates = async (
3636
const changesets_dir = join(repo.repo_dir, '.changeset');
3737

3838
// Ensure .changeset directory exists
39-
if (!fs_ops.exists({path: changesets_dir})) {
39+
if (!(await fs_ops.exists({path: changesets_dir}))) {
4040
const mkdir_result = await fs_ops.mkdir({path: changesets_dir, recursive: true});
4141
if (!mkdir_result.ok) {
4242
throw new Error(`Failed to create .changeset directory: ${mkdir_result.message}`);

src/lib/git_operations.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ export const git_has_changes = async (options?: SpawnOptions): Promise<boolean>
8686
};
8787

8888
/**
89-
* Returns list of changed files compared to HEAD.
89+
* Lists uncommitted files in the working tree (`git diff --name-only HEAD`).
9090
*/
91-
export const git_get_changed_files = async (options?: SpawnOptions): Promise<Array<string>> => {
91+
export const git_list_uncommitted_files = async (
92+
options?: SpawnOptions,
93+
): Promise<Array<string>> => {
9294
const {stdout} = await spawn_out('git', ['diff', '--name-only', 'HEAD'], options);
9395
if (!stdout) return [];
9496

src/lib/multi_repo_publisher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export const publish_repos = async (
337337
const deploy_result = await ops.process.spawn({
338338
cmd: 'gro',
339339
args: ['deploy', '--no-build'],
340-
spawn_options: {cwd: repo.repo_dir},
340+
cwd: repo.repo_dir,
341341
});
342342

343343
if (deploy_result.ok) {
@@ -426,7 +426,7 @@ const publish_single_repo = async (
426426
const publish_result = await ops.process.spawn({
427427
cmd: 'gro',
428428
args: ['publish', '--no-build'],
429-
spawn_options: {cwd: repo.repo_dir},
429+
cwd: repo.repo_dir,
430430
});
431431

432432
if (!publish_result.ok) {

src/lib/operations.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import type {Result} from '@fuzdev/fuz_util/result.js';
3838
import type {Logger} from '@fuzdev/fuz_util/log.js';
39-
import type {SpawnOptions} from 'node:child_process';
4039
import type {LocalRepo} from './local_repo.js';
4140
import type {ChangesetInfo} from './changeset_reader.js';
4241
import type {BumpType} from './semver.js';
@@ -161,9 +160,13 @@ export interface GitOperations {
161160
has_changes: (options?: {cwd?: string}) => Promise<Result<{value: boolean}, {message: string}>>;
162161

163162
/**
164-
* Gets a list of changed files.
163+
* Lists uncommitted files in the working tree (`git diff --name-only HEAD`).
164+
*
165+
* Renamed from `get_changed_files` in 2026-04 because "changed files" collided
166+
* with mageguild's `get_changed_files` which diffs two refs. This one reports
167+
* uncommitted working-tree changes relative to HEAD.
165168
*/
166-
get_changed_files: (options?: {
169+
list_uncommitted_files: (options?: {
167170
cwd?: string;
168171
}) => Promise<Result<{value: Array<string>}, {message: string}>>;
169172

@@ -216,7 +219,7 @@ export interface ProcessOperations {
216219
spawn: (options: {
217220
cmd: string;
218221
args: Array<string>;
219-
spawn_options?: SpawnOptions;
222+
cwd?: string;
220223
}) => Promise<Result<{stdout?: string; stderr?: string}, {message: string; stderr?: string}>>;
221224
}
222225

@@ -331,7 +334,7 @@ export interface FsOperations {
331334
/**
332335
* Checks if a path exists on the file system.
333336
*/
334-
exists: (options: {path: string}) => boolean;
337+
exists: (options: {path: string}) => Promise<boolean>;
335338
}
336339

337340
/**

src/lib/operations_defaults.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
*/
99

1010
import {spawn_out} from '@fuzdev/fuz_util/process.js';
11-
import {readFile, writeFile, mkdir} from 'node:fs/promises';
12-
import {existsSync} from 'node:fs';
11+
import {readFile, writeFile, mkdir, stat} from 'node:fs/promises';
1312
import {git_checkout, type GitBranch, type GitOrigin} from '@fuzdev/fuz_util/git.js';
1413
import {EMPTY_OBJECT} from '@fuzdev/fuz_util/object.js';
1514

@@ -23,7 +22,7 @@ import {
2322
git_tag,
2423
git_push_tag,
2524
git_has_changes,
26-
git_get_changed_files,
25+
git_list_uncommitted_files,
2726
git_has_file_changed,
2827
git_stash,
2928
git_stash_pop,
@@ -165,9 +164,9 @@ export const default_git_operations: GitOperations = {
165164
return wrap_with_value(() => git_has_changes(cwd ? {cwd} : undefined));
166165
},
167166

168-
get_changed_files: async (options) => {
167+
list_uncommitted_files: async (options) => {
169168
const {cwd} = options ?? EMPTY_OBJECT;
170-
return wrap_with_value(() => git_get_changed_files(cwd ? {cwd} : undefined));
169+
return wrap_with_value(() => git_list_uncommitted_files(cwd ? {cwd} : undefined));
171170
},
172171

173172
// Tagging
@@ -203,9 +202,9 @@ export const default_git_operations: GitOperations = {
203202

204203
export const default_process_operations: ProcessOperations = {
205204
spawn: async (options) => {
206-
const {cmd, args, spawn_options} = options;
205+
const {cmd, args, cwd} = options;
207206
try {
208-
const spawned = await spawn_out(cmd, args, spawn_options);
207+
const spawned = await spawn_out(cmd, args, cwd ? {cwd} : undefined);
209208
if (spawned.result.ok) {
210209
return {
211210
ok: true,
@@ -318,8 +317,13 @@ export const default_fs_operations: FsOperations = {
318317
return wrap_void(() => mkdir(path, {recursive}));
319318
},
320319

321-
exists: (options) => {
322-
return existsSync(options.path);
320+
exists: async (options) => {
321+
try {
322+
await stat(options.path);
323+
return true;
324+
} catch {
325+
return false;
326+
}
323327
},
324328
};
325329

src/lib/preflight_checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const run_preflight_checks = async ({
9999

100100
if (!clean_result.value) {
101101
// Get list of changed files for better error message
102-
const files_result = await git_ops.get_changed_files({cwd: repo.repo_dir}); // eslint-disable-line no-await-in-loop
102+
const files_result = await git_ops.list_uncommitted_files({cwd: repo.repo_dir}); // eslint-disable-line no-await-in-loop
103103
if (files_result.ok) {
104104
// No filtering - workspace must be 100% clean
105105
const unexpected_files = files_result.value;

0 commit comments

Comments
 (0)