From 1c6ace2034249e70f10a57ab0540600f4dc7c250 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 2 Nov 2015 17:09:17 -0500 Subject: [PATCH] Do not include empty lines or comment lines in the patterns extracted from .tesselignore (matchs fstream-ignore semantics). --- lib/tessel/deploy.js | 13 ++++-- test/unit/deploy.js | 45 +++++++++++++++++++ test/unit/fixtures/ignore/.tesselignore | 4 ++ .../unit/fixtures/ignore/nested/.tesselignore | 2 + 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/unit/fixtures/ignore/.tesselignore create mode 100644 test/unit/fixtures/ignore/nested/.tesselignore diff --git a/lib/tessel/deploy.js b/lib/tessel/deploy.js index 679e6152..62835225 100644 --- a/lib/tessel/deploy.js +++ b/lib/tessel/deploy.js @@ -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) { diff --git a/test/unit/deploy.js b/test/unit/deploy.js index 17fff7b3..72f963b5 100644 --- a/test/unit/deploy.js +++ b/test/unit/deploy.js @@ -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); diff --git a/test/unit/fixtures/ignore/.tesselignore b/test/unit/fixtures/ignore/.tesselignore new file mode 100644 index 00000000..2b8f9276 --- /dev/null +++ b/test/unit/fixtures/ignore/.tesselignore @@ -0,0 +1,4 @@ +# comment line +a/ + +mock-foo.js diff --git a/test/unit/fixtures/ignore/nested/.tesselignore b/test/unit/fixtures/ignore/nested/.tesselignore new file mode 100644 index 00000000..6af01d2d --- /dev/null +++ b/test/unit/fixtures/ignore/nested/.tesselignore @@ -0,0 +1,2 @@ +b/ +file.js