Skip to content
Open
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
3 changes: 1 addition & 2 deletions src/commands/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { config } from "../lib/config";
import { getFileSystemRepo } from "../lib/get-file-system-repo";
import { getQiitaApiInstance } from "../lib/get-qiita-api-instance";
import { getUrlAddress } from "../lib/getUrlAddress";
Expand All @@ -23,6 +22,6 @@ export const preview = async () => {

startLocalChangeWatcher({
server,
watchPath: config.getItemsRootDir(),
watchPath: fileSystemRepo.getRootPath(),
});
};
8 changes: 8 additions & 0 deletions src/lib/file-system-repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,12 @@ updated
});
});
});

describe("getRootPath()", () => {
it("returns the root path", () => {
const dataRootDir = "./tmp";
const instance = new FileSystemRepo({ dataRootDir });
expect(instance.getRootPath()).toBe(`tmp/public`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a hardcoded path separator / can cause this test to fail on different operating systems, such as Windows. It's best practice to use path.join to construct paths for cross-platform compatibility.

You'll need to add import path from 'node:path'; at the top of the file to use this suggestion.

Suggested change
expect(instance.getRootPath()).toBe(`tmp/public`);
expect(instance.getRootPath()).toBe(path.join("tmp", "public"));

});
});
});
2 changes: 1 addition & 1 deletion src/lib/file-system-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class FileSystemRepo {
await fs.mkdir(this.getRemotePath(), { recursive: true });
}

private getRootPath() {
public getRootPath() {
const subdir = "public";
return path.join(this.dataRootDir, subdir);
}
Expand Down
4 changes: 3 additions & 1 deletion src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export function startLocalChangeWatcher({
watchPath: string;
}) {
const wsServer = new WebSocketServer({ server });
const watcher = chokidar.watch(watchPath);
const watcher = chokidar.watch(watchPath, {
ignored: ["**/.remote/**"],
});
watcher.on("change", () => {
wsServer.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
Expand Down
Loading