Skip to content

Commit

Permalink
Do not include empty lines or comment lines in the patterns extracted…
Browse files Browse the repository at this point in the history
… from .tesselignore (matchs fstream-ignore semantics).
  • Loading branch information
rwaldron committed Nov 2, 2015
1 parent 91e8724 commit 1c6ace2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,16 @@ actions.tarBundle = function(opts) {

var rules = ignoreFiles.reduce(function(rules, ignoreFile) {
var dirname = path.dirname(ignoreFile);
var patterns = fs.readFileSync(ignoreFile, 'utf8').trim().split(/\r?\n/).map(function(pattern) {
return path.relative(target, path.join(dirname, pattern));
});
var patterns = fs.readFileSync(ignoreFile, 'utf8').trim().split(/\r?\n/).reduce(function(patterns, pattern) {
pattern = pattern.trim();

// Ignores empty lines and comments
if (pattern && !pattern.match(/^#/)) {
patterns.push(path.relative(target, path.join(dirname, pattern)));
}

return patterns;
}, []);

return rules.concat(patterns);
}, []).map(function(rule) {
Expand Down
45 changes: 45 additions & 0 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,51 @@ exports['tarBundle'] = {
done();
},

tesselIgnore: function(test) {
test.expect(2);

var target = 'test/unit/fixtures/ignore';
var entryPoint = 'index.js';
var fileToIgnore = path.join(target, 'mock-foo.js');
var slimPath = '__tessel_program__.js';

this.glob.restore();
this.globSync.restore();
this.globSync = sandbox.stub(deploy.glob, 'sync', function() {
return [fileToIgnore];
});

deploy.tarBundle({
target: target,
resolvedEntryPoint: entryPoint,
slimPath: slimPath,
slim: true,
}).then(function() {

// There are only 4 valid rules. (2 in each .tesselignore)
// The empty line MUST NOT create a pattern entry.
// The comment line MUST NOT create a pattern entry.
test.equal(this.globSync.callCount, 4);
test.deepEqual(this.globSync.args, [
['a/**/*.*', {
cwd: 'test/unit/fixtures/ignore'
}],
['mock-foo.js', {
cwd: 'test/unit/fixtures/ignore'
}],
['nested/b/**/*.*', {
cwd: 'test/unit/fixtures/ignore'
}],
['nested/file.js', {
cwd: 'test/unit/fixtures/ignore'
}]
]);

test.done();
}.bind(this));
},


full: function(test) {
test.expect(11);

Expand Down
4 changes: 4 additions & 0 deletions test/unit/fixtures/ignore/.tesselignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# comment line
a/

mock-foo.js
2 changes: 2 additions & 0 deletions test/unit/fixtures/ignore/nested/.tesselignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
b/
file.js

0 comments on commit 1c6ace2

Please sign in to comment.