Repository navigation
fix: edge case handling for update, add, and compose #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| import { findPack } from "../registry.js"; | ||
| import { parseSource, fetchFile } from "../github.js"; | ||
| import { writeInstructions, defaultTarget } from "../writer.js"; | ||
| import { addEntry } from "../lockfile.js"; | ||
| import { readLockfile, addEntry } from "../lockfile.js"; | ||
|
|
||
| export async function add(nameOrSource: string): Promise<void> { | ||
| const name = nameOrSource.startsWith("github:") | ||
| ? nameOrSource.split("/").pop()!.replace(/\.md$/, "").replace(/^github:/, "") | ||
| : nameOrSource; | ||
|
|
||
| const existing = readLockfile().packs[name]; | ||
| if (existing) { | ||
| console.log(`"${name}" is already installed at ${existing.target}. Run: instruct-sync update`); | ||
| return; | ||
| } | ||
|
Comment on lines
+7
to
+15
|
||
|
|
||
| let source: string; | ||
|
|
||
| if (nameOrSource.startsWith("github:")) { | ||
|
|
@@ -17,7 +27,6 @@ export async function add(nameOrSource: string): Promise<void> { | |
| console.log(`Fetching ${source}...`); | ||
| const file = await fetchFile(parsed); | ||
|
|
||
| const name = nameOrSource.startsWith("github:") ? parsed.path.split("/").pop()!.replace(/\.md$/, "") : nameOrSource; | ||
| const target = defaultTarget(name); | ||
|
|
||
| writeInstructions(file.content, target); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,21 @@ export function compose(): void { | |
| return; | ||
| } | ||
| const sections: string[] = [HEADER]; | ||
| let composed = 0; | ||
| for (const [name, entry] of entries) { | ||
| const absPath = resolve(process.cwd(), entry.target); | ||
| if (!existsSync(absPath)) { | ||
| console.warn(` ⚠ skipping "${name}" — file not found at ${entry.target}`); | ||
| console.warn(` ⚠ skipping "${name}" — file not found at ${entry.target}. Run: instruct-sync update`); | ||
| continue; | ||
| } | ||
| const content = readFileSync(absPath, "utf8").trim(); | ||
| sections.push(`## ${name}\n\n${content}\n`); | ||
| composed++; | ||
| } | ||
| writeInstructions(sections.join("\n"), OUTPUT); | ||
| console.log(`✓ Composed ${entries.length} pack(s) → ${OUTPUT}`); | ||
| if (composed < entries.length) { | ||
| console.log(`✓ Composed ${composed} of ${entries.length} pack(s) → ${OUTPUT} (${entries.length - composed} skipped — run: instruct-sync update)`); | ||
| } else { | ||
| console.log(`✓ Composed ${composed} pack(s) → ${OUTPUT}`); | ||
| } | ||
|
Comment on lines
+29
to
+33
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||||||
| import { mkdtempSync, mkdirSync, writeFileSync, existsSync } from "node:fs"; | ||||||
|
||||||
| import { mkdtempSync, mkdirSync, writeFileSync, existsSync } from "node:fs"; | |
| import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README claims
npm install -g instruct-syncwithout@latest“will keep the cached version”, but earlier in the README the same command is presented as the normal install method.npm install -g <pkg>already installs the latest dist-tag by default; consider removing or rewording this to avoid giving incorrect upgrade guidance.