Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit a57cf4f

Browse files
committed
split up jj into cmomands, remove dead code
1 parent f734eb4 commit a57cf4f

70 files changed

Lines changed: 3530 additions & 3367 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CLAUDE.md‎

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
### Avoid Barrel Files
4646

4747
Barrel files:
48+
4849
- Break tree-shaking
49-
- Create circular dependency risks
50+
- Create circular dependency risks
5051
- Hide the true source of imports
5152
- Make refactoring harder
5253

@@ -82,10 +83,6 @@ See [ARCHITECTURE.md](./ARCHITECTURE.md) for detailed patterns (DI, services, tR
8283
### Core Package (packages/core)
8384

8485
- Shared business logic for jj/GitHub operations
85-
- `pnpm --filter @array/core test` - Run bun tests
86-
- `pnpm --filter @array/core typecheck` - Type check
87-
- Uses Bun's test runner with `mock()` for test doubles
88-
- Test helpers in `tests/helpers/` (MockGitHub, TestRepo, withTestRepo)
8986

9087
## Key Libraries
9188

@@ -106,29 +103,3 @@ TODO: Update me
106103

107104
- `pnpm test` - Run tests across all packages
108105
- Array app: Vitest with jsdom, helpers in `apps/array/src/test/`
109-
- Core package: Bun test runner, helpers in `packages/core/tests/helpers/`
110-
111-
### Running Specific Tests (Bun)
112-
113-
```bash
114-
# Run all tests in a directory
115-
bun test tests/integration
116-
117-
# Run a specific test file
118-
bun test tests/integration/sync/sync.test.ts
119-
120-
# Run tests matching a pattern (--test-name-pattern / -t)
121-
bun test -t "sync fetches"
122-
123-
# Run with concurrency (default: 20)
124-
bun test --concurrent
125-
126-
# Limit concurrent tests
127-
bun test --concurrent --max-concurrency 10
128-
129-
# Increase timeout (default: 5000ms)
130-
bun test --timeout 15000
131-
132-
# Watch mode
133-
bun test --watch
134-
```

‎apps/cli/src/cli.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
type CommandInfo,
66
getCommandsByCategory,
77
getCoreCommands,
8-
} from "@array/core";
8+
getRequiredContext,
9+
resolveCommandAlias,
10+
} from "@array/core/commands";
911
import { auth } from "./commands/auth";
1012
import { bottom } from "./commands/bottom";
1113
import { checkout } from "./commands/checkout";
@@ -19,6 +21,7 @@ import { exit } from "./commands/exit";
1921
import { init } from "./commands/init";
2022
import { log } from "./commands/log";
2123
import { merge } from "./commands/merge";
24+
import { restack } from "./commands/restack";
2225
import { squash } from "./commands/squash";
2326
import { status } from "./commands/status";
2427
import { submit } from "./commands/submit";
@@ -27,6 +30,7 @@ import { top } from "./commands/top";
2730
import { trunk } from "./commands/trunk";
2831
import { undo } from "./commands/undo";
2932
import { up } from "./commands/up";
33+
import { type ParsedCommand, parseArgs } from "./utils/args";
3034
import {
3135
checkContext,
3236
isContextValid,
@@ -41,12 +45,6 @@ import {
4145
hint,
4246
message,
4347
} from "./utils/output";
44-
import {
45-
getRequiredContext,
46-
type ParsedCommand,
47-
parseArgs,
48-
resolveCommandAlias,
49-
} from "./utils/parser";
5048

5149
type CommandHandler = (parsed: ParsedCommand) => Promise<void>;
5250

@@ -64,6 +62,7 @@ const COMMANDS: Record<string, CommandHandler> = {
6462
bottom: () => bottom(),
6563
log: () => log(),
6664
sync: () => sync(),
65+
restack: () => restack(),
6766
checkout: (p) => checkout(p.args[0]),
6867
delete: (p) => deleteChange(p.args[0], { yes: !!p.flags.yes || !!p.flags.y }),
6968
squash: (p) => squash(p.args[0]),

‎apps/cli/src/commands/auth.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
2-
COMMANDS,
32
checkGhAuth,
43
ghAuthLogin,
54
isGhInstalled,
65
saveAuthState,
7-
} from "@array/core";
6+
} from "@array/core/auth";
7+
import { COMMANDS } from "@array/core/commands";
88
import {
99
arr,
1010
blank,

‎apps/cli/src/commands/bottom.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { bottom as bottomCommand } from "@array/core/commands/bottom";
12
import { printNav } from "../utils/output";
2-
import { createJJ, unwrap } from "../utils/run";
3+
import { unwrap } from "../utils/run";
34

45
export async function bottom(): Promise<void> {
5-
printNav("down", unwrap(await createJJ().navigateBottom()));
6+
printNav("down", unwrap(await bottomCommand()));
67
}

‎apps/cli/src/commands/checkout.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { changeLabel } from "@array/core";
1+
import { checkout as checkoutCmd } from "@array/core/commands/checkout";
2+
import { changeLabel } from "@array/core/slugify";
23
import { cyan, dim, formatSuccess, message } from "../utils/output";
3-
import { createJJ, findChange, requireArg, unwrap } from "../utils/run";
4+
import { findChange, requireArg, unwrap } from "../utils/run";
45

56
export async function checkout(id: string): Promise<void> {
67
requireArg(id, "Usage: arr checkout <id>");
7-
const jj = createJJ();
88

99
// Handle trunk checkout - creates new empty change on main
1010
if (id === "main" || id === "master" || id === "trunk") {
11-
unwrap(await jj.new({ parents: [id === "trunk" ? "trunk()" : id] }));
11+
unwrap(await checkoutCmd(id));
1212
message(formatSuccess(`Switched to ${cyan(id)}`));
1313
return;
1414
}
1515

16-
const change = await findChange(jj, id, { includeBookmarks: true });
17-
unwrap(await jj.edit(change.changeId));
16+
// For other targets, resolve via findChange first
17+
const change = await findChange(id, { includeBookmarks: true });
18+
unwrap(await checkoutCmd(change.changeId));
1819

1920
const label = changeLabel(change.description, change.changeId);
2021
message(

‎apps/cli/src/commands/ci.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
enableStackCheckProtection,
44
getBranchProtectionUrl,
55
getRepoInfoFromRemote,
6-
JJ,
76
setupCI,
8-
shellExecutor,
9-
} from "@array/core";
7+
} from "@array/core/ci";
8+
import { shellExecutor } from "@array/core/executor";
9+
import { getTrunk } from "@array/core/jj";
1010
import {
1111
blank,
1212
cyan,
@@ -90,8 +90,7 @@ async function tryEnableProtection(
9090
repoInfo: { owner: string; repo: string },
9191
isUpdate: boolean,
9292
): Promise<boolean> {
93-
const jj = new JJ({ cwd });
94-
const trunk = await jj.getTrunk();
93+
const trunk = await getTrunk(cwd);
9594

9695
status(isUpdate ? "Updating ruleset..." : `Creating ruleset for ${trunk}...`);
9796

‎apps/cli/src/commands/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
createDefaultUserConfig,
33
loadUserConfig,
44
saveUserConfig,
5-
} from "@array/core";
5+
} from "@array/core/config";
66
import {
77
blank,
88
bold,

‎apps/cli/src/commands/create.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { COMMANDS, datePrefixedLabel } from "@array/core";
1+
import { COMMANDS } from "@array/core/commands";
2+
import { create as createCmd } from "@array/core/commands/create";
23
import {
34
arr,
45
cyan,
@@ -7,7 +8,7 @@ import {
78
indent,
89
message,
910
} from "../utils/output";
10-
import { createJJ, requireArg, unwrap } from "../utils/run";
11+
import { requireArg, unwrap } from "../utils/run";
1112
import { showTip } from "../utils/tips";
1213

1314
export async function create(msg: string): Promise<void> {
@@ -16,10 +17,9 @@ export async function create(msg: string): Promise<void> {
1617
"Usage: arr create <description>\n Creates a change with current file modifications",
1718
);
1819

19-
unwrap(await createJJ().create({ message: msg, all: true }));
20+
const result = unwrap(await createCmd(msg));
2021

21-
const label = datePrefixedLabel(msg, new Date());
22-
message(formatSuccess(`Created ${cyan(label)}`));
22+
message(formatSuccess(`Created ${cyan(result.bookmarkName)}`));
2323
indent(
2424
`${dim("Run")} ${arr(COMMANDS.submit.name)} ${dim("to create a PR, or keep editing")}`,
2525
);

‎apps/cli/src/commands/delete.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { changeLabel } from "@array/core";
1+
import { deleteChange as deleteCmd } from "@array/core/commands/delete";
2+
import { changeLabel } from "@array/core/slugify";
23
import {
34
cyan,
45
dim,
@@ -9,16 +10,15 @@ import {
910
yellow,
1011
} from "../utils/output";
1112
import { confirm } from "../utils/prompt";
12-
import { createJJ, findChange, requireArg, unwrap } from "../utils/run";
13+
import { findChange, requireArg, unwrap } from "../utils/run";
1314

1415
export async function deleteChange(
1516
id: string,
1617
options?: { yes?: boolean },
1718
): Promise<void> {
1819
requireArg(id, "Usage: arr delete <id>");
19-
const jj = createJJ();
2020

21-
const change = await findChange(jj, id);
21+
const change = await findChange(id);
2222
const label = changeLabel(change.description, change.changeId);
2323

2424
// Confirm deletion since work will be lost
@@ -32,7 +32,7 @@ export async function deleteChange(
3232
return;
3333
}
3434

35-
const result = unwrap(await jj.delete(change.changeId));
35+
const result = unwrap(await deleteCmd(change.changeId));
3636

3737
message(formatSuccess(`Deleted change ${cyan(label)}`));
3838

‎apps/cli/src/commands/down.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { COMMANDS } from "@array/core";
1+
import { COMMANDS } from "@array/core/commands";
2+
import { down as downCommand } from "@array/core/commands/down";
23
import {
34
arr,
45
cyan,
@@ -8,10 +9,10 @@ import {
89
hint,
910
message,
1011
} from "../utils/output";
11-
import { createJJ, unwrap } from "../utils/run";
12+
import { unwrap } from "../utils/run";
1213

1314
export async function down(): Promise<void> {
14-
const result = unwrap(await createJJ().navigateDown());
15+
const result = unwrap(await downCommand());
1516

1617
if (result.createdOnTrunk) {
1718
message(`${green("◉")} Started fresh on ${cyan("main")}`);

0 commit comments

Comments
 (0)