Skip to content

Commit

Permalink
Revert "build(broccoli): allow rebuild() to return DiffResult"
Browse files Browse the repository at this point in the history
This reverts commit d575915.

See #2662
  • Loading branch information
tbosch committed Jun 23, 2015
1 parent 7b2f757 commit 2c3c235
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 56 deletions.
54 changes: 13 additions & 41 deletions tools/broccoli/diffing-broccoli-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function wrapDiffingPlugin(pluginClass): DiffingPluginWrapperFactory {


export interface DiffingBroccoliPlugin {
rebuild(diff: (DiffResult | DiffResult[])): (Promise<DiffResult | void>| DiffResult | void);
rebuild(diff: (DiffResult | DiffResult[])): (Promise<any>| void);
cleanup ? () : void;
}

Expand All @@ -52,8 +52,6 @@ class DiffingPluginWrapper implements BroccoliTree {
cachePath = null;
outputPath = null;

private diffResult: DiffResult = null;

constructor(private pluginClass, private wrappedPluginArguments) {
if (Array.isArray(wrappedPluginArguments[0])) {
this.inputTrees = this.stabilizeTrees(wrappedPluginArguments[0]);
Expand All @@ -64,59 +62,33 @@ class DiffingPluginWrapper implements BroccoliTree {
this.description = this.pluginClass.name;
}

private getDiffResult(): (DiffResult | DiffResult[]) {
let returnOrCalculateDiffResult = (tree, index) => {
// returnOrCalculateDiffResult will do one of two things:
//
// If `this.diffResult` is null, calculate a DiffResult using TreeDiffer
// for the input tree.
//
// Otherwise, `this.diffResult` was produced from the output of the
// inputTree's rebuild() method, and can be used without being checked.
// Set `this.diffResult` to null and return the previously stored value.
if (!tree.diffResult) {
let differ = index === false ? this.treeDiffer : this.treeDiffers[index];
return differ.diffTree();
}
let diffResult = tree.diffResult;
tree.diffResult = null;
return diffResult;
};

if (this.inputTrees) {
return this.inputTrees.map(returnOrCalculateDiffResult);
} else if (this.inputTree) {
return returnOrCalculateDiffResult(this.inputTree, false);
private calculateDiff(firstRun: boolean): (DiffResult | DiffResult[]) {
// TODO(caitp): optionally log trees based on environment variable or
// command line option. It may be worth logging for trees where elapsed
// time exceeds some threshold, like 10ms.
if (this.treeDiffer) {
return this.treeDiffer.diffTree();
} else if (this.treeDiffers) {
return this.treeDiffers.map((treeDiffer) => treeDiffer.diffTree());
} else {
throw new Error("Missing TreeDiffer");
}
}

private maybeStoreDiffResult(value: (DiffResult | void)) {
this.diffResult = value ? <DiffResult>(value) : null;
}

rebuild() {
try {
let firstRun = !this.initialized;
this.init();

let diffResult = this.getDiffResult();
let diffResult = this.calculateDiff(firstRun);

let result = this.wrappedPlugin.rebuild(diffResult);
var rebuildPromise = this.wrappedPlugin.rebuild(diffResult);

if (result) {
let resultPromise = <Promise<DiffResult | void>>(result);
if (resultPromise.then) {
// rebuild() -> Promise<>
return resultPromise.then((result: (DiffResult | void)) => {
this.maybeStoreDiffResult(result);
this.relinkOutputAndCachePaths();
});
}
if (rebuildPromise) {
return (<Promise<any>>rebuildPromise).then(this.relinkOutputAndCachePaths.bind(this));
}

this.maybeStoreDiffResult(<(DiffResult | void)>(result));
this.relinkOutputAndCachePaths();
} catch (e) {
e.message = `[${this.description}]: ${e.message}`;
Expand Down
27 changes: 12 additions & 15 deletions tools/broccoli/tree-differ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,25 @@ export class TreeDiffer {
}


export class DiffResult {
public addedPaths: string[] = [];
public changedPaths: string[] = [];
public removedPaths: string[] = [];

constructor(public label: string = '') {}

log(verbose: boolean): void {}

toString(): string {
// TODO(@caitp): more meaningful logging
return '';
}
export interface DiffResult {
addedPaths: string[];
changedPaths: string[];
removedPaths: string[];
log(verbose: boolean): void;
toString(): string;
}

class DirtyCheckingDiffResult extends DiffResult {

class DirtyCheckingDiffResult {
public filesChecked: number = 0;
public directoriesChecked: number = 0;
public addedPaths: string[] = [];
public changedPaths: string[] = [];
public removedPaths: string[] = [];
public startTime: number = Date.now();
public endTime: number = null;

constructor(label: string, public directoryName: string) { super(label); }
constructor(public label: string, public directoryName: string) {}

toString() {
return `${pad(this.label, 30)}, ${pad(this.endTime - this.startTime, 5)}ms, ` +
Expand Down

0 comments on commit 2c3c235

Please sign in to comment.