Socket
Socket
Sign inDemoInstall

browser-sync

Package Overview
Dependencies
Maintainers
1
Versions
300
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-sync - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

examples/plugin.logger.js

17

example.js

@@ -7,18 +7,9 @@ var browserSync = require("./lib/index");

server: {
baseDir: "test/fixtures"
},
open: false
baseDir: "test/fixtures",
directory: true
}
};
//browserSync.use("client:script", function () {
// var file = require("fs").readFileSync("./browser-sync-client.js");
// return function (req, res) {
// res.setHeader("Content-Type", "text/javascript");
// res.end(file);
// };
//});
browserSync.init(files, options, function (err, bs) {
return true;
});
});

@@ -18,7 +18,7 @@ "use strict";

var defaultPlugins = {
"plugin:client:script": bsClient.middleware(),
"plugin:file:watcher": fileWatcher.plugin(),
"plugin:socket": socket.plugin(),
"plugin:logger": logger.plugin(),
"plugin:controlpanel": bsControlPanel.plugin()
"plugin:client:script": bsClient.middleware,
"plugin:file:watcher": fileWatcher.plugin,
"plugin:socket": socket.plugin,
"plugin:logger": logger.plugin,
"plugin:controlpanel": bsControlPanel.plugin
};

@@ -70,3 +70,3 @@

if (typeof this.plugins[name] === "undefined") {
this.plugins[name] = defaultPlugins[name];
this.plugins[name] = defaultPlugins[name]();
}

@@ -190,3 +190,3 @@ }, this);

