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.4.0 to 0.4.1

77

Gruntfile.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -15,3 +15,3 @@ module.exports = function (grunt) {

nodeunit: {
files: ['test/**/*_test.js']
files: ["test/**/*_test.js"]
},

@@ -21,3 +21,3 @@ uglify: {

files: {
'lib/browser-sync-client.min.js': 'lib/browser-sync-client.js'
"lib/browser-sync-client.min.js": "lib/browser-sync-client.js"
}

@@ -29,17 +29,17 @@ }

options: {
jshintrc: '.jshintrc'
jshintrc: ".jshintrc"
},
src: 'Gruntfile.js'
src: "Gruntfile.js"
},
lib: {
options: {
jshintrc: '.jshintrc'
jshintrc: ".jshintrc"
},
src: ['lib/**/*.js', '!lib/browser-sync-client.min.js']
src: ["lib/**/*.js", "!lib/browser-sync-client.min.js"]
},
test: {
options: {
jshintrc: 'test/.jshintrc'
jshintrc: "test/.jshintrc"
},
src: ['test/**/*.js']
src: ["test/server/**/*.js", "test/client-script/**/*.js", "!test/client-script/libs/**/*"]
}

@@ -49,12 +49,16 @@ },

test: {
files: ['test/**/*.js', 'lib/**/*.js'],
tasks: ['jasmine_node']
files: ["test/**/*.js", "lib/**/*.js"],
tasks: ["jasmine_node"]
},
sass: {
files: ['test/fixtures/scss/bootstrap.scss'],
tasks: ['sass']
files: ["test/fixtures/scss/bootstrap.scss"],
tasks: ["sass"]
},
less: {
files: ['test/fixtures/less/bootstrap.less'],
tasks: ['less']
files: ["test/fixtures/less/bootstrap.less"],
tasks: ["less"]
},
jshint: {
files: ["test/server/**/*.js", "test/client-script/**/*.js", "!test/client-script/libs"],
tasks: ["jshint:test"]
}

@@ -64,20 +68,16 @@ },

