mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: rename
watch event missing (#24893)
This PR ensures that we forward a `rename` event in our file watcher. The rust lib we use combines that with the `modify` event. This fixes a compatibility issue with Node too, which sends the `rename` event as well. Fixes https://github.com/denoland/deno/issues/24880
This commit is contained in:
parent
59c9bd0800
commit
9d6da1036d
4 changed files with 38 additions and 2 deletions
9
cli/tsc/dts/lib.deno.ns.d.ts
vendored
9
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -4149,7 +4149,14 @@ declare namespace Deno {
|
||||||
* @category File System */
|
* @category File System */
|
||||||
export interface FsEvent {
|
export interface FsEvent {
|
||||||
/** The kind/type of the file system event. */
|
/** The kind/type of the file system event. */
|
||||||
kind: "any" | "access" | "create" | "modify" | "remove" | "other";
|
kind:
|
||||||
|
| "any"
|
||||||
|
| "access"
|
||||||
|
| "create"
|
||||||
|
| "modify"
|
||||||
|
| "rename"
|
||||||
|
| "remove"
|
||||||
|
| "other";
|
||||||
/** An array of paths that are associated with the file system event. */
|
/** An array of paths that are associated with the file system event. */
|
||||||
paths: string[];
|
paths: string[];
|
||||||
/** Any additional flags associated with the event. */
|
/** Any additional flags associated with the event. */
|
||||||
|
|
|
@ -368,6 +368,8 @@ function convertDenoFsEventToNodeFsEvent(
|
||||||
): NodeFsEventType {
|
): NodeFsEventType {
|
||||||
if (kind === "create" || kind === "remove") {
|
if (kind === "create" || kind === "remove") {
|
||||||
return "rename";
|
return "rename";
|
||||||
|
} else if (kind === "rename") {
|
||||||
|
return "rename";
|
||||||
} else {
|
} else {
|
||||||
return "change";
|
return "change";
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ use deno_core::op2;
|
||||||
|
|
||||||
use deno_permissions::PermissionsContainer;
|
use deno_permissions::PermissionsContainer;
|
||||||
use notify::event::Event as NotifyEvent;
|
use notify::event::Event as NotifyEvent;
|
||||||
|
use notify::event::ModifyKind;
|
||||||
use notify::Error as NotifyError;
|
use notify::Error as NotifyError;
|
||||||
use notify::EventKind;
|
use notify::EventKind;
|
||||||
use notify::RecommendedWatcher;
|
use notify::RecommendedWatcher;
|
||||||
|
@ -71,7 +72,13 @@ impl From<NotifyEvent> for FsEvent {
|
||||||
EventKind::Any => "any",
|
EventKind::Any => "any",
|
||||||
EventKind::Access(_) => "access",
|
EventKind::Access(_) => "access",
|
||||||
EventKind::Create(_) => "create",
|
EventKind::Create(_) => "create",
|
||||||
EventKind::Modify(_) => "modify",
|
EventKind::Modify(modify_kind) => match modify_kind {
|
||||||
|
ModifyKind::Name(_) => "rename",
|
||||||
|
ModifyKind::Any
|
||||||
|
| ModifyKind::Data(_)
|
||||||
|
| ModifyKind::Metadata(_)
|
||||||
|
| ModifyKind::Other => "modify",
|
||||||
|
},
|
||||||
EventKind::Remove(_) => "remove",
|
EventKind::Remove(_) => "remove",
|
||||||
EventKind::Other => "other",
|
EventKind::Other => "other",
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,6 +70,26 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
{ permissions: { read: true, write: true } },
|
||||||
|
async function watchFsRename() {
|
||||||
|
const testDir = await makeTempDir();
|
||||||
|
const watcher = Deno.watchFs(testDir);
|
||||||
|
async function waitForRename() {
|
||||||
|
for await (const event of watcher) {
|
||||||
|
if (event.kind === "rename") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const eventPromise = waitForRename();
|
||||||
|
const file = testDir + "/file.txt";
|
||||||
|
await Deno.writeTextFile(file, "hello");
|
||||||
|
await Deno.rename(file, testDir + "/file2.txt");
|
||||||
|
await eventPromise;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// TODO(kt3k): This test is for the backward compatibility of `.return` method.
|
// TODO(kt3k): This test is for the backward compatibility of `.return` method.
|
||||||
// This should be removed at 2.0
|
// This should be removed at 2.0
|
||||||
Deno.test(
|
Deno.test(
|
||||||
|
|
Loading…
Reference in a new issue