Skip to content

Commit c41117e

Browse files
committed
Fix preview watch target file path
Resolve "EMFILE: too many open files" error caused by watching unnecessary files. - Change preview command to use fileSystemRepo.getRootPath() instead of config.getItemsRootDir() - Make getRootPath() public in FileSystemRepo for external access(Please visit if this is the right approach) - Add chokidar ignore pattern to exclude .remote directory from file watching
1 parent b74c2a3 commit c41117e

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/commands/preview.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config } from "../lib/config";
21
import { getFileSystemRepo } from "../lib/get-file-system-repo";
32
import { getQiitaApiInstance } from "../lib/get-qiita-api-instance";
43
import { getUrlAddress } from "../lib/getUrlAddress";
@@ -23,6 +22,6 @@ export const preview = async () => {
2322

2423
startLocalChangeWatcher({
2524
server,
26-
watchPath: config.getItemsRootDir(),
25+
watchPath: fileSystemRepo.getRootPath(),
2726
});
2827
};

src/lib/file-system-repo.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,12 @@ updated
401401
});
402402
});
403403
});
404+
405+
describe("getRootPath()", () => {
406+
it("returns the root path", () => {
407+
const dataRootDir = "./tmp";
408+
const instance = new FileSystemRepo({ dataRootDir });
409+
expect(instance.getRootPath()).toBe(`tmp/public`);
410+
});
411+
});
404412
});

src/lib/file-system-repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class FileSystemRepo {
187187
await fs.mkdir(this.getRemotePath(), { recursive: true });
188188
}
189189

190-
private getRootPath() {
190+
public getRootPath() {
191191
const subdir = "public";
192192
return path.join(this.dataRootDir, subdir);
193193
}

src/server/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export function startLocalChangeWatcher({
6565
watchPath: string;
6666
}) {
6767
const wsServer = new WebSocketServer({ server });
68-
const watcher = chokidar.watch(watchPath);
68+
const watcher = chokidar.watch(watchPath, {
69+
ignored: ["**/.remote/**"],
70+
});
6971
watcher.on("change", () => {
7072
wsServer.clients.forEach((client) => {
7173
if (client.readyState === WebSocket.OPEN) {

0 commit comments

Comments
 (0)