Skip to content

Commit e4d766a

Browse files
committed
Fixes from feedback
1 parent a5b0dd8 commit e4d766a

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

packages/code-link-cli/src/helpers/watcher.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,35 @@ describe("rename detection", () => {
514514
await fs.rm(tmpDir, { recursive: true, force: true })
515515
})
516516

517+
it("suppresses delete when a buffered new-file add is replaced on the same path", async () => {
518+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "framer-watcher-"))
519+
520+
const events: WatcherEvent[] = []
521+
const watcher: Watcher = initWatcher(tmpDir)
522+
watcher.on("change", event => events.push(event))
523+
const rawWatcher = createdWatchers.at(-1)
524+
if (!rawWatcher) throw new Error("No watcher created")
525+
526+
const filePath = path.join(tmpDir, "Component.tsx")
527+
await fs.writeFile(filePath, "export const Version = 1", "utf-8")
528+
await rawWatcher.__emit("add", filePath)
529+
530+
await fs.writeFile(filePath, "export const Version = 2", "utf-8")
531+
await rawWatcher.__emit("add", filePath)
532+
533+
await fs.unlink(filePath)
534+
await rawWatcher.__emit("unlink", filePath)
535+
536+
expect(events).toHaveLength(0)
537+
538+
await waitForBuffer()
539+
540+
expect(events).toHaveLength(0)
541+
542+
await watcher.close()
543+
await fs.rm(tmpDir, { recursive: true, force: true })
544+
})
545+
517546
it("emits add and delete separately when content differs", async () => {
518547
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "framer-watcher-"))
519548

packages/code-link-cli/src/helpers/watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export function initWatcher(filesDir: string): Watcher {
306306
if (existingPendingAdd) {
307307
clearTimeout(existingPendingAdd.timer)
308308
}
309-
const retainedPreviousContentHash = existingPendingAdd?.previousContentHash ?? previousContentHash
309+
const retainedPreviousContentHash = existingPendingAdd ? existingPendingAdd.previousContentHash : previousContentHash
310310
const timer = setTimeout(() => {
311311
pendingAdds.delete(relativePath)
312312
dispatchEvent({ kind: "add", relativePath, content })

packages/code-link-cli/src/utils/project.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe("toDirectoryName", () => {
1616
it("replaces invalid chars preserving case and spaces", () => {
1717
expect(toDirectoryName("My Project")).toBe("My Project")
1818
expect(toDirectoryName("Hello World!")).toBe("Hello World")
19+
expect(toDirectoryName("My-Project 2026!")).toBe("My-Project 2026")
1920
})
2021

2122
it("removes boundary hyphens revealed by trimming", () => {

packages/code-link-cli/src/utils/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function toPackageName(name: string): string {
2020

2121
export function toDirectoryName(name: string): string {
2222
return name
23-
.replace(/[^a-zA-Z0-9- ]/g, "-")
23+
.replace(/[^a-zA-Z0-9 -]/g, "-")
2424
.trim()
2525
.replace(/^-+|-+$/g, "")
2626
.replace(/-+/g, "-")

0 commit comments

Comments
 (0)