Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions ext/node/polyfills/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
import {
ERR_FS_RMDIR_ENOTDIR,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
uvException,
} from "ext:deno_node/internal/errors.ts";
import { toUnixTimestamp } from "ext:deno_node/internal/fs/utils.mjs";
Expand Down Expand Up @@ -3159,10 +3160,47 @@
persistent?: boolean;
recursive?: boolean;
encoding?: string;
// deno-lint-ignore no-explicit-any
ignore?: string | RegExp | ((path: string) => boolean) | any[];
};

type watchListener = (eventType: string, filename: string) => void;

// Mirrors Node's `validateIgnoreOption` /
// `validateIgnoreOptionElement` in lib/internal/validators.js.
// deno-lint-ignore no-explicit-any
function validateIgnoreOptionElement(value: any, name: string) {
if (typeof value === "string") {
if (value.length === 0) {
throw new ERR_INVALID_ARG_VALUE(
name,
value,
"must be a non-empty string",
);
}
return;
}
if (value instanceof RegExp) return;

Check failure on line 3183 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug linux-x86_64

Don't use the global intrinsic

Check failure on line 3183 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug linux-x86_64

Don't use `instanceof` operator

Check failure on line 3183 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug windows-x86_64

Don't use the global intrinsic

Check failure on line 3183 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug windows-x86_64

Don't use `instanceof` operator
Comment thread
nathanwhitbot marked this conversation as resolved.
Outdated
if (typeof value === "function") return;
throw new ERR_INVALID_ARG_TYPE(
name,
["string", "RegExp", "Function"],
value,
);
}

// deno-lint-ignore no-explicit-any
function validateIgnoreOption(value: any, name: string) {
if (value == null) return;
if (Array.isArray(value)) {

Check failure on line 3195 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug linux-x86_64

Don't use the global intrinsic

Check failure on line 3195 in ext/node/polyfills/fs.ts

View workflow job for this annotation

GitHub Actions / lint debug windows-x86_64

Don't use the global intrinsic
Comment thread
nathanwhitbot marked this conversation as resolved.
Outdated
for (let i = 0; i < value.length; i++) {
validateIgnoreOptionElement(value[i], `${name}[${i}]`);
}
return;
}
validateIgnoreOptionElement(value, name);
}

function watch(
filename: string | URL,
options: watchOptions,
Expand Down Expand Up @@ -3193,6 +3231,8 @@
? optionsOrListener2
: undefined;

validateIgnoreOption(options?.ignore, "options.ignore");

// deno-lint-ignore prefer-primordials
const watchPath = getValidatedPath(filename).toString();

Expand Down
1 change: 1 addition & 0 deletions tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@
"parallel/test-fs-utimes-y2K38.js": {},
"parallel/test-fs-utimes.js": {},
"parallel/test-fs-watch-file-enoent-after-deletion.js": {},
"parallel/test-fs-watch-ignore-invalid.js": {},
"parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js": {},
"parallel/test-fs-watch-recursive-add-folder.js": {},
"parallel/test-fs-watch-recursive-delete.js": {},
Expand Down
Loading