Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-livereload-plugin

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-livereload-plugin - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

61

index.js
/* jshint node:true */
const crypto = require('crypto');
var lr = require('tiny-lr');
var portfinder = require('portfinder');
var servers = {};

@@ -7,5 +9,8 @@

this.options = options || {};
this.port = this.options.port || 35729;
this.defaultPort = 35729;
this.port = typeof this.options.port === 'number' ? this.options.port : this.defaultPort;
this.ignore = this.options.ignore || null;
this.quiet = this.options.quiet || false;
// Random alphanumeric string appended to id to allow multiple instances of live reload
this.instanceId = crypto.randomBytes(8).toString('hex');

@@ -32,23 +37,41 @@ // add delay, but remove it from options, so it doesn't get passed to tinylr

LiveReloadPlugin.prototype.start = function start(watching, cb) {
var port = this.port;
var quiet = this.quiet;
if (servers[port]) {
this.server = servers[port];
if (servers[this.port]) {
this.server = servers[this.port];
cb();
}
else {
this.server = servers[port] = lr(this.options);
this.server.errorListener = function serverError(err) {
console.error('Live Reload disabled: ' + err.message);
if (err.code !== 'EADDRINUSE') {
console.error(err.stack);
}
cb();
};
this.server.listen(this.port, function serverStarted(err) {
if (!err && !quiet) {
console.log('Live Reload listening on port ' + port + '\n');
}
cb();
});
const listen = function() {
this.server = servers[this.port] = lr(this.options);
this.server.errorListener = function serverError(err) {
console.error('Live Reload disabled: ' + err.message);
if (err.code !== 'EADDRINUSE') {
console.error(err.stack);
}
cb();
};
this.server.listen(this.port, function serverStarted(err) {
if (!err && !quiet) {
console.log('Live Reload listening on port ' + this.port + '\n');
}
cb();
}.bind(this));
}.bind(this);
if(this.port === 0) {
portfinder.basePort = this.defaultPort;
portfinder.getPort(function portSearchDone(err, port) {
if (err) {
throw err;
}
this.port = port;
listen()
}.bind(this));
} else {
listen();
}
}

@@ -84,3 +107,3 @@ };

' if (typeof window === "undefined") { return };',
' var id = "webpack-livereload-plugin-script";',
' var id = "webpack-livereload-plugin-script-' + this.instanceId + '";',
' if (document.getElementById(id)) { return; }',

@@ -87,0 +110,0 @@ ' var el = document.createElement("script");',

{
"name": "webpack-livereload-plugin",
"version": "2.1.1",
"version": "2.2.0",
"description": "Livereload for webpack",

@@ -25,7 +25,8 @@ "main": "index.js",

"faucet": "0.0.1",
"tape": "^4.4.0"
"tape": "^4.9.1"
},
"dependencies": {
"portfinder": "^1.0.17",
"tiny-lr": "^1.1.1"
}
}

@@ -43,3 +43,3 @@ # webpack-livereload-plugin

- `protocol` - (Default: protocol of the page, either `http` or `https`) Protocol for livereload `<script>` src attribute value
- `port` - (Default: 35729) The desired port for the livereload server
- `port` - (Default: 35729) The desired port for the livereload server. If you define port 0, an available port will be searched for, starting from 35729.
- `hostname` - (Default: hostname of the page, like `localhost` or `10.0.2.2`) The desired hostname for the appended

@@ -46,0 +46,0 @@ `<script>` (if present) to point to

@@ -31,2 +31,33 @@ var test = require('tape');

test('finds available ports', function(t) {
var plugin1 = new LiveReloadPlugin({port: 0});
var plugin2 = new LiveReloadPlugin({port: 0});
var count = 0;
var tryEnd = function() {
count++;
if(count === 2) {
t.notEqual(plugin1.port, plugin2.port);
t.end();
}
}
var startPlugin = function(p) {
p.start(null, function() {
t.notLooseEqual(p.server, null);
t.ok(p.server !== undefined)
t.ok(p.isRunning);
p.server.on('close', function() {
tryEnd();
});
setTimeout(function() {
p.server.close();
});
});
}
startPlugin(plugin1);
startPlugin(plugin2);
});
test('notifies when done', function(t) {

@@ -101,1 +132,14 @@ var plugin = new LiveReloadPlugin();

});
test('every instance has random id', function(t) {
var plugin = new LiveReloadPlugin();
var plugin2 = new LiveReloadPlugin();
t.notEqual(plugin.instanceId, plugin2.instanceId);
t.end();
});
test('autoloadJs contains instanceId', function(t) {
var plugin = new LiveReloadPlugin();
t.assert(plugin.autoloadJs().match(plugin.instanceId));
t.end();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc