Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fs.watch #832

Closed
robogeek opened this issue Jul 22, 2022 · 4 comments
Closed

Implement fs.watch #832

robogeek opened this issue Jul 22, 2022 · 4 comments
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs

Comments

@robogeek
Copy link

Version

Canary 0.1.5

Platform

Linux davidpc 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

Earlier I reported that running Chokidar throws lots of errors about stats.isSymbolicLink not existing. That is fixed as of the Canary build of 0.1.5, thank you.

With 0.1.5 there is still an error in Chokidar - fs.watch does not exist, and if you Import the fs module it is indeed undefined.

The following code was written primarily to be a performance test, but it will demonstrate the error.

import { inspect } from 'util';
import { default as chokidar } from 'chokidar';

const dirs = [
// Put a list of directory names here
];

let watcher;

const start = new Date();
let count = 0;

try {
    await new Promise((resolve, reject) => {
        try {
            watcher = chokidar.watch(
                typeof process.argv[2] !== 'undefined'
                ? process.argv[2]
                : dirs
            );
            watcher
            .on('error', async (error) => {
                console.error(error);
                reject(error);
            })
            .on('add', (fpath, stats) => {
                // console.log(`add ${fpath} ${inspect(stats)}`);
                count++;
            })
            .on('change', (fpath, stats) => {
                // console.log(`change ${fpath} ${inspect(stats)}`);
            })
           .on('ready', async () => {
                // console.log(`ready`);
                await close();

                const finish = new Date();

                console.log(`time ${(finish - start) / 1000} seconds - ${count} files`);

                resolve();
            });
        } catch (err) { reject(err); }
    });

} catch (errr) { console.error(errr); }

async function close() {
    await watcher.close();
    watcher = undefined;
}

Another piece of source is this:

import * as fs from 'fs';

console.log(fs.watch);

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior?

With choke.mjs the output for Node is:

$ node choke.mjs
time 1.45 seconds - 6426 files

And for fsw.mjs it is:

$ node fsw.mjs 
[Function: watch]

What do you see instead?

These are run using the Canary build of 0.1.5

$ ~/Projects/bun/bun-linux-x64/bun fsw.mjs 
undefined

And for choke.mjs there is one instance of this error for each file:

115 |       );
116 |     }
117 |   };
118 |   try {
119 | // console.log(fs.watch);
120 |     return fs.watch(path, options, handleEvent);
               ^
TypeError: fs.watch is not a function. (In 'fs.watch(path, options, handleEvent)', 'fs.watch' is undefined)
      at createFsWatchInstance (/home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/lib/nodefs-handler.js:120:11)
      at /home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/lib/nodefs-handler.js:167:14
      at _watchWithNodeFs (/home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/lib/nodefs-handler.js:332:13)
      at _handleFile (/home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/lib/nodefs-handler.js:396:17)
      at /home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/lib/nodefs-handler.js:638:15

Additional information

No response

@robogeek robogeek added bug Something isn't working needs repro Needs an example to reproduce labels Jul 22, 2022
@Jarred-Sumner
Copy link
Collaborator

fs.watch isn't implemented yet

@xhyrom xhyrom added node.js Compatibility with Node.js APIs polyfill and removed needs repro Needs an example to reproduce labels Jul 29, 2022
@xhyrom xhyrom changed the title Chokidar fails with fs.watch undefined Chokidar fails with fs.watch (Implement it) Aug 4, 2022
@Electroid Electroid changed the title Chokidar fails with fs.watch (Implement it) Implement fs.watch Nov 3, 2022
@Electroid Electroid added enhancement New feature or request and removed bug Something isn't working polyfill labels Nov 3, 2022
@WebReflection
Copy link
Contributor

WebReflection commented Feb 23, 2023

I know watch is problematic even in Node as there are no guarantees it works reliably cross platform but when it comes to Bun core features, being unable to watch a sqlite-wal or any generic database file is kinda a blocker for any logic reacting around changes on it.

This is also a blocker for anyone liking to indirectly communicate back-forward with Python libraries for IoT purpose on Bun capable targets and if this is of any any help, filebus based on inotifywait-spawn provides all primitives to have watch reliable wherever inotify-tools can run.

P.S. inotify-tools are available in both all Linux and Macs via home brew

@e3dio
Copy link
Contributor

e3dio commented May 23, 2023

when it comes to Bun core features, being unable to watch a file is kinda a blocker

Yes important feature needs to be a priority. If not node:fs.watch, at least do Bun.watch()

@paperdave paperdave mentioned this issue Jun 6, 2023
@Electroid
Copy link
Contributor

Electroid commented Jun 26, 2023

Implemented in #3249 (will be available in release 0.6.10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

6 participants