Code Monkey home page Code Monkey logo

Comments (7)

napcs avatar napcs commented on September 13, 2024 1

@asifbacchus Thanks for the code. Turns out the fix is easy.

The exclusions needs to be an array. You're taking it in from the args as a string.

Try splitting it on commas like this:

    exclusions: process.env.LR_EXCLUDE.split(","),

That's what the CLI version does anyway. When I applied that change to your code, it worked as expected.

With the exclusions.... no there's not currently a way to replace the default exclusions. It ends up breaking backwards compat if I changed that behavior. If I get enough requests for this I'll add a second command line option, but in the last 10 years it's never come up that people want remove the git/svn exclusions we have by default.

I'm gonna close this as I don't think this is an issue. But I am creating a new issue #157 so nobody else gets tripped up on this.

from node-livereload.

napcs avatar napcs commented on September 13, 2024

@asifbacchus you indicate you're using it by JS now. Please send me the code you're using so I can explore it.

The default exclusions look like this btw:

    const defaultExclusions = [/\.git\//, /\.svn\//, /\.hg\//];

Your regex patterns look like they are doing a .* capture group. I don't think you need that - I think you can just follow the same pattern the defaults use.

If you leave the defaults alone, does the .git folder get ignored for you? If so, check your regex.

from node-livereload.

napcs avatar napcs commented on September 13, 2024

@asifbacchus just a followup. These steps:

    use default exclusions, start server
    in watched directory, mkdir .git
    `echo "this is a test file" >./.git/file
    Livereload sees the change and commences a reload.

do not trigger a livereload event for me on macOS using 0.9.3 from npm. Happy to look at code.

from node-livereload.

asifbacchus avatar asifbacchus commented on September 13, 2024

First test I ran was literally what you suggested. I still get a notification "Reloading..." using the defaults. Super strange. As a side note, is there a way to override those defaults? I see that anything I specify is added -- might be a nice feature to be able to replace instead of append.

Here's the code I'm using:

// load livereload module
const livereload = require('livereload');

// set createServer options
const fs = require('fs');
const options = {
    port: process.env.LR_PORT,
    exts: process.env.LR_EXTS,
    exclusions: process.env.LR_EXCLUDE,
    usePolling: true,
    delay: process.env.LR_DELAY,
};

// set debugging output as per LR_DEBUG
if (process.env.LR_DEBUG === "true") {
    options.debug = true
    console.log("[Debug output ENABLED]");
}

// set HTTPS as per LR_HTTPS
if (process.env.LR_HTTPS === "true") {
    options.https = {
        cert: fs.readFileSync('/certs/fullchain.pem'),
        key: fs.readFileSync('/certs/privkey.pem')
    };
    console.log("[HTTPS mode]");
}
else {
    console.log("[HTTP mode]");
}

// start server
const lrServer = livereload.createServer(options, healthcheck);
lrServer.watch('/watch')

As you can see, I'm reading the exclusions from an environment variable. This is because everything is being run in a docker container and it's easier to specify at run-time this way. However, as I understand it, process.env.VARIABLE simply returns a string with the contents of the environment variable. So, maybe that string needs to be passed in a certain way?

The healthcheck callback is a separate function that I'm using as part of a docker deployment. I didn't include it because I can't see how it would affect this issue, but if you need to see it for whatever reason, let me know.

Thanks for looking into this -- very, very much appreciated.

from node-livereload.

asifbacchus avatar asifbacchus commented on September 13, 2024

Just to follow-up for the benefit of anyone else. Splitting on commas only accomplished half of what was needed. That resulted in an array of string elements which, while properly formatted, just would not work. I had to convert each element to a RegEx object.

// create array of string elements
const extraExclusions = process.env.LR_EXCLUDE.split(",");
// convert each element to a RegExp object
extraExclusions.forEach((exclusion, idx) => {
    extraExclusions[idx] = new RegExp(exclusion);
});

// set createServer options
const options = {
    port: process.env.LR_PORT,
    exts: process.env.LR_EXTS,
    exclusions: extraExclusions,
    usePolling: true,
    delay: process.env.LR_DELAY,
};

The extra advantage of this is the environment variable can be set in a simpler syntax:
LR_EXCLUDE=".somedir/,.swp$,.tmp$"

Hope this helps, thanks for the pointer and getting me set in the right direction, @napcs.

from node-livereload.

napcs avatar napcs commented on September 13, 2024

@asifbacchus Glad you got it! And sorry I wasted some time there - yes they need to be proper regex entries. Also, you can use map() instead of forEach - see lib/command.js in this repo for how I set them in the CLI.

from node-livereload.

asifbacchus avatar asifbacchus commented on September 13, 2024

No worries, thanks for all the help!

from node-livereload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.