/**
* Launch the server for serving the client JS plus static files
* Launch the server or proxy
* @param {String} host

@@ -193,0 +193,0 @@ * @param {Object} ports

@@ -10,4 +10,3 @@ "use strict";

var allowedOptions = ["host", "server", "proxy"];
module.exports.allowedOptions = allowedOptions;
module.exports.allowedOptions = ["host", "server", "proxy"];

@@ -40,3 +39,3 @@ /**

if (args[key] && typeof obj[key] !== "undefined") {
obj[key] = cliOptions[methodName(key)](obj[key], args[key]);
obj[key] = cliOptions[methodName(key)](obj[key], args[key], args);
}

@@ -80,5 +79,5 @@ return obj;

options = _.merge(defaultConfig, userConfig);
options = mergeOptions(defaultConfig, options, allowedOptions);
options = mergeOptions(defaultConfig, options, exports.allowedOptions);
} else {
options = mergeOptions(defaultConfig, args, allowedOptions);
options = mergeOptions(defaultConfig, args, exports.allowedOptions);
options.files = cliOptions._mergeFilesOption(args.files, options.exclude);

@@ -105,2 +104,3 @@ }

.option("--server", "Run a Local server (uses your cwd as the web root)")
.option("--directory", "Show a directory listing for the server")
.option("--proxy", "Proxy an existing server")

@@ -107,0 +107,0 @@ .option("--config", "Specify a path to a bs-config.js file")

@@ -14,3 +14,3 @@ "use strict";

*/
_mergeServerOption: function (defaultValue, arg, argv) {
_mergeServerOption: function (defaultValue, arg, args) {

@@ -30,4 +30,9 @@ // Return if object or array given

if (argv && argv.index) {
obj.index = argv.index;
if (args) {
if (args.index) {
obj.index = args.index;
}
if (args.directory) {
obj.directory = true;
}
}

@@ -38,4 +43,5 @@

/**
* @param {Object} defaultValue
* @param {String} arg
* @param defaultValue
* @param arg
* @returns {*}
* @private

@@ -49,2 +55,4 @@ */

var segs;
var startPath = false;
var returnObj;

@@ -69,6 +77,8 @@ if (typeof arg !== "string") {

if (~host.indexOf("/")) {
host = /^(.+?)\//.exec(host)[1];
segs = host.split("/");
host = segs.shift();
startPath = segs.join("/");
}
return {
returnObj = {
protocol: protocol,

@@ -78,2 +88,8 @@ host: host,

};
if (startPath) {
returnObj.startPath = startPath;
}
return returnObj;
},

@@ -83,3 +99,2 @@ /**

* @param {String} arg
* @param {Object} [argv] - process.argv
* @returns {String}

@@ -86,0 +101,0 @@ * @private

"use strict";
var fs = require("fs");
var fs = require("fs");
var Gaze = require("gaze").Gaze;
module.exports = {
/**
* Handle changed files
* @param {Object} options
* @param {EventEmitter} emitter
* @returns {Function}
*/
getChangeCallback: function (options, emitter) {
/**
* Plugin interface
* @returns {*|function(this:exports)}
*/
module.exports.plugin = function () {
return function (files, options, emitter) {
exports.init(files, options, emitter);
};
};
return function (filepath) {
/**
* @param {Array} files
* @param {Object} options
* @param {EventEmitter} emitter
*/
module.exports.init = function (files, options, emitter) {
var chunks = [];
if (!files.length) {
return;
}
fs.createReadStream(filepath)
.on("data", push)
.on("end", end);
var watchCallback = exports.getWatchCallback(emitter);
var changeCallback = exports.getChangeCallback(options, emitter);
function push(chunk) {
chunks.push(chunk);
}
var watcher = exports.getWatcher(files);
function end() {
if (chunks.join("").length > 0) {
setTimeout(function () {
emitter.emit("file:changed", {path: filepath});
}, options.reloadDelay || 0);
}
}
};
},
/**
* Function to be called when watching begins
* @param {EventEmitter} emitter
* @returns {Function}
*/
getWatchCallback: function (emitter) {
return function (watcher) {
emitter.emit("file:watching", { watcher: watcher});
};
},
/**
* Get an instance of Gaze
* @param {Array} files
* @returns {Gaze}
*/
getWatcher: function (files) {
return new Gaze(files);
},
/**
* @param {Array} files
* @param {Object} options
* @param {EventEmitter} emitter
*/
init: function (files, options, emitter) {
watcher.on("ready", watchCallback);
watcher.on("changed", changeCallback);
};
if (!files.length) {
return;
}
/**
* Function to be called when watching begins
* @param {EventEmitter} emitter
* @returns {Function}
*/
module.exports.getWatchCallback = function (emitter) {
return function (watcher) {
emitter.emit("file:watching", { watcher: watcher});
};
};
/**
* Get an instance of Gaze
* @param {Array} files
* @returns {Gaze}
*/
module.exports.getWatcher = function (files) {
return new Gaze(files);
};
var watchCallback = this.getWatchCallback(emitter);
var changeCallback = this.getChangeCallback(options, emitter);
/**
* Handle changed files
* @param {Object} options
* @param {EventEmitter} emitter
* @returns {Function}
*/
module.exports.getChangeCallback = function (options, emitter) {
var watcher = this.getWatcher(files);
return function (filepath) {
watcher.on("ready", watchCallback);
watcher.on("changed", changeCallback);
},
/**
* Plugin interface
* @returns {*|function(this:exports)}
*/
plugin: function () {
return function (files, options, emitter) {
this.init(files, options, emitter);
}.bind(this);
}
var chunks = [];
fs.createReadStream(filepath)
.on("data", push)
.on("end", end);
function push(chunk) {
chunks.push(chunk);
}
function end() {
if (chunks.join("").length > 0) {
setTimeout(function () {
emitter.emit("file:changed", {path: filepath});
}, options.reloadDelay || 0);
}
}
};
};

@@ -82,2 +82,7 @@ "use strict";

},
/**
* @param app
* @param middleware
* @returns {*}
*/
addMiddleware: function (app, middleware) {

@@ -95,2 +100,7 @@

},
/**
* @param app
* @param base
* @param index
*/
addBaseDir: function (app, base, index) {

@@ -104,2 +114,16 @@ if (Array.isArray(base)) {

}
},
/**
* @param app
* @param base
* @param directory
*/
addDirectory: function (app, base, directory) {
var dirBase = base;
if (directory) {
if (typeof directory === "string") {
dirBase = filePath.resolve(directory);
}
app.use(connect.directory(dirBase, {icons:true}));
}
}

@@ -119,8 +143,9 @@ };

var proxy = options.proxy || false;
var server = options.server || false;
var app;
var staticServer, proxyServer;
var proxy = options.proxy || false;
var server = options.server || false;
var staticServer;
var proxyServer;
var navCallback = utils.navigateCallback(io, options);
var scriptTags = messages.scriptTags(host, ports, options);
var scriptTags = options.snippet = messages.scriptTags(host, ports, options);

@@ -133,4 +158,5 @@ if (proxy) {

var baseDir = options.server.baseDir;
var index = options.server.index || "index.html";
var baseDir = server.baseDir;
var index = server.index || "index.html";
var directory = server.directory;

@@ -150,4 +176,9 @@ app = connect();

if (directory) {
utils.addDirectory(app, baseDir, server.directory);
}
utils.addBaseDir(app, baseDir, index);
staticServer = http.createServer(app);

@@ -154,0 +185,0 @@ }

@@ -6,67 +6,60 @@ "use strict";

/**
* @type {{setupSocket: setupSocket}}
* Plugin interface
* @returns {*|function(this:exports)}
*/
module.exports = {
/**
* @param {Number} port
* @param {Array} events
* @param {Object} options
* @param {EventEmitter} emitter
* @returns {*|http.Server}
*/
init: function (port, events, options, emitter) {
module.exports.plugin = function () {
return function (port, events, options, emitter) {
return exports.init(port, events, options, emitter);
};
};
var io = socket.listen(port, {log: false});
/**
* @param client
* @param event
*/
module.exports.clientEvent = function (client, event) {
client.on(event, function (data) {
client.broadcast.emit(event, data);
});
};
io.set("log level", 0);
/**
* @param {Array} events
* @param {Object} options
* @param {Socket} io
* @param {EventEmitter} emitter
*/
module.exports.socketConnection = function (events, options, io, emitter) {
this.socketConnection(events, options, io, emitter);
var ua;
return io;
},
/**
* @param {Array} events
* @param {Object} options
* @param {Socket} io
* @param {EventEmitter} emitter
*/
socketConnection: function (events, options, io, emitter) {
io.sockets.on("connection", function (client) {
var _this = this;
var ua;
// set ghostmode callbacks
if (options.ghostMode) {
events.forEach(function (evt) {
exports.clientEvent(client, evt);
});
}
io.sockets.on("connection", function (client) {
client.emit("connection", options);
// set ghostmode callbacks
if (options.ghostMode) {
events.forEach(function (evt) {
_this.clientEvent(client, evt);
});
}
ua = client.handshake.headers["user-agent"];
client.emit("connection", options);
emitter.emit("client:connected", {ua: ua});
});
};
ua = client.handshake.headers["user-agent"];
emitter.emit("client:connected", {ua: ua});
});
},
/**
* @param client
* @param event
*/
clientEvent: function (client, event) {
client.on(event, function (data) {
client.broadcast.emit(event, data);
});
},
/**
* Plugin interface
* @returns {*|function(this:exports)}
*/
plugin: function () {
return function (port, events, options, emitter) {
return this.init(port, events, options, emitter);
}.bind(this);
}
/**
* @param {Number} port
* @param {Array} events
* @param {Object} options
* @param {EventEmitter} emitter
* @returns {*|http.Server}
*/
module.exports.init = function (port, events, options, emitter) {
var io = socket.listen(port, {log: false});
io.set("log level", 0);
exports.socketConnection(events, options, io, emitter);
return io;
};

@@ -77,2 +77,6 @@ "use strict";

if (options.proxy && options.proxy.startPath) {
startPath = options.proxy.startPath;
}
if (startPath) {

@@ -85,2 +89,3 @@ if (startPath.charAt(0) === "/") {

return url;

@@ -87,0 +92,0 @@ },

{
"name": "browser-sync",
"description": "Live CSS Reload & Browser Syncing",
"version": "0.7.2",
"version": "0.7.3",
"homepage": "https://github.com/shakyshane/browser-sync",

@@ -35,3 +35,3 @@ "author": {

"lodash": "~2.2.1",
"socket.io": "~0.9.16",
"socket.io": "~0.8.0",
"connect": "~2.13.0",

@@ -47,3 +47,3 @@ "ua-parser-js": "~0.6.2",

"commander": "~2.1.0",
"browser-sync-control-panel": "0.0.1"
"browser-sync-control-panel": "0.0.3"
},

@@ -56,3 +56,3 @@ "devDependencies": {

"sinon": "~1.7.3",
"lodash": "~1.3.1",
"lodash": "~2.4.1",
"supertest": "~0.9.0",

@@ -59,0 +59,0 @@ "mocha": "*",

@@ -64,3 +64,3 @@ # browser-sync [![Build Status](https://travis-ci.org/shakyShane/browser-sync.png?branch=master)](https://travis-ci.org/shakyShane/browser-sync) [![NPM version](https://badge.fury.io/js/browser-sync.png)](http://badge.fury.io/js/browser-sync) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)

```
389 Shane Osbourne
398 Shane Osbourne
13 Hugo Bessa

@@ -67,0 +67,0 @@ 2 brutaldev

Sorry, the diff of this file is not supported yet

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