unit: {
configFile: 'test/karma.conf.js',
configFile: "test/karma.conf.js",
singleRun: true
},
watch: {
configFile: 'test/karma.conf.js',
configFile: "test/karma.conf.js",
singleRun: false
}
},
jasmine_node: {
specNameMatcher: "Spec", // load only specs containing specNameMatcher
projectRoot: "test/new-server",
requirejs: false,
forceExit: true,
jUnit: {
report: false,
savePath: "./build/reports/jasmine/",
useDotNotation: true,
consolidate: true
mochaTest: {
test: {
options: {
reporter: "spec"
},
src: ["test/server/**/*.js"]
}

@@ -87,3 +87,3 @@ },

github: {
command: 'git push origin master',
command: "git push origin master",
options: {

@@ -124,16 +124,15 @@ stdout: true

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-mocha-test");
grunt.loadNpmTasks("grunt-karma");
grunt.loadNpmTasks("grunt-shell");
// Tests
grunt.registerTask('default', ['jasmine_node']);
grunt.registerTask('test:server', ['jshint', 'jasmine_node']);
grunt.registerTask('test:client', ['jshint', 'karma:unit']);
grunt.registerTask('test', ['jshint', 'karma:unit', 'jasmine_node']);
grunt.registerTask("test:server", ["jshint", "mochaTest"]);
grunt.registerTask("test:client", ["jshint", "karma:unit"]);
grunt.registerTask("test", ["jshint", "karma:unit", "mochaTest"]);
grunt.registerTask('release:github', ['jshint', 'karma:unit', 'jasmine_node', 'shell:github']);
grunt.registerTask("release:github", ["jshint", "karma:unit", "mochaTest", "shell:github"]);
};

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -20,2 +20,3 @@ /*global window*/

"jpg": "img",
"jpeg": "img",
"png": "img",

@@ -33,2 +34,13 @@ "svg": "img",

var styles = [
"background-color: black",
"color: white",
"padding: 10px",
"display: none",
"fontFamily: sans-serif",
"position: absolute",
"zIndex: 1000",
"right: 0px"
];
var notifyElem;

@@ -49,32 +61,37 @@

if (options.notify) {
this.createNotifyElem();
notifyElem = this.createNotifyElem(styles || null);
}
},
createNotifyElem: function () {
/**
* @param {Array} [styles]
* @returns {HTMLElement}
*/
createNotifyElem: function (styles) {
notifyElem = document.createElement("DIV");
var elem = document.createElement("DIV");
elem.id = "notifyElem";
notifyElem.style.backgroundColor = "black";
notifyElem.style.color = "white";
notifyElem.style.padding = "10px";
notifyElem.style.display = "none";
notifyElem.style.fontFamily = "sans-serif";
notifyElem.style.position = "absolute";
notifyElem.style.zIndex = "1000";
notifyElem.style.right = "0px";
if (styles) {
elem.style.cssText = styles.join(";");
}
document.getElementsByTagName('body')[0].appendChild(notifyElem);
document.getElementsByTagName("body")[0].appendChild(elem);
return elem;
},
notify: function (message) {
if (notifyElem) {
/**
* @param {String} message
* @param {HTMLElement} elem
* @param {Number} [timeout]
*/
notify: function (message, elem, timeout) {
notifyElem.innerHTML = message;
notifyElem.style.top = ghost.getScrollTop() + "px";
notifyElem.style.display = "block";
elem.innerHTML = message;
elem.style.top = ghost.getScrollTop() + "px";
elem.style.display = "block";
window.setTimeout(function () {
notifyElem.style.display = "none";
}, 1000);
window.setTimeout(function () {
elem.style.display = "none";
}, timeout || 1000);
}
return elem;
},

@@ -92,3 +109,3 @@ /**

if (ghostMode.scroll) {
ghost.initEvents(scope, ['scroll'], utils, listeners);
ghost.initEvents(scope, ["scroll"], utils, listeners);
}

@@ -140,7 +157,7 @@

browserSync.notify("Injected: " + data.assetFileName);
browserSync.notify("Injected: " + data.assetFileName, notifyElem);
var domData = this.getElems(data.fileExtension);
var elems = this.getMatches(domData.elems, data.assetFileName, domData.attr);
for (var i = 0, n = elems.length; i < n; i += 1) {

@@ -376,3 +393,5 @@ transformedElem = actions.swapFile(elems[i], domData.attr);

emitEvent: function (name, data) {
socket.emit(name, data);
if (socket && socket.emit) {
socket.emit(name, data);
}
},

@@ -398,4 +417,4 @@ /**

* @param {HTMLElement} elem
* @param {HTMLElement} context
* @returns {string}
* @param {HTMLElement} [context]
* @returns {String}
*/

@@ -570,3 +589,3 @@ getHref: function (elem, context) {

if (window.__karma__) {
window.browserSync = browserSync;
window.bs = browserSync;
window.browserSyncActions = browserSyncActions;

@@ -582,3 +601,3 @@ window.ghost = ghost;

socket.on('reload', function (data) {
socket.on("reload", function (data) {
if (data) {

@@ -589,3 +608,3 @@ browserSync.reloadEvent(scope, data, browserSyncActions);

socket.on('location:update', function (data) {
socket.on("location:update", function (data) {
if (data.url) {

@@ -592,0 +611,0 @@ window.location = data.url;

@@ -1,3 +0,3 @@

var portScanner = require('portscanner');
var gaze = require('gaze');
var portScanner = require("portscanner");
var gaze = require("gaze");
var _ = require("lodash");

@@ -8,11 +8,12 @@ var fs = require("fs");

var http = require("http");
var devIp = require('dev-ip');
var UAParser = require('ua-parser-js');
var devIp = require("dev-ip");
var UAParser = require("ua-parser-js");
var messages = require('./messages');
var loadSnippet = require('./loadSnippet');
var createProxy = require('./dev-proxy');
var messages = require("./messages");
var loadSnippet = require("./loadSnippet");
var createProxy = require("./dev-proxy");
var parser = new UAParser();
var browserSync = function () {};
var cwd = process.cwd();

@@ -22,4 +23,6 @@ var io;

browserSync.prototype = {
cwd: cwd,
options: {
injectFileTypes: ['css', 'png', 'jpg', 'svg', 'gif']
injectFileTypes: ["css", "png", "jpg", "svg", "gif"],
minPorts: 3
},

@@ -34,34 +37,76 @@ /**

var _this = this, iolocal, handles, server, watcher;
var _this = this, iolocal, handles, server, watcher, minPorts = this.options.minPorts;
this.getPorts(3, function (ports) {
var portRange = this.getPortRange(minPorts, options);
// setup Socket.io
iolocal = _this.setupSocket(ports);
if (portRange) {
// Set up event callbacks
handles = _this.handleSocketConnection(_this.callbacks, options, _this.handleClientSocketEvent);
this.getPorts(minPorts, function (ports) {
// launch the server
server = _this.launchServer(_this.getHostIp(options), ports, options);
// setup Socket.io
iolocal = _this.setupSocket(ports);
// Watch files
watcher = _this.watchFiles(files, io, _this.changeFile, options);
// Set up event callbacks
handles = _this.handleSocketConnection(_this.callbacks, options, _this.handleClientSocketEvent);
}, options);
// launch the server
server = _this.launchServer(_this.getHostIp(options, devIp.getIp(null)), ports, options);
// Watch files
watcher = _this.watchFiles(files, io, _this.changeFile, options);
}, portRange.min, portRange.max);
} else {
this.fail(messages.ports.invalid(minPorts), options, true);
}
},
/**
* @param {Number} minCount
* @param {Object} options
*/
getPortRange: function (minCount, options) {
var ports = options.ports;
if (ports) {
if (ports.min && ports.max) {
if ((ports.max - ports.min + 1) < minCount) {
return false;
}
return {
min: ports.min,
max: ports.max
};
}
if (ports.min) {
var max = ports.min + 500;
return {
min: ports.min,
max: max < 10000 ? max : 9999
};
}
}
return {
min: 3000,
max: 4000
};
},
/**
* Get two available Ports
* @param {Number} limit
* @param {Function} callback
* @param {Number} [min]
* @param {Number} [max]
*/
getPorts: function (limit, callback) {
getPorts: function (limit, callback, min, max) {
var ports = [];
var lastFound = 2999;
var lastFound = min - 1 || 2999;
// get a port (async)
var getPort = function () {
portScanner.findAPortNotInUse(lastFound + 1, 4000, 'localhost', function (error, port) {
portScanner.findAPortNotInUse(lastFound + 1, max || 4000, "localhost", function (error, port) {
ports.push(port);

@@ -94,4 +139,4 @@ lastFound = port;

io = require('socket.io').listen(ports[0]);
io.set('log level', 0);
io = require("socket.io").listen(ports[0]);
io.set("log level", 0);

@@ -110,3 +155,2 @@ return io;

var ua;
io.sockets.on("connection", function (client) {

@@ -123,3 +167,3 @@

ua = client.handshake.headers['user-agent'];
ua = client.handshake.headers["user-agent"];

@@ -210,9 +254,10 @@ _this.logConnection(ua, userOptions);

* Helper to try to retrieve the correct external IP for host
* Defaults to localhost if no network ip's are accessible.
* Defaults to localhost (0.0.0.0) if no network ip's are accessible.
* @param {Object} options
* @param {String} [devIp]
* @returns {String} - the IP address
*/
getHostIp: function (options) {
getHostIp: function (options, devIp) {
var externalIp = "0.0.0.0"; // default
var fallback = "0.0.0.0";

@@ -223,12 +268,12 @@ if (options) {

}
if (options.detect === false) {
return externalIp;
if (options.detect === false || !devIp) {
return fallback;
}
}
return devIp.getIp(null) || externalIp;
return devIp || fallback;
},
/**
* Take the path provided in options & transform into CWD for serving files
* @param {String} baseDir
* @param {String} [baseDir]
* @returns {String}

@@ -279,2 +324,13 @@ */

/**
* @param {String} msg
* @param {Object} options
* @param {Boolean} kill
*/
fail: function (msg, options, kill) {
this.log(msg, options, true);
if (kill) {
process.exit(1);
}
},
/**
* @param {String} path

@@ -308,3 +364,3 @@ * @param {socket} io

// log the message to the console
_this.log(messages.files.changed(path), options, false);
_this.log(messages.files.changed(_this.resolveRelativeFilePath(path, _this.cwd)), options, false);
_this.log(messages.browser[message](), options, false);

@@ -402,7 +458,8 @@

* @param {Array|String} files
* @param {Object} io
* @param {function} callback
* @param options
* @param {socket} io
* @param {Function} callback
* @param {Number} [timeout] - time between changes
* @param {Object} options
*/
watchFiles: function (files, io, callback, options) {
watchFiles: function (files, io, callback, options, timeout) {

@@ -422,3 +479,3 @@ var _this = this, log = this.log, lastInjected = { time: new Date().getTime() };

// On file changed
this.on('changed', function(filepath) {
this.on("changed", function(filepath) {
var stats = fs.statSync(filepath);

@@ -449,3 +506,3 @@ if (stats.size === 0) {

if (new Date().getTime() > lastInjected.time + 2000) {
if (new Date().getTime() > lastInjected.time + (timeout || 2000)) {
callback(filepath, io, options, _this);

@@ -460,2 +517,14 @@ }

},
/**
* @param filepath
* @param cwd
* @returns {*|XML|string|void}
*/
resolveRelativeFilePath: function (filepath, cwd) {
return filepath.replace(cwd + "/", "");
},
/**
* @param {String} path
* @returns {String}
*/
getFileExtension: function (path) {

@@ -462,0 +531,0 @@ return filePath.extname(path).replace(".", "");

@@ -1,5 +0,5 @@

var httpProxy = require('http-proxy');
var messages = require('./messages');
var write = require('./snippet').write;
var utils = require('./snippet').utils;
var httpProxy = require("http-proxy");
var messages = require("./messages");
var write = require("./snippet").write;
var utils = require("./snippet").utils;

@@ -48,3 +48,3 @@ /**

if (response.headers.hasOwnProperty("content-length")) {
delete response.headers['content-length'];
delete response.headers["content-length"];
}

@@ -51,0 +51,0 @@ });

#! /usr/bin/env node
'use strict';
"use strict";
var argv = require('optimist').argv;
var argv = require("optimist").argv;
var bs = require("./browser-sync");

@@ -13,4 +13,4 @@ var fs = require("fs");

defaultConfig: true,
reloadFileTypes: ['php', 'html', 'js', 'erb'],
injectFileTypes: ['css', 'png', 'jpg', 'svg', 'gif'],
reloadFileTypes: ["php", "html", "js", "erb"],
injectFileTypes: ["css", "png", "jpg", "svg", "gif"],
host: null,

@@ -38,3 +38,2 @@ ghostMode: {

getConfig: function (defaultConfig, argv) {
var configArg = argv.config;

@@ -64,2 +63,5 @@

// Ports Config
defaultConfig = this._setPortsConfig(defaultConfig, argv);
if (argv.ghostMode === "false") {

@@ -147,2 +149,29 @@ defaultConfig.ghostMode = false;

/**
*
* @param {Object} defaultConfig
* @param {Object} argv
* @returns {Object}
* @private
*/
_setPortsConfig: function (defaultConfig, argv) {
if (argv.ports) {
if (typeof argv.ports === "number") {
defaultConfig.ports = {
min: argv.ports
};
} else {
var split = argv.ports.replace(" ", "").split(",");
defaultConfig.ports = {
min: parseInt(split[0], 10),
max: (split[1]) ? parseInt(split[1], 10) : null
};
}
}
return defaultConfig;
},
/**
* Retrieve the config file

@@ -149,0 +178,0 @@ * @param path

@@ -1,4 +0,4 @@

var messages = require('./messages');
var write = require('./snippet').write;
var utils = require('./snippet').utils;
var messages = require("./messages");
var write = require("./snippet").write;
var utils = require("./snippet").utils;

@@ -5,0 +5,0 @@ module.exports = function (hostIp, socketIoPort, scriptPort) {

@@ -89,2 +89,16 @@ var compile = require("cl-strings").compile;

},
ports: {
/**
* @param {Number} minCount
* @returns {String}
*/
invalid: function (minCount) {
var template = "{red:Invalid port range!} - At least {:minCount:} required!";
var params = {
minCount: minCount
};
return compile(template, params);
}
},
files: {

@@ -91,0 +105,0 @@ /**

@@ -12,3 +12,3 @@ /**

*/
excludeList: ['.js', '.css', '.svg', '.ico', '.woff', '.png', '.jpg', '.jpeg', '.gif'],
excludeList: [".js", ".css", ".svg", ".ico", ".woff", ".png", ".jpg", ".jpeg", ".gif"],
/**

@@ -75,4 +75,4 @@ * Check if HTML body exists

if (!this.headerSent) {
if (this._headers.hasOwnProperty('content-length')) {
delete this._headers['content-length'];
if (this._headers.hasOwnProperty("content-length")) {
delete this._headers["content-length"];
}

@@ -79,0 +79,0 @@ this._implicitHeader();

{
"name": "browser-sync",
"description": "Live CSS Reload & Browser Syncing",
"version": "0.4.0",
"homepage": "https://github.com/shakyshane/browser-sync",
"author": {
"name": "Shane Osbourne"
},
"repository": {
"type": "git",
"url": "git://github.com/shakyshane/browser-sync.git"
},
"bugs": {
"url": "https://github.com/shakyshane/browser-sync/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/shakyshane/browser-sync/blob/master/LICENSE-MIT"
}
],
"main": "lib/index.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"portscanner": "~0.1.3",
"path": "~0.4.9",
"url": "~0.7.9",
"open": "~0.0.4",
"lodash": "~1.3.1",
"socket.io": "~0.9.16",
"connect": "~2.11.0",
"ua-parser-js": "~0.6.2",
"optimist": "0.6.0",
"dev-ip": "~0.1.5",
"gaze": "~0.4.3",
"http-proxy": "~0.10.3",
"cl-strings": "~0.0.2"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2",
"karma-script-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma": "~0.10.2",
"grunt-karma": "~0.6.2",
"grunt-cli": "*",
"grunt": "~0.4.1",
"grunt-jasmine-node": "~0.1.0",
"optimist": "~0.6.0",
"socket.io-client": "~0.9.16",
"grunt-contrib-watch": "~0.5.3",
"cli-color": "~0.2.3",
"grunt-shell": "~0.6.1"
},
"keywords": [
"browser sync",
"css",
"live reload",
"sync"
],
"bin": {
"browser-sync": "lib/index.js"
"name": "browser-sync",
"description": "Live CSS Reload & Browser Syncing",
"version": "0.4.1",
"homepage": "https://github.com/shakyshane/browser-sync",
"author": {
"name": "Shane Osbourne"
},
"repository": {
"type": "git",
"url": "git://github.com/shakyshane/browser-sync.git"
},
"bugs": {
"url": "https://github.com/shakyshane/browser-sync/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/shakyshane/browser-sync/blob/master/LICENSE-MIT"
}
],
"main": "lib/index.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"portscanner": "~0.1.3",
"path": "~0.4.9",
"url": "~0.7.9",
"open": "~0.0.4",
"lodash": "~1.3.1",
"socket.io": "~0.9.16",
"connect": "~2.11.0",
"ua-parser-js": "~0.6.2",
"optimist": "0.6.0",
"dev-ip": "~0.1.5",
"gaze": "~0.4.3",
"http-proxy": "~0.10.3",
"cl-strings": "~0.0.2"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-uglify": "~0.2.2",
"karma-script-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma": "~0.10.2",
"grunt-karma": "~0.6.2",
"grunt-cli": "*",
"grunt": "~0.4.1",
"optimist": "~0.6.0",
"socket.io-client": "~0.9.16",
"grunt-contrib-watch": "~0.5.3",
"cli-color": "~0.2.3",
"grunt-shell": "~0.6.1",
"grunt-mocha-test": "~0.8.1",
"chai": "~1.8.1",
"sinon": "~1.7.3",
"karma-mocha": "~0.1.1",
"karma-sinon": "~1.0.0"
},
"keywords": [
"browser sync",
"css",
"live reload",
"sync"
],
"bin": {
"browser-sync": "lib/index.js"
}
}

@@ -213,2 +213,18 @@ # 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/)

###ports - (default: null)
Browser-sync will detect up to 3 available ports to use within a fixed range. You can override this if you need to.
```
// only use ports within a certain range
ports: {
min: 3000,
max: 3100
}
// you can also specify just a minimum
ports: {
min: 3000
}
```
###open - (default: true) - when used with server

@@ -215,0 +231,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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