build(broccoli): add support for DiffResult#addedPaths
Some plugins want to explicitly know of new paths, so we need to distinguish them from changed paths.
This commit is contained in:
@ -16,29 +16,31 @@ class DiffingTraceurCompiler implements DiffingBroccoliPlugin {
|
||||
static includeExtensions = ['.js', '.es6', '.cjs'];
|
||||
|
||||
rebuild(treeDiff: DiffResult) {
|
||||
treeDiff.changedPaths.forEach((changedFilePath) => {
|
||||
var traceurOpts = xtend({filename: changedFilePath}, this.options.traceurOptions);
|
||||
treeDiff.addedPaths.concat(treeDiff.changedPaths)
|
||||
.forEach((changedFilePath) => {
|
||||
var traceurOpts = xtend({filename: changedFilePath}, this.options.traceurOptions);
|
||||
|
||||
var fsOpts = {encoding: 'utf-8'};
|
||||
var absoluteInputFilePath = path.join(this.inputPath, changedFilePath);
|
||||
var sourcecode = fs.readFileSync(absoluteInputFilePath, fsOpts);
|
||||
var fsOpts = {encoding: 'utf-8'};
|
||||
var absoluteInputFilePath = path.join(this.inputPath, changedFilePath);
|
||||
var sourcecode = fs.readFileSync(absoluteInputFilePath, fsOpts);
|
||||
|
||||
var result = traceur.compile(traceurOpts, changedFilePath, sourcecode);
|
||||
var result = traceur.compile(traceurOpts, changedFilePath, sourcecode);
|
||||
|
||||
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
|
||||
// (but we might switch to typescript first)
|
||||
var mapFilepath = changedFilePath.replace(/\.\w+$/, '') + this.options.destSourceMapExtension;
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(mapFilepath);
|
||||
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
|
||||
// (but we might switch to typescript first)
|
||||
var mapFilepath =
|
||||
changedFilePath.replace(/\.\w+$/, '') + this.options.destSourceMapExtension;
|
||||
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(mapFilepath);
|
||||
|
||||
var destFilepath = changedFilePath.replace(/\.\w+$/, this.options.destExtension);
|
||||
var destFile = path.join(this.cachePath, destFilepath);
|
||||
fse.mkdirsSync(path.dirname(destFile));
|
||||
fs.writeFileSync(destFile, result.js, fsOpts);
|
||||
var destFilepath = changedFilePath.replace(/\.\w+$/, this.options.destExtension);
|
||||
var destFile = path.join(this.cachePath, destFilepath);
|
||||
fse.mkdirsSync(path.dirname(destFile));
|
||||
fs.writeFileSync(destFile, result.js, fsOpts);
|
||||
|
||||
var destMap = path.join(this.cachePath, mapFilepath);
|
||||
result.sourceMap.file = destFilepath;
|
||||
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
|
||||
});
|
||||
var destMap = path.join(this.cachePath, mapFilepath);
|
||||
result.sourceMap.file = destFilepath;
|
||||
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
|
||||
});
|
||||
|
||||
treeDiff.removedPaths.forEach((removedFilePath) => {
|
||||
var destFilepath = removedFilePath.replace(/\.\w+$/, this.options.destExtension);
|
||||
|
Reference in New Issue
Block a user