From f3f4784ee003973f301b7ac4ab043f424331e754 Mon Sep 17 00:00:00 2001 From: Alex Lohr Date: Wed, 4 Jun 2025 09:02:22 +0200 Subject: [PATCH 1/2] fix: (fs) rm also removes signal --- .changeset/clean-baboons-kneel.md | 5 +++++ packages/filesystem/src/reactive.ts | 4 ++++ packages/filesystem/test/index.test.ts | 25 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changeset/clean-baboons-kneel.md diff --git a/.changeset/clean-baboons-kneel.md b/.changeset/clean-baboons-kneel.md new file mode 100644 index 000000000..7ccf0624c --- /dev/null +++ b/.changeset/clean-baboons-kneel.md @@ -0,0 +1,5 @@ +--- +"@solid-primitives/filesystem": minor +--- + +fix: removing a file deletes its signal correctly diff --git a/packages/filesystem/src/reactive.ts b/packages/filesystem/src/reactive.ts index 83c2c0e9d..66ce16482 100644 --- a/packages/filesystem/src/reactive.ts +++ b/packages/filesystem/src/reactive.ts @@ -112,6 +112,10 @@ export const createSyncFileSystem = ( getTypeMap.delete(item); } }); + if (readFileMap.has(path)) { + readFileMap.get(path)?.[1](undefined); + readFileMap.delete(path); + } readdirMap.get(getParentDir(path))?.[1]( (items = []) => items.filter(item => item === getItemName(path)) as [] | DirEntries, ); diff --git a/packages/filesystem/test/index.test.ts b/packages/filesystem/test/index.test.ts index d2c17f63d..e71d30c12 100644 --- a/packages/filesystem/test/index.test.ts +++ b/packages/filesystem/test/index.test.ts @@ -11,7 +11,7 @@ import { makeTauriFileSystem, rsync, } from "../src/index.js"; -import { createEffect, createRoot } from "solid-js"; +import { catchError, createEffect, createRoot } from "solid-js"; describe("makeNoFileSystem", () => { const fs = makeNoFileSystem(); @@ -51,6 +51,15 @@ describe("makeVirtualFileSystem", () => { }); test("fs.readFile returns file content", () => expect(fs.readFile("src/test.ts")).toBe("// test")); + test("fs.readFile throws on attempting to read a directory as file", () => { + expect(() => fs.readFile("src")).toThrow('"src" is not a file'); + }); + test("fs.readFile throws on attempting to read a non-existent file", () => { + expect(() => fs.readFile("src/nonexistent.ts")).toThrow('"src/nonexistent.ts" is not a file'); + }); + test("fs.readFile throws on attempting to read from a non-existing directory", () => { + expect(() => fs.readFile("nonexistent/test.ts")).toThrow('"nonexistent" is not a directory') + }); test("fs.writeFile creates and overwrites file", () => { expect(fs.readdir("src")).toHaveLength(1); fs.writeFile("src/test2.ts", "// data"); @@ -114,6 +123,20 @@ describe("createFileSystem (sync) calls the underlying fs", () => { }); }); +describe("createFileSystem (sync) relays file system errors", () => { + test("a deleted file stored in a signal throws an error", () => new Promise((done, fail) => { + setTimeout(() => fail(new Error('did not throw')), 100); + const fs = createFileSystem(makeVirtualFileSystem({ 'test.json': '{}' })); + catchError(() => { + createEffect(() => fs.readFile("test.json")); + setTimeout(() => fs.rm("test.json"), 30); + }, (error) => { + expect(error).toEqual(new Error('"test.json" is not a file')); + done(); + }); + })); +}); + describe("createFileSystem (async) calls the underlying fs", () => { const afs = makeNoAsyncFileSystem(); instrumentFs(afs); From 4a275bb5c4f6ae846f4c6b3c155dabbc101cf219 Mon Sep 17 00:00:00 2001 From: Alex Lohr Date: Wed, 4 Jun 2025 14:23:00 +0200 Subject: [PATCH 2/2] patch level update Co-authored-by: Damian Tarnawski --- .changeset/clean-baboons-kneel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/clean-baboons-kneel.md b/.changeset/clean-baboons-kneel.md index 7ccf0624c..dee9daef3 100644 --- a/.changeset/clean-baboons-kneel.md +++ b/.changeset/clean-baboons-kneel.md @@ -1,5 +1,5 @@ --- -"@solid-primitives/filesystem": minor +"@solid-primitives/filesystem": patch --- fix: removing a file deletes its signal correctly