Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Run reconciliation explicitly when GitHub history must be re-read:

```bash
# Reconcile one explicit registered repository by owner/name.
pnpm reconcile -- --repository <owner>/<name>
pnpm reconcile --repository <owner>/<name>

# Reconcile every active registered repository.
pnpm reconcile
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"db:migrate": "node scripts/migrate.ts",
"release:switch": "node scripts/release.ts switch",
"release:prune": "node scripts/release.ts prune",
"reconcile": "node scripts/reconcile.ts"
"reconcile": "node --experimental-transform-types --import ./scripts/register-path-aliases.ts scripts/reconcile.ts"
},
"dependencies": {
"next": "16.3.4",
Expand Down
25 changes: 17 additions & 8 deletions scripts/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ export async function runReconciliationCli(
): Promise<void>;
export async function runReconciliationCli(
argumentsList: readonly string[] = process.argv.slice(2),
dependencies: ReconcileCliDependencies = productionDependencies(),
dependencies?: ReconcileCliDependencies,
): Promise<void> {
const repositoryIds = await repositoryIdsForArguments(argumentsList, dependencies.store);
const ownerName = parseArguments(argumentsList);
dependencies ??= productionDependencies();
const repositoryIds = await repositoryIdsForOwnerName(ownerName, dependencies.store);
for (const repositoryId of repositoryIds) {
const summary = await dependencies.reconcile(repositoryId);
dependencies.write(JSON.stringify(summary));
}
}

async function repositoryIdsForArguments(
argumentsList: readonly string[],
store: ReconcileCliDependencies["store"],
): Promise<string[]> {
function parseArguments(argumentsList: readonly string[]): string | null {
if (argumentsList.length === 0) {
return store.listActiveRepositoryIds();
return null;
}
if (
argumentsList.length !== 2 ||
Expand All @@ -40,7 +39,17 @@ async function repositoryIdsForArguments(
throw new Error("Usage: pnpm reconcile [--repository owner/name]");
}

const repository = await store.findRepositoryByOwnerName(argumentsList[1]!);
return argumentsList[1]!;
}

async function repositoryIdsForOwnerName(
ownerName: string | null,
store: ReconcileCliDependencies["store"],
): Promise<string[]> {
if (ownerName === null) {
return store.listActiveRepositoryIds();
}
const repository = await store.findRepositoryByOwnerName(ownerName);
if (repository === null) {
throw new Error("Registered active repository was not found.");
}
Expand Down
18 changes: 18 additions & 0 deletions scripts/register-path-aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { existsSync } from "node:fs";
import { registerHooks } from "node:module";

const sourceRoot = new URL("../src/", import.meta.url);

registerHooks({
resolve(specifier, context, nextResolve) {
if (specifier.startsWith("@/")) {
for (const suffix of [".ts", ".tsx", "/index.ts"]) {
const candidate = new URL(`${specifier.slice(2)}${suffix}`, sourceRoot);
if (existsSync(candidate)) {
return nextResolve(candidate.href, context);
}
}
}
return nextResolve(specifier, context);
},
});
Loading