Skip to content

Commit 4ccdc0a

Browse files
committed
fix(files): Fix a regression where strings within the 'files' option were split on commas - fixes #1080
1 parent 5a2e3d9 commit 4ccdc0a

5 files changed

Lines changed: 70 additions & 13 deletions

File tree

lib/cli/cli-options.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ opts.makeFilesArg = function (value) {
297297
if (isList(value) && value.size) {
298298
value.forEach(function (value) {
299299
if (_.isString(value)) {
300-
globs = globs.concat(
301-
opts.utils.explodeFilesArg(value)
302-
);
300+
globs.push(value);
303301
} else {
304302
if (isMap(value)) {
305303
objs.push(value);

lib/cli/command.start.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var path = require("path");
44
var fs = require("fs");
55
var _ = require("lodash");
66
var utils = require("../utils");
7+
var opts = require("./cli-options").utils;
78

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

19-
var flags = stripUndefined(opts.cli.flags);
20+
var flags = preprocessFlags(opts.cli.flags);
2021
var maybepkg = path.resolve(process.cwd(), "package.json");
2122
var input = flags;
2223

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

47+
/**
48+
* @param flags
49+
* @returns {*}
50+
*/
51+
function preprocessFlags (flags) {
52+
return [
53+
stripUndefined,
54+
legacyFilesArgs
55+
].reduce(function (flags, fn) {
56+
return fn.call(null, flags);
57+
}, flags);
58+
}
59+
4660
/**
4761
* Incoming undefined values are problematic as
4862
* they interfere with Immutable.Map.mergeDeep
@@ -59,3 +73,16 @@ function stripUndefined (subject) {
5973
return acc;
6074
}, {});
6175
}
76+
77+
/**
78+
* @param flags
79+
* @returns {*}
80+
*/
81+
function legacyFilesArgs(flags) {
82+
if (flags.files && flags.files.length) {
83+
flags.files = flags.files.reduce(function (acc, item) {
84+
return acc.concat(opts.explodeFilesArg(item));
85+
}, []);
86+
}
87+
return flags;
88+
}

test/specs/cli/cli.options.files.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ describe("CLI: Options: Merging Options: Files", function () {
1313
objs: []
1414
});
1515
});
16-
it("should return the files property from Array given with strings in legacy format", function () {
17-
var imm = merge({files: ["css/*.css,*.html"]});
18-
assert.deepEqual(imm.get("files").get("core").toJS(), {
19-
globs: ["css/*.css", "*.html"],
20-
objs: []
21-
});
22-
});
2316
it("should return the files property from array given", function () {
2417
var imm = merge({files: ["css/*.css", "*.html"]});
2518
assert.deepEqual(imm.get("files").get("core").toJS(), {

test/specs/e2e/cli/e2e.cli.files.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("E2E CLI `files` arg - multi globs", function () {
1616
flags: {
1717
logLevel: "silent",
1818
open: false,
19-
files: "*.html, css/*.css"
19+
files: ["*.html, css/*.css"]
2020
}
2121
},
2222
cb: function (err, bs) {
@@ -38,7 +38,7 @@ describe("E2E CLI `files` arg, single glob", function () {
3838
flags: {
3939
logLevel: "silent",
4040
open: false,
41-
files: "*.html"
41+
files: ["*.html"]
4242
}
4343
},
4444
cb: function (err, bs) {
@@ -50,3 +50,25 @@ describe("E2E CLI `files` arg, single glob", function () {
5050
});
5151
});
5252
});
53+
54+
describe("E2E CLI `files` arg, with commas", function () {
55+
it("Converts cli files arg", function (done) {
56+
browserSync.reset();
57+
cli({
58+
cli: {
59+
input: ["start"],
60+
flags: {
61+
logLevel: "silent",
62+
open: false,
63+
files: ["*.css,*.html"]
64+
}
65+
},
66+
cb: function (err, bs) {
67+
assert.equal(bs.options.getIn(["files", "core", "globs"]).size, 2);
68+
assert.isTrue(Array.isArray(bs.watchers.core.watchers));
69+
bs.cleanup();
70+
done();
71+
}
72+
});
73+
});
74+
});

test/specs/files/files.watching.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,21 @@ describe("File Watcher Module", function () {
134134
done();
135135
});
136136
});
137+
it("should allow arrays with , in API mode", function (done) {
138+
139+
browserSync.reset();
140+
var bs = browserSync.create();
141+
142+
bs.init({
143+
files: ["test/fixtures/**/*.{css,html}"],
144+
ui: false,
145+
online: false,
146+
logSnippet: false,
147+
logLevel: "silent"
148+
}, function (err, bs) {
149+
assert.equal(bs.options.getIn(["files", "core", "globs"]).size, 1);
150+
bs.cleanup();
151+
done();
152+
});
153+
});
137154
});

0 commit comments

Comments
 (0)