mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
BREAKING CHANGE: rename Deno.fsEvents() to Deno.watchFs() (#4886)
This commit is contained in:
parent
6a37e4426e
commit
824329f0da
5 changed files with 18 additions and 20 deletions
|
@ -38,7 +38,7 @@ export {
|
||||||
OpenMode,
|
OpenMode,
|
||||||
} from "./files.ts";
|
} from "./files.ts";
|
||||||
export { read, readSync, write, writeSync } from "./ops/io.ts";
|
export { read, readSync, write, writeSync } from "./ops/io.ts";
|
||||||
export { FsEvent, fsEvents } from "./ops/fs_events.ts";
|
export { FsEvent, watchFs } from "./ops/fs_events.ts";
|
||||||
export {
|
export {
|
||||||
EOF,
|
EOF,
|
||||||
copy,
|
copy,
|
||||||
|
|
14
cli/js/lib.deno.ns.d.ts
vendored
14
cli/js/lib.deno.ns.d.ts
vendored
|
@ -2169,15 +2169,12 @@ declare namespace Deno {
|
||||||
*/
|
*/
|
||||||
export function resources(): ResourceMap;
|
export function resources(): ResourceMap;
|
||||||
|
|
||||||
/** **UNSTABLE**: new API. Needs docs. */
|
|
||||||
export interface FsEvent {
|
export interface FsEvent {
|
||||||
kind: "any" | "access" | "create" | "modify" | "remove";
|
kind: "any" | "access" | "create" | "modify" | "remove";
|
||||||
paths: string[];
|
paths: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** **UNSTABLE**: new API, yet to be vetted.
|
/** Watch for file system events against one or more `paths`, which can be files
|
||||||
*
|
|
||||||
* Watch for file system events against one or more `paths`, which can be files
|
|
||||||
* or directories. These paths must exist already. One user action (e.g.
|
* or directories. These paths must exist already. One user action (e.g.
|
||||||
* `touch test.file`) can generate multiple file system events. Likewise,
|
* `touch test.file`) can generate multiple file system events. Likewise,
|
||||||
* one user action can result in multiple file paths in one event (e.g. `mv
|
* one user action can result in multiple file paths in one event (e.g. `mv
|
||||||
|
@ -2185,14 +2182,15 @@ declare namespace Deno {
|
||||||
* for directories, will watch the specified directory and all sub directories.
|
* for directories, will watch the specified directory and all sub directories.
|
||||||
* Note that the exact ordering of the events can vary between operating systems.
|
* Note that the exact ordering of the events can vary between operating systems.
|
||||||
*
|
*
|
||||||
* const iter = Deno.fsEvents("/");
|
* const watcher = Deno.watchFs("/");
|
||||||
* for await (const event of iter) {
|
* for await (const event of watcher) {
|
||||||
* console.log(">>>> event", event); // e.g. { kind: "create", paths: [ "/foo.txt" ] }
|
* console.log(">>>> event", event);
|
||||||
|
* // { kind: "create", paths: [ "/foo.txt" ] }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission.
|
* Requires `allow-read` permission.
|
||||||
*/
|
*/
|
||||||
export function fsEvents(
|
export function watchFs(
|
||||||
paths: string | string[],
|
paths: string | string[],
|
||||||
options?: { recursive: boolean }
|
options?: { recursive: boolean }
|
||||||
): AsyncIterableIterator<FsEvent>;
|
): AsyncIterableIterator<FsEvent>;
|
||||||
|
|
|
@ -7,7 +7,7 @@ export interface FsEvent {
|
||||||
paths: string[];
|
paths: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class FsEvents implements AsyncIterableIterator<FsEvent> {
|
class FsWatcher implements AsyncIterableIterator<FsEvent> {
|
||||||
readonly rid: number;
|
readonly rid: number;
|
||||||
|
|
||||||
constructor(paths: string[], options: { recursive: boolean }) {
|
constructor(paths: string[], options: { recursive: boolean }) {
|
||||||
|
@ -31,9 +31,9 @@ class FsEvents implements AsyncIterableIterator<FsEvent> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fsEvents(
|
export function watchFs(
|
||||||
paths: string | string[],
|
paths: string | string[],
|
||||||
options = { recursive: true }
|
options = { recursive: true }
|
||||||
): AsyncIterableIterator<FsEvent> {
|
): AsyncIterableIterator<FsEvent> {
|
||||||
return new FsEvents(Array.isArray(paths) ? paths : [paths], options);
|
return new FsWatcher(Array.isArray(paths) ? paths : [paths], options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { unitTest, assert } from "./test_util.ts";
|
||||||
|
|
||||||
// TODO(ry) Add more tests to specify format.
|
// TODO(ry) Add more tests to specify format.
|
||||||
|
|
||||||
unitTest({ perms: { read: false } }, function fsEventsPermissions() {
|
unitTest({ perms: { read: false } }, function watchFsPermissions() {
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
Deno.fsEvents(".");
|
Deno.watchFs(".");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(err instanceof Deno.errors.PermissionDenied);
|
assert(err instanceof Deno.errors.PermissionDenied);
|
||||||
thrown = true;
|
thrown = true;
|
||||||
|
@ -14,10 +14,10 @@ unitTest({ perms: { read: false } }, function fsEventsPermissions() {
|
||||||
assert(thrown);
|
assert(thrown);
|
||||||
});
|
});
|
||||||
|
|
||||||
unitTest({ perms: { read: true } }, function fsEventsInvalidPath() {
|
unitTest({ perms: { read: true } }, function watchFsInvalidPath() {
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
Deno.fsEvents("non-existant.file");
|
Deno.watchFs("non-existant.file");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (Deno.build.os === "win") {
|
if (Deno.build.os === "win") {
|
||||||
|
@ -47,9 +47,9 @@ async function getTwoEvents(
|
||||||
|
|
||||||
unitTest(
|
unitTest(
|
||||||
{ perms: { read: true, write: true } },
|
{ perms: { read: true, write: true } },
|
||||||
async function fsEventsBasic(): Promise<void> {
|
async function watchFsBasic(): Promise<void> {
|
||||||
const testDir = await Deno.makeTempDir();
|
const testDir = await Deno.makeTempDir();
|
||||||
const iter = Deno.fsEvents(testDir);
|
const iter = Deno.watchFs(testDir);
|
||||||
|
|
||||||
// Asynchornously capture two fs events.
|
// Asynchornously capture two fs events.
|
||||||
const eventsPromise = getTwoEvents(iter);
|
const eventsPromise = getTwoEvents(iter);
|
||||||
|
|
|
@ -470,8 +470,8 @@ The above for-await loop exits after 5 seconds when sig.dispose() is called.
|
||||||
To poll for file system events:
|
To poll for file system events:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const iter = Deno.fsEvents("/");
|
const watcher = Deno.watchFs("/");
|
||||||
for await (const event of iter) {
|
for await (const event of watcher) {
|
||||||
console.log(">>>> event", event);
|
console.log(">>>> event", event);
|
||||||
// { kind: "create", paths: [ "/foo.txt" ] }
|
// { kind: "create", paths: [ "/foo.txt" ] }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue