Skip to content

Commit

Permalink
fix(deploy): catches/rejects swallowed copySync errors
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Jan 16, 2016
1 parent c0a73d8 commit 7d610fb
Showing 1 changed file with 81 additions and 77 deletions.
158 changes: 81 additions & 77 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ actions.resolveBinaryModules = function(opts) {

actions.injectBinaryModules = function(globRoot, tempBundlePath) {

return new Promise(resolve => {
return new Promise((resolve) => {
// For every binary module in use...
binaryModulesUsed.forEach(details => {
var sourceBinary = path.join(details.extractPath, 'Release', details.binName);
Expand Down Expand Up @@ -636,35 +636,37 @@ actions.tarBundle = function(opts) {
}
});

actions.injectBinaryModules(globRoot, tempBundleDir).then(() => {
var fstream = new Reader({
path: tempBundleDir,
type: 'Directory',
});
actions.injectBinaryModules(globRoot, tempBundleDir)
.then(() => {
var fstream = new Reader({
path: tempBundleDir,
type: 'Directory',
});

fstream
.on('entry', (entry) => {
entry.root = {
path: entry.path
};
})
.pipe(packer)
.on('data', (chunk) => {
buffers.push(chunk);
})
.on('error', (data) => {
reject(data);
})
.on('end', () => {
fs.remove(tempBundleDir, (error) => {
if (error) {
reject(error);
} else {
resolve(Buffer.concat(buffers));
}
fstream
.on('entry', (entry) => {
entry.root = {
path: entry.path
};
})
.pipe(packer)
.on('data', (chunk) => {
buffers.push(chunk);
})
.on('error', (data) => {
reject(data);
})
.on('end', () => {
fs.remove(tempBundleDir, (error) => {
if (error) {
reject(error);
} else {
resolve(Buffer.concat(buffers));
}
});
});
});
});
})
.catch(reject);
}
});
});
Expand All @@ -675,62 +677,64 @@ actions.tarBundle = function(opts) {
// This allows us a safe way to "swap" binary modules.
fs.copySync(globRoot, tempBundleDir);

return actions.injectBinaryModules(globRoot, tempBundleDir).then(() => {
var fstream = new Ignore({
basename: '',
ignoreFiles: ['.tesselignore'],
path: tempBundleDir,
});
return actions.injectBinaryModules(globRoot, tempBundleDir)
.then(() => {
var fstream = new Ignore({
basename: '',
ignoreFiles: ['.tesselignore'],
path: tempBundleDir,
});

// Don't send the actual rules files
fstream.addIgnoreRules([
'**/.tesselignore',
'**/.tesselinclude',
]);
// Don't send the actual rules files
fstream.addIgnoreRules([
'**/.tesselignore',
'**/.tesselinclude',
]);

if (includeNegateRules.length) {
fstream.addIgnoreRules(includeNegateRules);
}

if (!opts.single && includeFiles.length) {
// Instead of making a complete subclass of Ignore (as is done in fstream-npm,
// https://github.com/npm/fstream-npm/blob/master/fstream-npm.js#L91-L183),
// we'll over-ride the just the `applyIgnores` method for cases where there
// are .tesselinclude entries that have explicit inclusion rules.
fstream.applyIgnores = function(entry, partial, entryObj) {
if (includeFiles.indexOf(entry) !== -1) {
return true;
}
if (includeNegateRules.length) {
fstream.addIgnoreRules(includeNegateRules);
}

return Ignore.prototype.applyIgnores.call(fstream, entry, partial, entryObj);
};
}
if (!opts.single && includeFiles.length) {
// Instead of making a complete subclass of Ignore (as is done in fstream-npm,
// https://github.com/npm/fstream-npm/blob/master/fstream-npm.js#L91-L183),
// we'll over-ride the just the `applyIgnores` method for cases where there
// are .tesselinclude entries that have explicit inclusion rules.
fstream.applyIgnores = function(entry, partial, entryObj) {
if (includeFiles.indexOf(entry) !== -1) {
return true;
}

if (opts.single) {
fstream.addIgnoreRules(['*', '!' + opts.resolvedEntryPoint]);
}
return Ignore.prototype.applyIgnores.call(fstream, entry, partial, entryObj);
};
}

// This ensures that the remote root directory
// is the same level as the directory containing
// our program entry-point files.
fstream.on('entry', (entry) => {
entry.root = {
path: entry.path
};
});
if (opts.single) {
fstream.addIgnoreRules(['*', '!' + opts.resolvedEntryPoint]);
}

// Send the ignore-filtered file stream into the tar packer
fstream.pipe(packer)
.on('data', (chunk) => {
buffers.push(chunk);
})
.on('error', (data) => {
reject(data);
})
.on('end', () => {
resolve(Buffer.concat(buffers));
// This ensures that the remote root directory
// is the same level as the directory containing
// our program entry-point files.
fstream.on('entry', (entry) => {
entry.root = {
path: entry.path
};
});
});

// Send the ignore-filtered file stream into the tar packer
fstream.pipe(packer)
.on('data', (chunk) => {
buffers.push(chunk);
})
.on('error', (data) => {
reject(data);
})
.on('end', () => {
resolve(Buffer.concat(buffers));
});
})
.catch(reject);
});
}
};
Expand Down

0 comments on commit 7d610fb

Please sign in to comment.