Skip to content

Commit

Permalink
fix(files): Fix a regression where strings within the 'files' option …
Browse files Browse the repository at this point in the history
…were split on commas - fixes #1080
  • Loading branch information
shakyShane committed Apr 25, 2016
1 parent 5a2e3d9 commit 4ccdc0a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/cli/cli-options.js
Expand Up @@ -297,9 +297,7 @@ opts.makeFilesArg = function (value) {
if (isList(value) && value.size) {
value.forEach(function (value) {
if (_.isString(value)) {
globs = globs.concat(
opts.utils.explodeFilesArg(value)
);
globs.push(value);
} else {
if (isMap(value)) {
objs.push(value);
Expand Down
29 changes: 28 additions & 1 deletion lib/cli/command.start.js
Expand Up @@ -4,6 +4,7 @@ var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var utils = require("../utils");
var opts = require("./cli-options").utils;

/**
* $ browser-sync start <options>
Expand All @@ -16,7 +17,7 @@ var utils = require("../utils");
*/
module.exports = function (opts) {

var flags = stripUndefined(opts.cli.flags);
var flags = preprocessFlags(opts.cli.flags);
var maybepkg = path.resolve(process.cwd(), "package.json");
var input = flags;

Expand All @@ -43,6 +44,19 @@ module.exports = function (opts) {
.init(input, opts.cb);
};

/**
* @param flags
* @returns {*}
*/
function preprocessFlags (flags) {
return [
stripUndefined,
legacyFilesArgs
].reduce(function (flags, fn) {
return fn.call(null, flags);
}, flags);
}

/**
* Incoming undefined values are problematic as
* they interfere with Immutable.Map.mergeDeep
Expand All @@ -59,3 +73,16 @@ function stripUndefined (subject) {
return acc;
}, {});
}

/**
* @param flags
* @returns {*}
*/
function legacyFilesArgs(flags) {
if (flags.files && flags.files.length) {
flags.files = flags.files.reduce(function (acc, item) {
return acc.concat(opts.explodeFilesArg(item));
}, []);
}
return flags;
}
7 changes: 0 additions & 7 deletions test/specs/cli/cli.options.files.js
Expand Up @@ -13,13 +13,6 @@ describe("CLI: Options: Merging Options: Files", function () {
objs: []
});
});
it("should return the files property from Array given with strings in legacy format", function () {
var imm = merge({files: ["css/*.css,*.html"]});
assert.deepEqual(imm.get("files").get("core").toJS(), {
globs: ["css/*.css", "*.html"],
objs: []
});
});
it("should return the files property from array given", function () {
var imm = merge({files: ["css/*.css", "*.html"]});
assert.deepEqual(imm.get("files").get("core").toJS(), {
Expand Down
26 changes: 24 additions & 2 deletions test/specs/e2e/cli/e2e.cli.files.js
Expand Up @@ -16,7 +16,7 @@ describe("E2E CLI `files` arg - multi globs", function () {
flags: {
logLevel: "silent",
open: false,
files: "*.html, css/*.css"
files: ["*.html, css/*.css"]
}
},
cb: function (err, bs) {
Expand All @@ -38,7 +38,7 @@ describe("E2E CLI `files` arg, single glob", function () {
flags: {
logLevel: "silent",
open: false,
files: "*.html"
files: ["*.html"]
}
},
cb: function (err, bs) {
Expand All @@ -50,3 +50,25 @@ describe("E2E CLI `files` arg, single glob", function () {
});
});
});

describe("E2E CLI `files` arg, with commas", function () {
it("Converts cli files arg", function (done) {
browserSync.reset();
cli({
cli: {
input: ["start"],
flags: {
logLevel: "silent",
open: false,
files: ["*.css,*.html"]
}
},
cb: function (err, bs) {
assert.equal(bs.options.getIn(["files", "core", "globs"]).size, 2);
assert.isTrue(Array.isArray(bs.watchers.core.watchers));
bs.cleanup();
done();
}
});
});
});
17 changes: 17 additions & 0 deletions test/specs/files/files.watching.js
Expand Up @@ -134,4 +134,21 @@ describe("File Watcher Module", function () {
done();
});
});
it("should allow arrays with , in API mode", function (done) {

browserSync.reset();
var bs = browserSync.create();

bs.init({
files: ["test/fixtures/**/*.{css,html}"],
ui: false,
online: false,
logSnippet: false,
logLevel: "silent"
}, function (err, bs) {
assert.equal(bs.options.getIn(["files", "core", "globs"]).size, 1);
bs.cleanup();
done();
});
});
});

0 comments on commit 4ccdc0a

Please sign in to comment.