Skip to content

Commit

Permalink
Dependency: update to t2-project@0.2.0; Use explicit dirname for depe…
Browse files Browse the repository at this point in the history
…ndency graph. (#660)

Closes tessel/ambient-attx4#53

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 11, 2016
1 parent 8d9d3ee commit e7860cc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
34 changes: 27 additions & 7 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ actions.tarBundle = function(opts) {

if (opts.slim) {
return new Promise((resolve, reject) => {
var absRoot = path.resolve(globRoot);
// Setup for detecting "overlooked" assets (files, directories, etc.)
var common = ['node_modules', 'package.json', '.tesselinclude', opts.resolvedEntryPoint];
// These will be compared against the dependency graph
Expand All @@ -781,18 +782,20 @@ actions.tarBundle = function(opts) {
// Initialize a project for dependency graphing
var entry = path.join(relative, opts.resolvedEntryPoint);
var project = actions.project({
entry: entry
entry: entry,
dirname: globRoot,
});

project.on('error', error => reject(error));

// Remove the includeFiles from the ignoreFiles
ignoreFiles = ignoreFiles.filter(file => includeFiles.indexOf(file) === -1);

// Inform the project of files to exclude
project.exclude(
ignoreFiles.reduce((files, file) => {
if (includeFiles.indexOf(file) === -1) {
files.push(path.normalize(file));
files.push(path.join(globRoot, file));
}
files.push(path.normalize(file));
files.push(path.join(globRoot, file));
return files;
}, [])
);
Expand All @@ -802,7 +805,6 @@ actions.tarBundle = function(opts) {
if (error) {
return reject(error);
} else {
var absRoot = path.resolve(globRoot);
var written = {};

// 1. Move all dependency entries to the temp directory
Expand All @@ -811,6 +813,21 @@ actions.tarBundle = function(opts) {
var source = dependency.source;
var target = path.normalize(dependency.file.replace(absRoot, tempBundleDir));
var compressionOptions = deployLists.compressionOptions[dependency.packageName];
var isIgnored = false;

// Last check against ignored files. This is necessary because
// the _entryPoint_ dirname might be further down from the project
// root dirname, which will prevent nested rules from being applied
ignoreFiles.forEach(file => {
var target = path.join(absRoot, file);
if (target === dependency.file) {
isIgnored = true;
}
});

if (isIgnored) {
return;
}

if (opts.single && !dependency.entry) {
return;
Expand Down Expand Up @@ -841,7 +858,10 @@ actions.tarBundle = function(opts) {
written[target] = true;
});

// 2. Copy any files that matched all .tesselinclude patterns
// 2. Copy any files that matched all .tesselinclude patterns,
// where the file in question was actually ignored due to
// an ignore rule. Ultimately, .tesselinclude has the final
// word on any file's inclusion/exclusion
if (!opts.single) {
includeFiles.forEach(file => {
var target = path.join(tempBundleDir, file);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"ssh2": "^0.4.2",
"sshpk": "^1.6.0",
"stream-to-buffer": "^0.1.0",
"t2-project": "^0.1.0",
"t2-project": "^0.2.0",
"tar": "^2.1.1",
"tar-stream": "^1.3.0",
"uglify-js": "^2.5.0",
Expand Down
19 changes: 19 additions & 0 deletions test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,25 @@ exports['deploy.tarBundle'] = {
test.done();
});
},

alwaysExplicitlyProvideProjectDirname: function(test) {
test.expect(1);

var entryPoint = 'index.js';
var target = 'test/unit/fixtures/project';

deploy.tarBundle({
target: path.normalize(target),
resolvedEntryPoint: entryPoint,
slim: true,
}).then(() => {
test.deepEqual(this.project.lastCall.args[0], {
entry: path.join(target, entryPoint),
dirname: path.normalize(target),
});
test.done();
});
},
};

exports['Tessel.prototype.restartScript'] = {
Expand Down

0 comments on commit e7860cc

Please sign in to comment.