question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watching subdirectories unavailable on Linux

See original GitHub issue

Hey @rsms I wasn’t immediately sure if this was something on estrella’s end or a limitation of esbuild, so excuse my assumptions if they’re off!

When I have an entry point file which is importing a module from a sub-directory, estrella only seems to execute a rebuild when something changes in the entry-point file. However if I move my files from the sub-directory to the same directory as the entry-point file, things will rebuild when any file is changed.

I guess my expectation would be to have files, which are referenced by the entry-point file but are not in the base-level directory, trigger a rebuild when they change.

An example set up running on Node 12.16.3.

./src/index.js

import MyModule from "./modules/my-module";

(function () {
  
   MyModule.foo();
   // returns string bar

})();

./src/modules/my-module.js

const MyModule = (function () {

   return {
       foo: function () {
           return "bar";
       }
   };

})();

export default MyModule;

./build.js

#!/usr/bin/env node

const path = require("path");
const { build, cliopts } = require("estrella");
const { createServer } = require("serve-http");

const options = {
  entry: "./src/index.js",
  outfile: "./public/bundle.js",
  bundle: true,
  minify: true
};

build(options);

cliopts.watch && createServer({
  port: 3000,
  pubdir: path.join(__dirname, "./public"),
});

Thus far whenever I change anything within my-module.js a rebuild won’t trigger. Only when the change is within index.js.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jonathontooncommented, May 26, 2020

Thanks @rsms will try it out and report back if I find any quirks.

Alternatively I also hacked something together using node-watch which has a significantly smaller footprint than chokidar (less battle tested though). I don’t get the warm and fuzzy feeling of seeing estrella’s nice console logs but it solves the problem on Linux for the short term. 😄

#!/usr/bin/env node

(function () {

  const watch = require("node-watch");
  const path = require("path");

  const { build } = require("esbuild");
  const { createServer } = require("serve-http");

  const buildOptions = {
    entryPoints: ["./src/index.js"],
    outfile: "./public/bundle.min.js",
    bundle: true,
    minify: true,
    target: "es2015"
  };

  if (process.env.NODE_ENV === "production") {
    build(buildOptions);
  } else {
    watch("./src", { recursive: true }, function () {
      build(buildOptions);
    });

    createServer({
      port: 3000,
      pubdir: path.join(__dirname, "./public"),
    });
  }

})();
1reaction
rsmscommented, May 26, 2020

I actually have a dedicated Ubuntu MacBook in my office :–)

Unfortunately this is a limitation with NodeJS’s fs.watch function. The documentation mentions “The recursive option is only supported on macOS and Windows.”

I’ll rename this issue to be about improving deep-directory watch support. There are a lot of 3rd party libraries implementing this in JS but they are all rather heavy and I’m trying to keep estrella small.

In the meantime, what you can do is some hack like this:

#!/usr/bin/env node
const { build, scandir, watchdir } = require("estrella")
const fs = require("fs")
build({
  entry: "src/main.ts",
  outfile: "out/foo.js",
})
const srcSubdirs = [ "src/meow", "src/woff" ] // fs.readdir to automate
cliopts.watch && watchdir(srcSubdirs, /\..*$/i,() => {
  fs.writeFileSync("src/dummy.js", "")  // this would trigger a rebuild
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Enable Viewing Subdirectories in Apache2 Under ...
Under Ubuntu 14.04 I could see the subdirectories under " /var/www ". ... How can subdirectory viewing (access) be enabled for " var/www...
Read more >
watch a subdirectory with incron - Stack Overflow
It's ok when I add a file in /home/pat0/downloads but, if I create a subdirectory and I add in a file no thing...
Read more >
cat files in current folder and all subfolders [duplicate]
I want to cat a file in current folder and all files in all subfolders (and subsubfolders). Here is my directory structure $...
Read more >
4 Invoking fswatch
Request the monitor to watch directories only during a recursive scan. This feature helps reducing the number of open file descriptors if a...
Read more >
Display each sub-directory size in a list format using one line ...
du -h gives it, but it displays all of the sub-folders which is not what I want. just the current directories folders. linux...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found